Skip to content

Commit 6aae4b0

Browse files
authored
test(wtr): change jasmine globals to explicit imports @W-19098266 (#5490)
* test(wtr): update tests to use relative path to utils instead of weird fake module * test(wtr): revert removing TestUtils * test(wtr): remove useless describe There's no setup/teardown needed, it's a single test, and WTR provides per-file encapsulation * test(wtr): replace IIFE script with module import * test(wtr): clean up SSR execution script working toward just importing and executing things, but not quite there yet * test(wtr): always use DISABLE_SYNTHETIC two env vars for the same goal is unnecessary * test(wtr): enable all hydration tests I think the last one was a concurrency related timeout, which was previously addressed. * test(wtr): remove side effect from signals helper helper files shouldn't have side effects; all setup should be in the setup file * test(wtr): import directly from file, not from barrel exporter * test(wtr): change bulk export statement to individual exports * test(wtr): remove unnecessary aria re-export * test(wtr): fix a few more ARIA util imports * chore: move comment for nicer aesthetic * test(wtr): remove unused option * test(wtr): fix another ARIA util import * test(wtr): import directly from hooks file rather than utils * test(wtr): import directly from signals file rather than utils * test(wtr): import directly from console helper rather than utils * test(wtr): import directly from constants helper rather than utils * test(wtr): only import what is needed from LWC * test(wtr): split lwc:dynamic load helpers into separate file * test(wtr): avoid relying on global LWC * test(wtr): remove unnecessary wrapping of hydration test config * test(wtr): remove test-utils logic from resolveImport no longer necessary * test(wtr): move plugin from shared config to only config that uses it * test(wtr): remove useless guid all tests are run in isolation * test(wtr): remove unnecessary test-utils global * test(wtr): clean up component definition * test(wtr): change component in test from IIFE to import * test(wtr): shift logic out of wrapper into static test runner file we want to keep the generated wrappers as thin as possible and use regular js files as much as possible * test(wtr): make test setup/teardown more idiomatic * test(wtr): clean up module compilation * chore(wtr): make dependency on @vitest/spy explicit * test(wtr): remove console suppression It was originally implemented to suppress distracting warnings in Karma tests, but WTR's log output is different / managed differently. * test(wtr): clean up names and comments * test(wtr): move and rename file * test(wtr): remove usage of global TestUtils from hydration tests * test(wtr): remove LWC import from utils It breaks hydration tests if there's an import from LWC. * test(wtr): remove unused external deps * test(wtr): use imports instead of jasmine globals * chore(eslint): remove unused rule config
1 parent 3a03a76 commit 6aae4b0

File tree

38 files changed

+72
-48
lines changed

38 files changed

+72
-48
lines changed

eslint.config.mjs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -362,14 +362,8 @@ export default tseslint.config(
362362
lwcRuntimeFlags: true,
363363
process: true,
364364
...globals.browser,
365-
...globals.jasmine,
366365
},
367366
},
368-
369-
rules: {
370-
'no-var': 'off',
371-
'prefer-rest-params': 'off',
372-
},
373367
},
374368
{
375369
files: ['packages/@lwc/integration-karma/**'],
@@ -384,11 +378,6 @@ export default tseslint.config(
384378
...globals.jasmine,
385379
},
386380
},
387-
388-
rules: {
389-
'no-var': 'off',
390-
'prefer-rest-params': 'off',
391-
},
392381
},
393382
{
394383
files: ['packages/@lwc/synthetic-shadow/**'],
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { spyOn, fn } from '@vitest/spy';
2+
3+
/**
4+
* Adds the jasmine interfaces we use in the Karma tests to a Vitest spy.
5+
* Should ultimately be removed and tests updated to use Vitest spies.
6+
* @param {import('@vitest/spy').MockInstance}
7+
*/
8+
function jasmineSpyAdapter(spy) {
9+
Object.defineProperties(spy, {
10+
and: { get: () => spy },
11+
calls: { get: () => spy.mock.calls },
12+
returnValue: { value: () => spy.mockReturnValue() },
13+
// calling mockImplementation() with nothing restores the original
14+
callThrough: { value: () => spy.mockImplementation() },
15+
callFake: { value: (impl) => spy.mockImplementation(impl) },
16+
});
17+
18+
Object.defineProperties(spy.mock.calls, {
19+
// Must be non-enumerable for equality checks to work on array literal expected values
20+
allArgs: { value: () => spy.mock.calls },
21+
count: { value: () => spy.mock.calls.length },
22+
reset: { value: () => spy.mockReset() },
23+
argsFor: { value: (index) => spy.mock.calls.at(index) },
24+
});
25+
26+
return spy;
27+
}
28+
29+
export const jasmineSpyOn = (object, prop) => jasmineSpyAdapter(spyOn(object, prop));
30+
export const jasmine = {
31+
any: expect.any,
32+
arrayWithExactContents: () => {
33+
throw new Error('TODO: jasmine.arrayWithExactContents');
34+
},
35+
createSpy: (name, impl) => jasmineSpyAdapter(fn(impl)),
36+
objectContaining: expect.objectContaining,
37+
};

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

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// This import ensures that the global `Mocha` object is present for mutation.
22
import { JestAsymmetricMatchers, JestChaiExpect, JestExtend } from '@vitest/expect';
33
import * as chai from 'chai';
4-
import { spyOn, fn } from '@vitest/spy';
54
import { registerCustomMatchers } from './matchers/index.js';
65
import { initSignals } from './signals.js';
76

@@ -15,44 +14,8 @@ chai.use(JestChaiExpect);
1514
chai.use(JestAsymmetricMatchers);
1615
// add our custom matchers
1716
chai.use(registerCustomMatchers);
18-
19-
/**
20-
* Adds the jasmine interfaces we use in the Karma tests to a Vitest spy.
21-
* Should ultimately be removed and tests updated to use Vitest spies.
22-
* @param {import('@vitest/spy').MockInstance}
23-
*/
24-
function jasmineSpyAdapter(spy) {
25-
Object.defineProperties(spy, {
26-
and: { get: () => spy },
27-
calls: { get: () => spy.mock.calls },
28-
returnValue: { value: () => spy.mockReturnValue() },
29-
// calling mockImplementation() with nothing restores the original
30-
callThrough: { value: () => spy.mockImplementation() },
31-
callFake: { value: (impl) => spy.mockImplementation(impl) },
32-
});
33-
34-
Object.defineProperties(spy.mock.calls, {
35-
// Must be non-enumerable for equality checks to work on array literal expected values
36-
allArgs: { value: () => spy.mock.calls },
37-
count: { value: () => spy.mock.calls.length },
38-
reset: { value: () => spy.mockReset() },
39-
argsFor: { value: (index) => spy.mock.calls.at(index) },
40-
});
41-
42-
return spy;
43-
}
44-
4517
// expose so we don't need to import `expect` in every test file
4618
globalThis.expect = chai.expect;
47-
globalThis.spyOn = (object, prop) => jasmineSpyAdapter(spyOn(object, prop));
48-
globalThis.jasmine = {
49-
any: expect.any,
50-
arrayWithExactContents: () => {
51-
throw new Error('TODO: jasmine.arrayWithExactContents');
52-
},
53-
createSpy: (name, impl) => jasmineSpyAdapter(fn(impl)),
54-
objectContaining: expect.objectContaining,
55-
};
5619

5720
/**
5821
* `@web/test-runner-mocha`'s autorun.js file inlines its own copy of mocha, and there's no direct

packages/@lwc/integration-not-karma/test/accessibility/non-standard-aria-props/index.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createElement } from 'lwc';
22
import Light from 'x/light';
33
import Shadow from 'x/shadow';
4+
import { jasmine } from '../../../helpers/jasmine.js';
45
import { nonStandardAriaProperties } from '../../../helpers/aria.js';
56
import {
67
attachReportingControlDispatcher,

packages/@lwc/integration-not-karma/test/accessibility/synthetic-cross-root-aria/index.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { createElement } from 'lwc';
22

33
import AriaContainer from 'x/ariaContainer';
44
import Valid from 'x/valid';
5+
import { jasmine } from '../../../helpers/jasmine.js';
56
import {
67
attachReportingControlDispatcher,
78
detachReportingControlDispatcher,

packages/@lwc/integration-not-karma/test/api/freezeTemplate/index.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { registerTemplate, freezeTemplate, setFeatureFlagForTest } from 'lwc';
2+
import { jasmine } from '../../../helpers/jasmine.js';
23

34
import {
45
attachReportingControlDispatcher,

packages/@lwc/integration-not-karma/test/api/getComponentDef/index.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import PublicPropertiesInheritance from 'x/publicPropertiesInheritance';
77
import PublicMethodsInheritance from 'x/publicMethodsInheritance';
88
import PrivateAccessors from 'x/privateAccessors';
99
import HtmlElementProps from 'x/htmlElementProps';
10+
import { jasmine } from '../../../helpers/jasmine.js';
1011
import { ariaProperties } from '../../../helpers/aria.js';
1112

1213
function testInvalidComponentConstructor(name, ctor) {

packages/@lwc/integration-not-karma/test/api/isNodeFromTemplate/index.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createElement, isNodeFromTemplate } from 'lwc';
22
import Test from 'x/test';
3+
import { jasmineSpyOn as spyOn } from '../../../helpers/jasmine.js';
34

45
function testNonNodes(type, obj) {
56
it(`should return false if the passed object if a ${type}`, () => {

packages/@lwc/integration-not-karma/test/api/sanitizeHtmlContent/index.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createElement } from 'lwc';
22
import XInnerHtml from 'x/innerHtml';
3+
import { jasmine } from '../../../helpers/jasmine.js';
34
import { getHooks, setHooks } from '../../../helpers/hooks.js';
45

56
const ACTUAL_CONTENT = 'Hello <b>World</b>';

packages/@lwc/integration-not-karma/test/component/LightningElement.disconnectedCallback/index.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Test from 'x/test';
55
import DisconnectedCallbackThrow from 'x/disconnectedCallbackThrow';
66
import DualTemplate from 'x/dualTemplate';
77
import ExplicitRender from 'x/explicitRender';
8+
import { jasmine } from '../../../helpers/jasmine.js';
89
import { customElementCallbackReactionErrorListener } from '../../../helpers/utils.js';
910

1011
function testDisconnectSlot(name, fn) {

0 commit comments

Comments
 (0)