diff --git a/packages/@lwc/integration-karma/test/api/getComponentDef/index.spec.js b/packages/@lwc/integration-karma/test/api/getComponentDef/index.spec.js index b1a6212632..f346662d0a 100644 --- a/packages/@lwc/integration-karma/test/api/getComponentDef/index.spec.js +++ b/packages/@lwc/integration-karma/test/api/getComponentDef/index.spec.js @@ -17,36 +17,6 @@ function testInvalidComponentConstructor(name, ctor) { }); } -beforeAll(function () { - const getNormalizedFunctionAsString = (fn) => fn.toString().replace(/(\s|\n)/g, ''); - - jasmine.addMatchers({ - toEqualWireSettings: function () { - return { - compare: function (actual, expected) { - Object.keys(actual).forEach((currentKey) => { - const normalizedActual = Object.assign({}, actual[currentKey], { - config: getNormalizedFunctionAsString(actual[currentKey].config), - }); - - const normalizedExpected = Object.assign({}, expected[currentKey], { - config: getNormalizedFunctionAsString( - expected[currentKey].config || function () {} - ), - }); - - expect(normalizedActual).toEqual(normalizedExpected); - }); - - return { - pass: true, - }; - }, - }; - }, - }); -}); - testInvalidComponentConstructor('null', null); testInvalidComponentConstructor('undefined', undefined); testInvalidComponentConstructor('String', 'component'); diff --git a/packages/@lwc/integration-karma/test/component/native-vs-synthetic-lifecycle/index.spec.js b/packages/@lwc/integration-karma/test/component/native-vs-synthetic-lifecycle/index.spec.js index fde1d29003..57a780ac11 100644 --- a/packages/@lwc/integration-karma/test/component/native-vs-synthetic-lifecycle/index.spec.js +++ b/packages/@lwc/integration-karma/test/component/native-vs-synthetic-lifecycle/index.spec.js @@ -25,7 +25,8 @@ const expectLogs = (regexes) => { const args = logger.calls.allArgs(); expect(args.length).toBe(regexes.length); for (let i = 0; i < args.length; i++) { - expect(args[i][0]).toMatch(regexes[i]); + expect(args[i][0]).toBeInstanceOf(Error); + expect(args[i][0].message).toMatch(regexes[i]); } } }; diff --git a/packages/@lwc/integration-karma/test/wire/wiring/index.spec.js b/packages/@lwc/integration-karma/test/wire/wiring/index.spec.js index 18cdb079a7..656420f816 100644 --- a/packages/@lwc/integration-karma/test/wire/wiring/index.spec.js +++ b/packages/@lwc/integration-karma/test/wire/wiring/index.spec.js @@ -21,7 +21,7 @@ function filterCalls(echoAdapterSpy, methodType) { describe('wiring', () => { describe('component lifecycle and wire adapter', () => { - it('should call a connect when component is connected', () => { + it('should call a connect when component is connected', async () => { const spy = []; const elm = createElement('x-echo-adapter-consumer', { is: ComponentClass }); AdapterId.setSpy(spy); @@ -30,7 +30,7 @@ describe('wiring', () => { expect(filterCalls(spy, 'connect').length).toBe(1); }); - it('should call a disconnect when component is disconnected', () => { + it('should call a disconnect when component is disconnected', async () => { const spy = []; AdapterId.setSpy(spy); const elm = createElement('x-echo-adapter-consumer', { is: ComponentClass }); @@ -40,7 +40,7 @@ describe('wiring', () => { expect(filterCalls(spy, 'disconnect').length).toBe(1); }); - it('should call a connect and disconnect when component is connected, disconnected twice', () => { + it('should call a connect and disconnect when component is connected, disconnected twice', async () => { const spy = []; const elm = createElement('x-echo-adapter-consumer', { is: ComponentClass }); AdapterId.setSpy(spy); @@ -59,7 +59,7 @@ describe('wiring', () => { }); describe('update method on wire adapter', () => { - it('should be called in same tick when component with wire no dynamic params is created', () => { + it('should be called in same tick when component with wire no dynamic params is created', async () => { const spy = []; AdapterId.setSpy(spy); expect(spy.length).toBe(0); @@ -83,7 +83,7 @@ describe('wiring', () => { setFeatureFlagForTest('ENABLE_WIRE_SYNC_EMIT', false); }); - it('should be called synchronously after connect when a component with wire that has dynamic params is created', () => { + it('should be called synchronously after connect when a component with wire that has dynamic params is created', async () => { const spy = []; AdapterId.setSpy(spy); expect(spy.length).toBe(0); @@ -96,7 +96,7 @@ describe('wiring', () => { expect(spy[1].method).toBe('update'); }); - it('should call synchronously update only once when the component is created and a wire dynamic param is modified', () => { + it('should call synchronously update only once when the component is created and a wire dynamic param is modified', async () => { const spy = []; AdapterId.setSpy(spy); expect(spy.length).toBe(0); @@ -112,7 +112,7 @@ describe('wiring', () => { }); }); - it('should be called next tick when the component with wire that has dynamic params is created', () => { + it('should be called next tick when the component with wire that has dynamic params is created', async () => { const spy = []; AdapterId.setSpy(spy); expect(spy.length).toBe(0); @@ -130,7 +130,7 @@ describe('wiring', () => { }); }); - it('should call update only once when the component is created and a wire dynamic param is modified in the same tick', () => { + it('should call update only once when the component is created and a wire dynamic param is modified in the same tick', async () => { const spy = []; AdapterId.setSpy(spy); expect(spy.length).toBe(0); @@ -147,7 +147,7 @@ describe('wiring', () => { }); }); - it('should be called only once during multiple renders when the wire config does not change', () => { + it('should be called only once during multiple renders when the wire config does not change', async () => { const spy = []; AdapterId.setSpy(spy); const elm = createElement('x-echo-adapter-consumer', { is: ComponentClass }); @@ -165,7 +165,7 @@ describe('wiring', () => { }); }); - it('should be called when the wire parameters change its value.', () => { + it('should be called when the wire parameters change its value.', async () => { const spy = []; AdapterId.setSpy(spy); const elm = createElement('x-echo-adapter-consumer', { is: ComponentClass }); @@ -186,7 +186,7 @@ describe('wiring', () => { }); }); - it('should be called for common parameter when shared among wires', () => { + it('should be called for common parameter when shared among wires', async () => { const spy = []; AdapterId.setSpy(spy); const elm = createElement('x-bc-consumer', { is: BroadcastConsumer }); @@ -209,7 +209,7 @@ describe('wiring', () => { }); }); - it('should not update when setting parameter with same value', () => { + it('should not update when setting parameter with same value', async () => { const spy = []; const elm = createElement('x-echo-adapter-consumer', { is: ComponentClass }); document.body.appendChild(elm); @@ -255,7 +255,7 @@ describe('wiring', () => { expect(dynamicValue.textContent).toBe('modified value'); }); - it('should not call update when component is disconnected.', () => { + it('should not call update when component is disconnected.', async () => { const spy = []; AdapterId.setSpy(spy); const elm = createElement('x-echo-adapter-consumer', { is: ComponentClass }); @@ -272,7 +272,7 @@ describe('wiring', () => { }); }); - it('should call update when component is re-connected.', () => { + it('should call update when component is re-connected.', async () => { const spy = []; AdapterId.setSpy(spy); const elm = createElement('x-echo-adapter-consumer', { is: ComponentClass }); @@ -302,7 +302,7 @@ describe('wiring', () => { }); describe('wired fields', () => { - it('should rerender component when adapter pushes data', () => { + it('should rerender component when adapter pushes data', async () => { BroadcastAdapter.clearInstances(); const elm = createElement('x-bc-consumer', { is: BroadcastConsumer }); document.body.appendChild(elm); @@ -322,7 +322,7 @@ describe('wired fields', () => { }); }); - it('should rerender component when wired field is mutated from within the component', () => { + it('should rerender component when wired field is mutated from within the component', async () => { BroadcastAdapter.clearInstances(); const elm = createElement('x-bc-consumer', { is: BroadcastConsumer }); document.body.appendChild(elm); @@ -343,7 +343,7 @@ describe('wired fields', () => { }); describe('wired methods', () => { - it('should call component method when wired to a method', () => { + it('should call component method when wired to a method', async () => { BroadcastAdapter.clearInstances(); const elm = createElement('x-bc-consumer', { is: BroadcastConsumer }); document.body.appendChild(elm); @@ -355,7 +355,7 @@ describe('wired methods', () => { }); }); - it('should support method override', () => { + it('should support method override', async () => { const spy = []; EchoWireAdapter.setSpy(spy); const elm = createElement('x-inherited-methods', { is: InheritedMethods }); @@ -376,7 +376,7 @@ describe('wired methods', () => { }); describe('context aware', () => { - it('should receive the source element tag name when adapter is constructed', () => { + it('should receive the source element tag name when adapter is constructed', async () => { const spy = []; ContextLog.setSpy(spy); diff --git a/packages/@lwc/integration-not-karma/web-test-runner.hydration.mjs b/packages/@lwc/integration-not-karma/configs/base.mjs similarity index 57% rename from packages/@lwc/integration-not-karma/web-test-runner.hydration.mjs rename to packages/@lwc/integration-not-karma/configs/base.mjs index b3890536c1..e931a92ba4 100644 --- a/packages/@lwc/integration-not-karma/web-test-runner.hydration.mjs +++ b/packages/@lwc/integration-not-karma/configs/base.mjs @@ -1,8 +1,9 @@ +import { join } from 'node:path'; import { LWC_VERSION } from '@lwc/shared'; -import * as options from './helpers/options.mjs'; -import wrapHydrationTest from './helpers/hydration-tests.mjs'; +import * as options from '../helpers/options.mjs'; -const pluck = (obj, keys) => Object.fromEntries(keys.map((k) => [k, Boolean(obj[k])])); +const pluck = (obj, keys) => Object.fromEntries(keys.map((k) => [k, obj[k]])); +const maybeImport = (file, condition) => (condition ? `await import('${file}');` : ''); /** `process.env` to inject into test environment. */ const env = { @@ -20,32 +21,21 @@ const env = { LWC_VERSION, NODE_ENV: options.NODE_ENV_FOR_TEST, }; + /** @type {import("@web/test-runner").TestRunnerConfig} */ export default { - files: [ - // FIXME: These tests are just symlinks to integration-karma for now so the git diff smaller - 'test-hydration/**/*.spec.js', - '!test-hydration/light-dom/scoped-styles/replace-scoped-styles-with-dynamic-templates/index.spec.js', - ], nodeResolve: true, - rootDir: import.meta.dirname, + rootDir: join(import.meta.dirname, '..'), plugins: [ { resolveImport({ source }) { if (source === 'test-utils') { - return '/helpers/wtr-utils.mjs'; + return '/helpers/utils.mjs'; } else if (source === 'wire-service') { - return '@lwc/wire-service'; - } - }, - async serve(ctx) { - // Hydration test "index.spec.js" files are actually just config files. - // They don't directly define the tests. Instead, when we request the file, - // we wrap it with some boilerplate. That boilerplate must include the config - // file we originally requested, so the ?original query parameter is used - // to return the file unmodified. - if (ctx.path.endsWith('.spec.js') && !ctx.query.original) { - return await wrapHydrationTest(ctx.path.slice(1)); // remove leading / + // To serve files outside the web root (e.g. node_modules in the monorepo root), + // @web/dev-server provides this "magic" path. It's hacky of us to use it directly. + // `/__wds-outside-root__/${depth}/` === '../'.repeat(depth) + return '/__wds-outside-root__/1/wire-service/dist/index.js'; } }, async transform(ctx) { @@ -59,16 +49,19 @@ export default { testRunnerHtml: (testFramework) => ` -
+ + - - + `, }; diff --git a/packages/@lwc/integration-not-karma/configs/hydration.mjs b/packages/@lwc/integration-not-karma/configs/hydration.mjs new file mode 100644 index 0000000000..eb81e7701a --- /dev/null +++ b/packages/@lwc/integration-not-karma/configs/hydration.mjs @@ -0,0 +1,19 @@ +// Use native shadow by default in hydration tests; MUST be set before imports +process.env.DISABLE_SYNTHETIC ??= 'true'; +import baseConfig from './base.mjs'; +import hydrationTestPlugin from './plugins/serve-hydration.mjs'; + +/** @type {import("@web/test-runner").TestRunnerConfig} */ +export default { + ...baseConfig, + files: [ + // FIXME: These tests are just symlinks to integration-karma for now so the git diff smaller + 'test-hydration/**/*.spec.js', + // FIXME: hits timeout? + '!test-hydration/light-dom/scoped-styles/replace-scoped-styles-with-dynamic-templates/index.spec.js', + // FIXME: This uses ENABLE_SYNTHETIC_SHADOW_IN_MIGRATION to detect status, + // we should just use DISABLE_SYNTHETIC instead + '!test-hydration/synthetic-shadow/index.spec.js', + ], + plugins: [...baseConfig.plugins, hydrationTestPlugin], +}; diff --git a/packages/@lwc/integration-not-karma/configs/integration.mjs b/packages/@lwc/integration-not-karma/configs/integration.mjs new file mode 100644 index 0000000000..ea3bae21bf --- /dev/null +++ b/packages/@lwc/integration-not-karma/configs/integration.mjs @@ -0,0 +1,52 @@ +import baseConfig from './base.mjs'; +import testPlugin from './plugins/serve-integration.mjs'; + +/** @type {import("@web/test-runner").TestRunnerConfig} */ +export default { + ...baseConfig, + files: [ + // FIXME: These tests are just symlinks to integration-karma for now so the git diff smaller + 'test/**/*.spec.js', + '!test/events/focus-event-related-target/index.spec.js', + '!test/light-dom/multiple-templates/index.spec.js', + '!test/light-dom/scoped-slot/if-block/index.spec.js', + '!test/light-dom/scoped-styles/index.spec.js', + '!test/light-dom/style-global/index.spec.js', + '!test/misc/clean-dom/index.spec.js', + '!test/polyfills/document-body-properties/index.spec.js', + '!test/polyfills/document-properties/index.spec.js', + '!test/profiler/mutation-logging/index.spec.js', + '!test/regression/invalid-key/index.spec.js', + '!test/rendering/iframe/index.spec.js', + '!test/rendering/inner-outer-html/index.spec.js', + '!test/rendering/legacy-stylesheet-api/index.spec.js', + '!test/rendering/sanitize-stylesheet-token/index.spec.js', + '!test/rendering/slotting/index.spec.js', + '!test/rendering/stylesheet-caching/index.spec.js', + '!test/shadow-dom/ShadowRoot.elementsFromPoint/index.spec.js', + '!test/signal/protocol/index.spec.js', + '!test/spread/index.spec.js', + '!test/swapping/styles/index.spec.js', + '!test/template/directive-for-each/index.spec.js', + + // Flaky tests that sometimes time out + '!test/light-dom/host-pseudo/index.spec.js', + '!test/rendering/programmatic-stylesheets/index.spec.js', + '!test/shadow-dom/multiple-templates/index.spec.js', + '!test/synthetic-shadow/dom-manual-sharing-nodes/index.spec.js', + '!test/synthetic-shadow/host-pseudo/index.spec.js', + '!test/synthetic-shadow/style-svg/index.spec.js', + + // Cannot reassign properties of module + '!test/api/sanitizeAttribute/index.spec.js', + + // Hacky nonsense highly tailored to Karma + '!test/custom-elements-registry/index.spec.js', + + // Logging mismatches + '!test/accessibility/synthetic-cross-root-aria/index.spec.js', + '!test/api/freezeTemplate/index.spec.js', + '!test/component/LightningElement.addEventListener/index.spec.js', + ], + plugins: [...baseConfig.plugins, testPlugin], +}; diff --git a/packages/@lwc/integration-not-karma/helpers/hydration-tests.mjs b/packages/@lwc/integration-not-karma/configs/plugins/serve-hydration.mjs similarity index 90% rename from packages/@lwc/integration-not-karma/helpers/hydration-tests.mjs rename to packages/@lwc/integration-not-karma/configs/plugins/serve-hydration.mjs index 7608c49efc..e89b764b68 100644 --- a/packages/@lwc/integration-not-karma/helpers/hydration-tests.mjs +++ b/packages/@lwc/integration-not-karma/configs/plugins/serve-hydration.mjs @@ -3,10 +3,10 @@ import vm from 'node:vm'; import fs from 'node:fs/promises'; import { rollup } from 'rollup'; import lwcRollupPlugin from '@lwc/rollup-plugin'; -import { DISABLE_STATIC_CONTENT_OPTIMIZATION, ENGINE_SERVER } from './options.mjs'; +import { DISABLE_STATIC_CONTENT_OPTIMIZATION, ENGINE_SERVER } from '../../helpers/options.mjs'; const lwcSsr = await (ENGINE_SERVER ? import('@lwc/engine-server') : import('@lwc/ssr-runtime')); -const ROOT_DIR = path.join(import.meta.dirname, '..'); +const ROOT_DIR = path.join(import.meta.dirname, '../..'); const context = { LWC: lwcSsr, @@ -177,7 +177,7 @@ async function existsUp(dir, file) { * Hydration test `index.spec.js` files are actually config files, not spec files. * This function wraps those configs in the test code to be executed. */ -export default async function wrapHydrationTest(filePath /* .../index.spec.js */) { +async function wrapHydrationTest(filePath) { const suiteDir = path.dirname(filePath); // Wrap all the tests into a describe block with the file stricture name @@ -230,3 +230,17 @@ export default async function wrapHydrationTest(filePath /* .../index.spec.js */ }); } } + +/** @type {import('@web/dev-server-core').Plugin} */ +export default { + async serve(ctx) { + // Hydration test "index.spec.js" files are actually just config files. + // They don't directly define the tests. Instead, when we request the file, + // we wrap it with some boilerplate. That boilerplate must include the config + // file we originally requested, so the ?original query parameter is used + // to return the file unmodified. + if (ctx.path.endsWith('.spec.js') && !ctx.query.original) { + return await wrapHydrationTest(ctx.path.slice(1)); // remove leading / + } + }, +}; diff --git a/packages/@lwc/integration-not-karma/helpers/lwc.mjs b/packages/@lwc/integration-not-karma/configs/plugins/serve-integration.mjs similarity index 93% rename from packages/@lwc/integration-not-karma/helpers/lwc.mjs rename to packages/@lwc/integration-not-karma/configs/plugins/serve-integration.mjs index f78332e333..c59a990436 100644 --- a/packages/@lwc/integration-not-karma/helpers/lwc.mjs +++ b/packages/@lwc/integration-not-karma/configs/plugins/serve-integration.mjs @@ -7,7 +7,7 @@ import { COVERAGE, DISABLE_STATIC_CONTENT_OPTIMIZATION, DISABLE_SYNTHETIC_SHADOW_SUPPORT_IN_COMPILER, -} from './options.mjs'; +} from '../../helpers/options.mjs'; /** Cache reused between each compilation to speed up the compilation time. */ let cache; @@ -41,7 +41,7 @@ const createRollupPlugin = (input, options) => { }); }; -export default async (ctx) => { +const transform = async (ctx) => { const input = ctx.path.slice(1); // strip leading / from URL path to get relative file path const defaultRollupPlugin = createRollupPlugin(input); @@ -106,3 +106,12 @@ export default async (ctx) => { return output[0].code; }; + +/** @type {import('@web/dev-server-core').Plugin} */ +export default { + async serve(ctx) { + if (ctx.path.endsWith('.spec.js')) { + return await transform(ctx); + } + }, +}; diff --git a/packages/@lwc/integration-not-karma/helpers/options.mjs b/packages/@lwc/integration-not-karma/helpers/options.mjs index aff4cf1ca3..a18ae6df4a 100644 --- a/packages/@lwc/integration-not-karma/helpers/options.mjs +++ b/packages/@lwc/integration-not-karma/helpers/options.mjs @@ -1,3 +1,5 @@ +// IMPORTANT: This file is used in both the node/setup environment and the browser/test environment + import { HIGHEST_API_VERSION } from '@lwc/shared'; // FIXME: Add jsdoc comments to each export explaining what it's used for diff --git a/packages/@lwc/integration-not-karma/helpers/setup.mjs b/packages/@lwc/integration-not-karma/helpers/setup.mjs index 6bd47784ea..8f572ec12d 100644 --- a/packages/@lwc/integration-not-karma/helpers/setup.mjs +++ b/packages/@lwc/integration-not-karma/helpers/setup.mjs @@ -4,6 +4,11 @@ import * as chai from 'chai'; import * as LWC from 'lwc'; import { spyOn, fn } from '@vitest/spy'; import { registerCustomMatchers } from './matchers/index.mjs'; +import * as TestUtils from './utils.mjs'; + +// FIXME: As a relic of the Karma tests, some test files rely on the global object, +// rather than importing from `test-utils`. +window.TestUtils = TestUtils; // allows using expect.extend instead of chai.use to extend plugins chai.use(JestExtend); @@ -14,31 +19,41 @@ chai.use(JestAsymmetricMatchers); // add our custom matchers chai.use(registerCustomMatchers); +/** + * Adds the jasmine interfaces we use in the Karma tests to a Vitest spy. + * Should ultimately be removed and tests updated to use Vitest spies. + * @param {import('@vitest/spy').MockInstance} + */ +function jasmineSpyAdapter(spy) { + Object.defineProperties(spy, { + and: { get: () => spy }, + calls: { get: () => spy.mock.calls }, + returnValue: { value: () => spy.mockReturnValue() }, + // calling mockImplementation() with nothing restores the original + callThrough: { value: () => spy.mockImplementation() }, + }); + + Object.defineProperties(spy.mock.calls, { + // Must be non-enumerable for equality checks to work on array literal expected values + allArgs: { value: () => spy.mock.calls }, + count: { value: () => spy.mock.calls.length }, + reset: { value: () => spy.mockReset() }, + }); + + return spy; +} + // expose so we don't need to import `expect` in every test file globalThis.expect = chai.expect; // Expose globals for karma compat globalThis.LWC = LWC; -globalThis.spyOn = spyOn; +globalThis.spyOn = (object, prop) => jasmineSpyAdapter(spyOn(object, prop)); globalThis.jasmine = { - any: () => { - throw new Error(`TODO: jasmine.any`); - }, + any: expect.any, arrayWithExactContents: () => { throw new Error('TODO: jasmine.arrayWithExactContents'); }, - createSpy: (name, impl) => { - const spy = fn(impl); - // Bridge for jasmine - spy.calls = { - count() { - return spy.mock.calls.length; - }, - reset() { - spy.mockReset(); - }, - }; - return spy; - }, + createSpy: (name, impl) => jasmineSpyAdapter(fn(impl)), objectContaining: expect.objectContaining, }; diff --git a/packages/@lwc/integration-not-karma/helpers/wtr-utils.mjs b/packages/@lwc/integration-not-karma/helpers/utils.mjs similarity index 92% rename from packages/@lwc/integration-not-karma/helpers/wtr-utils.mjs rename to packages/@lwc/integration-not-karma/helpers/utils.mjs index 70875552aa..5ebdd95dde 100644 --- a/packages/@lwc/integration-not-karma/helpers/wtr-utils.mjs +++ b/packages/@lwc/integration-not-karma/helpers/utils.mjs @@ -1,3 +1,6 @@ +/* + * An as yet uncategorized mishmash of helpers, relics of Karma + */ import * as LWC from 'lwc'; import { ariaAttributes, @@ -349,41 +352,3 @@ export { ENABLE_THIS_DOT_STYLE, TEMPLATE_CLASS_NAME_OBJECT_BINDING, }; - -window.TestUtils = { - clearRegister, - extractDataIds, - extractShadowDataIds, - getHostChildNodes, - isNativeShadowRootInstance, - isSyntheticShadowRootInstance, - load, - registerForLoad, - getHooks, - setHooks, - spyConsole, - customElementCallbackReactionErrorListener, - ariaPropertiesMapping, - ariaProperties, - ariaAttributes, - nonStandardAriaProperties, - nonPolyfilledAriaProperties, - getPropertyDescriptor, - attachReportingControlDispatcher, - detachReportingControlDispatcher, - IS_SYNTHETIC_SHADOW_LOADED, - expectConsoleCalls, - expectConsoleCallsDev, - catchUnhandledRejectionsAndErrors, - addTrustedSignal, - expectEquivalentDOM, - LOWERCASE_SCOPE_TOKENS, - USE_COMMENTS_FOR_FRAGMENT_BOOKENDS, - USE_FRAGMENTS_FOR_LIGHT_DOM_SLOTS, - DISABLE_OBJECT_REST_SPREAD_TRANSFORMATION, - ENABLE_ELEMENT_INTERNALS_AND_FACE, - USE_LIGHT_DOM_SLOT_FORWARDING, - ENABLE_THIS_DOT_HOST_ELEMENT, - ENABLE_THIS_DOT_STYLE, - TEMPLATE_CLASS_NAME_OBJECT_BINDING, -}; diff --git a/packages/@lwc/integration-not-karma/package.json b/packages/@lwc/integration-not-karma/package.json index a8f63c9b87..d9c5589acb 100644 --- a/packages/@lwc/integration-not-karma/package.json +++ b/packages/@lwc/integration-not-karma/package.json @@ -4,8 +4,8 @@ "version": "8.20.1", "scripts": { "start": "web-test-runner --manual", - "test": "web-test-runner", - "test:hydration": "web-test-runner --config web-test-runner.hydration.mjs" + "test": "web-test-runner --config configs/integration.mjs", + "test:hydration": "web-test-runner --config configs/hydration.mjs" }, "devDependencies": { "@lwc/compiler": "8.20.1", diff --git a/packages/@lwc/integration-not-karma/web-test-runner.config.mjs b/packages/@lwc/integration-not-karma/web-test-runner.config.mjs deleted file mode 100644 index bce0d9f208..0000000000 --- a/packages/@lwc/integration-not-karma/web-test-runner.config.mjs +++ /dev/null @@ -1,154 +0,0 @@ -import { LWC_VERSION } from '@lwc/shared'; -import customRollup from './helpers/lwc.mjs'; -import * as options from './helpers/options.mjs'; - -const pluck = (obj, keys) => Object.fromEntries(keys.map((k) => [k, Boolean(obj[k])])); -const maybeImport = (file, condition) => (condition ? `await import('${file}');` : ''); - -/** `process.env` to inject into test environment. */ -const env = { - ...pluck(options, [ - 'API_VERSION', - 'DISABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE', - 'DISABLE_STATIC_CONTENT_OPTIMIZATION', - 'DISABLE_SYNTHETIC', - 'ENABLE_ARIA_REFLECTION_GLOBAL_POLYFILL', - 'ENABLE_SYNTHETIC_SHADOW_IN_HYDRATION', - 'ENGINE_SERVER', - 'FORCE_NATIVE_SHADOW_MODE_FOR_TEST', - 'NATIVE_SHADOW', - ]), - LWC_VERSION, - NODE_ENV: options.NODE_ENV_FOR_TEST, -}; -/** @type {import("@web/test-runner").TestRunnerConfig} */ -export default { - files: [ - // FIXME: These tests are just symlinks to integration-karma for now so the git diff smaller - 'test/**/*.spec.js', - // Failing Karma tests that need to be migrated to WTR - '!test/accessibility/synthetic-cross-root-aria/index.spec.js', - '!test/api/CustomElementConstructor-getter/index.spec.js', - '!test/api/freezeTemplate/index.spec.js', - '!test/api/getComponentDef/index.spec.js', - '!test/api/isNodeFromTemplate/index.spec.js', - '!test/api/registerTemplate/index.spec.js', - '!test/api/sanitizeAttribute/index.spec.js', - '!test/api/sanitizeHtmlContent/index.spec.js', - '!test/component/LightningElement.addEventListener/index.spec.js', - '!test/component/LightningElement.attachInternals/api/index.spec.js', - '!test/component/LightningElement.attachInternals/elementInternals/formAssociated/index.spec.js', - '!test/component/LightningElement.connectedCallback/index.spec.js', - '!test/component/LightningElement.disconnectedCallback/index.spec.js', - '!test/component/LightningElement.errorCallback/index.spec.js', - '!test/component/LightningElement.hostElement/index.spec.js', - '!test/component/LightningElement.render/index.spec.js', - '!test/component/LightningElement.style/index.spec.js', - '!test/component/LightningElement/index.spec.js', - '!test/component/face-callbacks/index.spec.js', - '!test/component/native-vs-synthetic-lifecycle/index.spec.js', - '!test/custom-elements-registry/index.spec.js', - '!test/events/focus-event-related-target/index.spec.js', - '!test/integrations/locker/index.spec.js', - '!test/light-dom/host-pseudo/index.spec.js', - '!test/light-dom/lifecycle/index.spec.js', - '!test/light-dom/multiple-templates/index.spec.js', - '!test/light-dom/scoped-slot/if-block/index.spec.js', - '!test/light-dom/scoped-slot/index.spec.js', - '!test/light-dom/scoped-slot/runtime-checks/index.spec.js', - '!test/light-dom/scoped-styles/index.spec.js', - '!test/light-dom/slot-fowarding/slots/duplicates/index.spec.js', - '!test/light-dom/slot-fowarding/slots/forwarding/index.spec.js', - '!test/light-dom/slot-fowarding/slots/reactivity/index.spec.js', - '!test/light-dom/slotting/index.spec.js', - '!test/light-dom/style-global/index.spec.js', - '!test/light-dom/synthetic-shadow-styles/index.spec.js', - '!test/lwc-on/index.spec.js', - '!test/misc/clean-dom/index.spec.js', - '!test/misc/object-rest-spread/index.spec.js', - '!test/mixed-shadow-mode/composed-path/index.spec.js', - '!test/polyfills/document-body-properties/index.spec.js', - '!test/polyfills/document-properties/index.spec.js', - '!test/profiler/mutation-logging/index.spec.js', - '!test/regression/invalid-key/index.spec.js', - '!test/rendering/callback-invocation-order/index.spec.js', - '!test/rendering/fragment-cache/index.spec.js', - '!test/rendering/iframe/index.spec.js', - '!test/rendering/inner-outer-html/index.spec.js', - '!test/rendering/legacy-scope-tokens/index.spec.js', - '!test/rendering/legacy-stylesheet-api/index.spec.js', - '!test/rendering/programmatic-stylesheets/index.spec.js', - '!test/rendering/sanitize-stylesheet-token/index.spec.js', - '!test/rendering/scoped-styles-with-existing-class/index.spec.js', - '!test/rendering/side-effects/index.spec.js', - '!test/rendering/slot-not-at-top-level/element/light/index.spec.js', - '!test/rendering/slot-not-at-top-level/external/light/index.spec.js', - '!test/rendering/slot-not-at-top-level/ifTrue/light/index.spec.js', - '!test/rendering/slot-not-at-top-level/lwcIf/light/index.spec.js', - '!test/rendering/slotting/index.spec.js', - '!test/rendering/stylesheet-caching/index.spec.js', - '!test/rendering/version-mismatch/index.spec.js', - '!test/shadow-dom/Element-properties/index.spec.js', - '!test/shadow-dom/Event-properties/Event.target.spec.js', - '!test/shadow-dom/Node-properties/Node.getRootNode.spec.js', - '!test/shadow-dom/ShadowRoot.elementsFromPoint/index.spec.js', - '!test/shadow-dom/multiple-templates/index.spec.js', - '!test/signal/protocol/index.spec.js', - '!test/spread/index.spec.js', - '!test/static-content/index.spec.js', - '!test/swapping/styles/index.spec.js', - '!test/synthetic-shadow/dom-manual-sharing-nodes/index.spec.js', - '!test/synthetic-shadow/element-api/element-api.spec.js', - '!test/synthetic-shadow/host-pseudo/index.spec.js', - '!test/synthetic-shadow/style-svg/index.spec.js', - '!test/template/attribute-class/object-values.spec.js', - '!test/template/directive-for-each/index.spec.js', - '!test/template/directive-lwc-render-mode/index.spec.js', - '!test/wire/legacy-adapters/index.spec.js', - '!test/wire/reactive-params.spec.js', - '!test/wire/wirecontextevent-legacy/index.spec.js', - '!test/wire/wiring/index.spec.js', - ], - nodeResolve: true, - rootDir: import.meta.dirname, - plugins: [ - { - resolveImport({ source }) { - if (source === 'test-utils') { - return '/helpers/wtr-utils.mjs'; - } else if (source === 'wire-service') { - return '@lwc/wire-service'; - } - }, - async serve(ctx) { - if (ctx.path.endsWith('.spec.js')) { - return await customRollup(ctx); - } - }, - async transform(ctx) { - if (ctx.type === 'application/javascript') { - // FIXME: copy/paste Nolan's spiel about why we do this ugly thing - return ctx.body.replace(/process\.env\.NODE_ENV === 'test-karma-lwc'/g, 'true'); - } - }, - }, - ], - testRunnerHtml: (testFramework) => - ` - - - - - - - - `, -};