Skip to content

Commit a5b0209

Browse files
authored
test(wtr): get another pile of tests passing (#5425)
* refactor(wtr): move NODE_ENV_FOR_TEST default into options file * chore(wtr): move hooks util to separate file * chore(wtr): move aria utils to separate file * chore(wtr): move constants to separate file * chore(wtr): clean up custom rollup plugin * test(wtr): get hydration tests kinda running * test(wtr): kinda start moving to ESM instead of IIFE * fix(shared): make sanitizeHtmlContent work * chore(ci): run hydration tests in ci * test(wtr): remove unused script * test(wtr): implement missing jasmine assertions * test(wtr): clean up test to make assertions more clear * test(wtr): implement custom console matchers * test(wtr): use simpler console spy * test(wtr): remove outdated, unnecessary spies * test(wtr): move signals util to own file * test(wtr): implement custom error matchers everything passed first try, which is kinda sus * chore: split matchers into separate files * chore: ugh tui go away * chore: remove unused file code is now in helpers/matchers/index.mjs * test(wtr): conditionally import polyfills reduces test failures from 291 to 220 * test(wtr): use one setup file instead of two * chore: add comment explaining file * chore(wtr): rename file * chore(wtr): move test configs into directory * chore(wtr): extract shared parts of config into base config object * chore(wtr): rename config files who needs convention? * chore(wtr): move WTR plugins from helpers dir to config dir * chore: move full plugins to plugin files instead of just inner logic * test(wtr): not all env vars are boolean fixes ~50 test failures * test(wtr): make tests async so they clean up properly I'm not sure why the async matters, but it does. * test(wtr): fix resolution of wire-service * test(wtr): skip flaky tests * test(wtr): add more jasmine spy adapter methods * test(wtr): enable passing tests turns out they just had browser log warnings, not failures * test(wtr): make spy props non-enumerable * test(wtr): remove unused matcher * test(wtr): fix assertion to match error message * test(wtr): implement jasmine.any * test(wtr): mark test as flaky timeout * update comment * update comment * test(wtr): move scripts to head instead of body tests manipulate the body, so we use head for scripts to keep the body clean * Update packages/@lwc/integration-not-karma/configs/base.mjs * Update packages/@lwc/integration-not-karma/configs/base.mjs * test(wtr): clean DOM after each test * test(wtr): implement callFake jasmine adapter * test(wtr): add missing argsFor jasmine adapter * test(wtr): add missing toHaveBeenCalledOnceWith assertion * test(wtr): categorize failures * test(wtr): fix .toMatch and categorize failing files * test(wtr): using detached objectContaining does not work it breaks the required `this` reference * test(wtr): add pre-test assertion checking for window focus * test(wtr): eliminate concurrency it messes with focus and breaks tests * chore(deps): bump @web/test-runner to latest * test(wtr): reset logged messages after each test * chore(wtr): link potential workaround for concurrency issue * test(wtr): reset logs between all tests * test(wtr): fix more toMatch failures * chore(deps): bump chai
1 parent da10730 commit a5b0209

File tree

16 files changed

+59
-51
lines changed

16 files changed

+59
-51
lines changed

packages/@lwc/integration-karma/test/component/LightningElement.attachInternals/api/index.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const attachInternalsSanityTest = (tagName, ctor) => {
3939
});
4040

4141
afterAll(() => {
42-
document.body.removeChild(elm);
42+
elm.remove();
4343
});
4444

4545
it('should be able to create ElementInternals object', () => {

packages/@lwc/integration-karma/test/events/focus-event-related-target/index.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Container from 'x/container';
66
// So this test may "flap" during local development if your browser window isn't focused (e.g. you're focused on
77
// the DevTools instead).
88
it('should retarget relatedTarget', function () {
9+
expect(document.hasFocus(), 'Browser window must be focused for test to work').toBe(true);
910
const elm = createElement('x-container', { is: Container });
1011
document.body.appendChild(elm);
1112

packages/@lwc/integration-karma/test/light-dom/slot-fowarding/scoped-slots/index.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('scoped slots, slot forwarding', () => {
1010
});
1111

1212
afterAll(() => {
13-
document.body.removeChild(lightContainer);
13+
lightContainer.remove();
1414
});
1515

1616
// TODO [#3889]: This test should be updated once a fix is ready.

packages/@lwc/integration-karma/test/light-dom/slot-fowarding/slots/forwarding/index.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('slot forwarding', () => {
5757
});
5858

5959
afterAll(() => {
60-
document.body.removeChild(lightContainer);
60+
lightContainer.remove();
6161
});
6262

6363
it('should correctly forward slot assignments - light > light slot', () => {

packages/@lwc/integration-karma/test/light-dom/slot-fowarding/slots/reactivity/index.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ describe('light DOM slot forwarding reactivity', () => {
77
let nodes;
88
let lightContainer;
99

10-
beforeAll(() => {
10+
beforeEach(() => {
1111
lightContainer = createElement('x-light-container', { is: LightContainer });
1212
document.body.appendChild(lightContainer);
1313
nodes = extractDataIds(lightContainer);
1414
});
1515

16-
afterAll(() => {
17-
document.body.removeChild(lightContainer);
16+
afterEach(() => {
17+
lightContainer.remove();
1818
});
1919

2020
const verifySlotContent = (leaf, expected) => {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import Child from 'x/child';
44
import GetterThrows from 'x/getterThrows';
55

66
const arr = jasmine.arrayWithExactContents;
7-
const obj = jasmine.objectContaining;
7+
// `jasmine.objectContaining` is long, but the method can't be detached/aliased, ergo wrapper
8+
const obj = (val) => jasmine.objectContaining(val);
89

910
let entries = [];
1011

packages/@lwc/integration-karma/test/regression/invalid-key/index.spec.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ it('W-15885661 - renders list when key is invalid (preserve backwards compat)',
1515
elm.items = [{ value: 1 }];
1616
await Promise.resolve();
1717

18-
const {
19-
calls: { error },
20-
} = spy;
21-
expect(error.length).toBe(process.env.NODE_ENV === 'production' ? 0 : 2);
22-
error.forEach((error) =>
23-
expect(error).toMatch(/(Invalid key value.*|Invalid "key" attribute.*)/)
24-
);
18+
const errorCalls = spy.calls.error;
19+
expect(errorCalls.length).toBe(process.env.NODE_ENV === 'production' ? 0 : 2);
20+
errorCalls.forEach(([error]) => {
21+
expect(error).toBeInstanceOf(Error);
22+
expect(error.message).toMatch(/(Invalid key value.*|Invalid "key" attribute.*)/);
23+
});
2524

2625
spy.reset();
2726

packages/@lwc/integration-karma/test/rendering/sanitize-stylesheet-token/index.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ props.forEach((prop) => {
8989
} else {
9090
// dev mode
9191
expect(logger).toHaveBeenCalledTimes(1);
92-
expect(logger.calls.allArgs()[0]).toMatch(
92+
const loggedError = logger.calls.allArgs()[0][0];
93+
expect(loggedError.message).toMatch(
9394
new RegExp(
9495
`Mutating the "${prop}" property on a template is deprecated`
9596
)

packages/@lwc/integration-karma/test/static-content/index.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ describe('text containing comments', () => {
819819
describe(`preserveComments ${preserveComments}`, () => {
820820
let elm;
821821
let nodes;
822-
beforeAll(async () => {
822+
beforeEach(async () => {
823823
elm = createElement(tagName, {
824824
is: ctor,
825825
});
@@ -829,7 +829,7 @@ describe('text containing comments', () => {
829829
});
830830

831831
afterAll(() => {
832-
document.body.removeChild(elm);
832+
elm.remove();
833833
});
834834

835835
const assertChildNodesInnerHTMLMatches = (actual, expected) => {

packages/@lwc/integration-karma/test/template/directive-for-each/index.spec.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ describe('null/undefined values', () => {
9696
expect(spy.calls.error.length).toBe(0);
9797
} else {
9898
expect(spy.calls.error.length).toBe(1);
99+
const err = spy.calls.error[0][0]; // first arg of first call
100+
expect(err).toBeInstanceOf(Error);
99101
// TODO [#1283]: Improve this error message. The vm should not be exposed and the message is not helpful.
100-
expect(spy.calls.error[0]).toMatch(/It must be an array-like object/);
102+
expect(err.message).toMatch(/It must be an array-like object/);
101103
}
102104
});
103105
});

0 commit comments

Comments
 (0)