Skip to content

Commit a130ead

Browse files
fix: merge master
2 parents a8b5f88 + e0e0879 commit a130ead

File tree

128 files changed

+2452
-3104
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+2452
-3104
lines changed

packages/@lwc/integration-not-karma/configs/base.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export default {
2929
// time out before they receive focus. But it also makes the full suite take 3x longer to run...
3030
// Potential workaround: https://github.com/modernweb-dev/web/issues/2588
3131
concurrency: 1,
32+
browserLogs: false,
3233
nodeResolve: true,
3334
rootDir: join(import.meta.dirname, '..'),
3435
plugins: [

packages/@lwc/integration-not-karma/configs/integration.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,7 @@ import testPlugin from './plugins/serve-integration.js';
55
/** @type {import("@web/test-runner").TestRunnerConfig} */
66
export default {
77
...baseConfig,
8-
files: [
9-
// FIXME: These tests are just symlinks to integration-karma for now so the git diff smaller
10-
'test/**/*.spec.js',
11-
12-
// Logging mismatches
13-
'!test/component/LightningElement.addEventListener/index.spec.js',
14-
15-
// Implement objectContaining / arrayWithExactContents
16-
'!test/profiler/mutation-logging/index.spec.js',
17-
],
8+
files: ['test/**/*.spec.js'],
189
plugins: [
1910
...baseConfig.plugins,
2011
importMapsPlugin({ inject: { importMap: { imports: { lwc: './mocks/lwc.js' } } } }),

packages/@lwc/integration-not-karma/configs/plugins/serve-hydration.js

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import path from 'node:path';
22
import vm from 'node:vm';
3-
import fs from 'node:fs/promises';
43
import { fileURLToPath } from 'node:url';
54
import { rollup } from 'rollup';
65
import lwcRollupPlugin from '@lwc/rollup-plugin';
@@ -21,16 +20,6 @@ const ROOT_DIR = path.join(import.meta.dirname, '../..');
2120
const COMPONENT_NAME = 'x-main';
2221
const COMPONENT_ENTRYPOINT = 'x/main/main.js';
2322

24-
// Like `fs.existsSync` but async
25-
async function exists(path) {
26-
try {
27-
await fs.access(path);
28-
return true;
29-
} catch (_err) {
30-
return false;
31-
}
32-
}
33-
3423
async function compileModule(input, targetSSR, format) {
3524
const modulesDir = path.join(ROOT_DIR, input.slice(0, -COMPONENT_ENTRYPOINT.length));
3625
const bundle = await rollup({
@@ -106,15 +95,6 @@ async function getSsrMarkup(componentEntrypoint, configPath) {
10695
return await script.runInContext(vm.createContext({ LWC: lwcSsr }));
10796
}
10897

109-
async function existsUp(dir, file) {
110-
while (true) {
111-
if (await exists(path.join(dir, file))) return true;
112-
dir = path.join(dir, '..');
113-
const basename = path.basename(dir);
114-
if (basename === '.') return false;
115-
}
116-
}
117-
11898
/**
11999
* Hydration test `index.spec.js` files are actually config files, not spec files.
120100
* This function wraps those configs in the test code to be executed.
@@ -129,8 +109,6 @@ async function wrapHydrationTest(configPath) {
129109

130110
const suiteDir = path.dirname(configPath);
131111
const componentEntrypoint = path.join(suiteDir, COMPONENT_ENTRYPOINT);
132-
// You can add an `.only` file alongside an `index.spec.js` file to make the test focused
133-
const onlyFileExists = await existsUp(suiteDir, '.only');
134112
const ssrOutput = await getSsrMarkup(componentEntrypoint, configPath);
135113

136114
return `
@@ -139,8 +117,7 @@ async function wrapHydrationTest(configPath) {
139117
runTest(
140118
'/${configPath}?original=1',
141119
'/${componentEntrypoint}',
142-
${JSON.stringify(ssrOutput) /* escape quotes */},
143-
${onlyFileExists}
120+
${JSON.stringify(ssrOutput) /* escape quotes */}
144121
);
145122
`;
146123
} finally {

packages/@lwc/integration-not-karma/configs/plugins/serve-integration.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,8 @@ const createRollupPlugin = (input, options) => {
3232
enableStaticContentOptimization: !DISABLE_STATIC_CONTENT_OPTIMIZATION,
3333
disableSyntheticShadowSupport: DISABLE_SYNTHETIC_SHADOW_SUPPORT_IN_COMPILER,
3434
apiVersion: API_VERSION,
35-
modules: [
36-
{
37-
// Assume `ctx.path` is a component file, e.g. modules/x/foo/foo.js
38-
dir: path.resolve(input, '../../..'),
39-
},
40-
],
35+
// Assume `ctx.path` is a component file, e.g. modules/x/foo/foo.js
36+
modules: [{ dir: path.resolve(input, '../../..') }],
4137
...options,
4238
});
4339
};
@@ -85,6 +81,8 @@ const transform = async (ctx) => {
8581
plugins: [customLwcRollupPlugin],
8682

8783
external: [
84+
'@vitest/expect',
85+
'@vitest/spy',
8886
'lwc',
8987
'wire-service',
9088
// Some helper files export functions that mutate a global state. The setup file calls
@@ -120,6 +118,11 @@ export default {
120118
async serve(ctx) {
121119
if (ctx.path.endsWith('.spec.js')) {
122120
return await transform(ctx);
121+
} else if (ctx.path === '/test_api_sanitizeAttribute') {
122+
// The test in /test/api/sanitizeAttribute makes network requests
123+
// The returned value doesn't matter; this is just to avoid
124+
// unnecessary logging output
125+
return '';
123126
}
124127
},
125128
};

packages/@lwc/integration-not-karma/configs/plugins/test-hydration.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { spyOn } from '@vitest/spy';
12
import * as LWC from 'lwc';
2-
import { spyConsole } from '../../helpers/console';
33
import { setHooks } from '../../helpers/hooks';
44

55
setHooks({ sanitizeHtmlContent: (content) => content });
@@ -8,6 +8,28 @@ function parseStringToDom(html) {
88
return Document.parseHTMLUnsafe(html).body.firstChild;
99
}
1010

11+
/**
12+
* A much simplified version of the spies originally used for Karma.
13+
* Should probably be eventually replaced with individual spies.
14+
*/
15+
export function spyConsole() {
16+
const log = spyOn(console, 'log');
17+
const warn = spyOn(console, 'warn');
18+
const error = spyOn(console, 'error');
19+
return {
20+
calls: {
21+
log: log.mock.calls,
22+
warn: warn.mock.calls,
23+
error: error.mock.calls,
24+
},
25+
reset() {
26+
log.mockRestore();
27+
warn.mockRestore();
28+
error.mockRestore();
29+
},
30+
};
31+
}
32+
1133
function appendTestTarget(ssrText) {
1234
const div = document.createElement('div');
1335
const testTarget = parseStringToDom(ssrText);
@@ -23,8 +45,7 @@ function setFeatureFlags(requiredFeatureFlags, value) {
2345
}
2446

2547
// Must be sync to properly register tests; async behavior can happen in before/after blocks
26-
export function runTest(configPath, componentPath, ssrRendered, focused) {
27-
const test = focused ? it.only : it;
48+
export function runTest(configPath, componentPath, ssrRendered) {
2849
const description = new URL(configPath, location.href).pathname;
2950
let consoleSpy;
3051
let testConfig;
@@ -48,7 +69,7 @@ export function runTest(configPath, componentPath, ssrRendered, focused) {
4869
setFeatureFlags(testConfig.requiredFeatureFlags, false);
4970
});
5071

51-
test(description, async () => {
72+
it(description, async () => {
5273
const container = appendTestTarget(ssrRendered);
5374
const selector = container.firstChild.tagName.toLowerCase();
5475
let target = container.querySelector(selector);

packages/@lwc/integration-not-karma/helpers/console.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

packages/@lwc/integration-not-karma/helpers/matchers/errors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function windowErrorListener(callback) {
3636
// 2) We're using native lifecycle callbacks, so the error is thrown asynchronously and can
3737
// only be caught with window.addEventListener('error')
3838
// - Note native lifecycle callbacks are all thrown asynchronously.
39-
function customElementCallbackReactionErrorListener(callback) {
39+
export function customElementCallbackReactionErrorListener(callback) {
4040
return lwcRuntimeFlags.DISABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE
4141
? directErrorListener(callback)
4242
: windowErrorListener(callback);

packages/@lwc/integration-not-karma/helpers/matchers/jasmine.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ export const registerJasmineMatchers = (chai, utils) => {
1919
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
2020
chai.expect(value).to.be.true;
2121
},
22-
toHaveBeenCalledOnceWith(...args) {
23-
const spy = utils.flag(this, 'object');
24-
chai.expect(spy.calls).to.have.length(1);
25-
chai.expect(spy.calls[0]).to.deep.equal(args);
26-
},
2722
};
2823

2924
for (const [name, impl] of Object.entries(matchers)) {

packages/@lwc/integration-not-karma/helpers/utils.js

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,6 @@
22
* An as yet uncategorized mishmash of helpers, relics of Karma
33
*/
44

5-
// Listen for errors thrown directly by the callback
6-
function directErrorListener(callback) {
7-
try {
8-
callback();
9-
} catch (error) {
10-
return error;
11-
}
12-
}
13-
14-
// Listen for errors using window.addEventListener('error')
15-
function windowErrorListener(callback) {
16-
let error;
17-
function onError(event) {
18-
event.preventDefault(); // don't log the error
19-
error = event.error;
20-
}
21-
22-
// Prevent jasmine from handling the global error. There doesn't seem to be another
23-
// way to disable this behavior: https://github.com/jasmine/jasmine/pull/1860
24-
const originalOnError = window.onerror;
25-
window.onerror = null;
26-
window.addEventListener('error', onError);
27-
28-
try {
29-
callback();
30-
} finally {
31-
window.onerror = originalOnError;
32-
window.removeEventListener('error', onError);
33-
}
34-
return error;
35-
}
36-
37-
// For errors we expect to be thrown in the connectedCallback() phase
38-
// of a custom element, there are two possibilities:
39-
// 1) We're using non-native lifecycle callbacks, so the error is thrown synchronously
40-
// 2) We're using native lifecycle callbacks, so the error is thrown asynchronously and can
41-
// only be caught with window.addEventListener('error')
42-
// - Note native lifecycle callbacks are all thrown asynchronously.
43-
export function customElementCallbackReactionErrorListener(callback) {
44-
return lwcRuntimeFlags.DISABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE
45-
? directErrorListener(callback)
46-
: windowErrorListener(callback);
47-
}
48-
495
export function extractDataIds(root) {
506
const nodes = {};
517

packages/@lwc/integration-not-karma/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@lwc/synthetic-shadow": "8.22.3",
1717
"@types/chai": "^5.2.2",
1818
"@types/jasmine": "^5.1.9",
19+
"@vitest/expect": "^3.2.4",
1920
"@vitest/spy": "^3.2.4",
2021
"@web/dev-server-import-maps": "^0.2.1",
2122
"@web/dev-server-rollup": "^0.6.4",

0 commit comments

Comments
 (0)