Skip to content

Commit 9f94468

Browse files
committed
test(wtr): implement missing jasmine matcher
1 parent 3747a46 commit 9f94468

File tree

6 files changed

+28
-17
lines changed

6 files changed

+28
-17
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 & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ import testPlugin from './plugins/serve-integration.js';
55
/** @type {import("@web/test-runner").TestRunnerConfig} */
66
export default {
77
...baseConfig,
8-
files: [
9-
'test/**/*.spec.js',
10-
// Implement objectContaining / arrayWithExactContents
11-
'!test/profiler/mutation-logging/index.spec.js',
12-
],
8+
files: ['test/**/*.spec.js'],
139
plugins: [
1410
...baseConfig.plugins,
1511
importMapsPlugin({ inject: { importMap: { imports: { lwc: './mocks/lwc.js' } } } }),

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ const transform = async (ctx) => {
8181
plugins: [customLwcRollupPlugin],
8282

8383
external: [
84+
'@vitest/expect',
8485
'@vitest/spy',
8586
'lwc',
8687
'wire-service',

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",

packages/@lwc/integration-not-karma/test/profiler/mutation-logging/index.spec.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,40 @@ import { createElement } from 'lwc';
22
import Parent from 'x/parent';
33
import Child from 'x/child';
44
import GetterThrows from 'x/getterThrows';
5-
import { jasmine, jasmineSpyOn as spyOn } from '../../../helpers/jasmine.js';
5+
import { ArrayContaining } from '@vitest/expect';
6+
import { spyOn } from '@vitest/spy';
7+
8+
class ArrayWithExactContents extends ArrayContaining {
9+
asymmetricMatch(other) {
10+
return (
11+
super.asymmetricMatch(other) &&
12+
(this.inverse
13+
? this.sample.length !== other.length
14+
: this.sample.length === other.length)
15+
);
16+
}
17+
}
618

7-
const arr = jasmine.arrayWithExactContents;
8-
// `jasmine.objectContaining` is long, but the method can't be detached/aliased, ergo wrapper
9-
const obj = (val) => jasmine.objectContaining(val);
19+
const arr = (val) => new ArrayWithExactContents(val);
20+
const obj = (val) => expect.objectContaining(val);
1021

1122
let entries = [];
1223

13-
beforeEach(() => {
14-
const perfMeasure = performance.measure.bind(performance);
15-
16-
// We could use PerformanceObserver for this, but it's awkward and unreliable for unit testing
17-
// See: https://github.com/salesforce/lwc/issues/4600
18-
spyOn(performance, 'measure').and.callFake((...args) => {
19-
const entry = perfMeasure(...args);
24+
beforeAll(() => {
25+
const realMeasure = performance.measure.bind(performance);
26+
spyOn(performance, 'measure').mockImplementation((...args) => {
27+
const entry = realMeasure(...args);
2028
if (['lwc-render', 'lwc-rerender'].includes(entry.name)) {
2129
entries.push(entry);
2230
}
2331
return entry;
2432
});
2533
});
2634

35+
afterAll(() => {
36+
performance.measure.mockRestore();
37+
});
38+
2739
afterEach(() => {
2840
entries = [];
2941
});

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3569,7 +3569,7 @@
35693569
"@typescript-eslint/scope-manager" "^8.41.0"
35703570
"@typescript-eslint/utils" "^8.24.1"
35713571

3572-
"@vitest/expect@3.2.4":
3572+
"@vitest/expect@3.2.4", "@vitest/expect@^3.2.4":
35733573
version "3.2.4"
35743574
resolved "https://registry.yarnpkg.com/@vitest/expect/-/expect-3.2.4.tgz#8362124cd811a5ee11c5768207b9df53d34f2433"
35753575
integrity sha512-Io0yyORnB6sikFlt8QW5K7slY4OjqNX9jmJQ02QDda8lyM6B5oNgVWoSoKPac8/kgnCUzuHQKrSLtu/uOqqrig==

0 commit comments

Comments
 (0)