Skip to content

Commit

Permalink
[IMP] tests: use inline snapshots for lifecycle checks
Browse files Browse the repository at this point in the history
This allows them to be updated automatically when needed instead of
having to update them by hand.
  • Loading branch information
sdegueldre authored and ged-odoo committed Oct 4, 2023
1 parent 0d341d9 commit 0048205
Show file tree
Hide file tree
Showing 17 changed files with 3,330 additions and 2,508 deletions.
2 changes: 1 addition & 1 deletion tests/app/__snapshots__/app.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ exports[`app app: clear scheduler tasks and destroy cancelled nodes immediately
}"
`;
exports[`app app: clear scheduler tasks and destroy cancelled nodes immediately on destroy 2`] = `
exports[`app app: clear scheduler tasks and destroy cancelled nodes immediately on destroy 3`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
Expand Down
43 changes: 34 additions & 9 deletions tests/app/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
useLogLifecycle,
makeDeferred,
nextMicroTick,
steps,
} from "../helpers";

let fixture: HTMLElement;
Expand Down Expand Up @@ -123,23 +124,47 @@ describe("app", () => {

const app = new App(A);
const comp = await app.mount(fixture);
expect(["A:setup", "A:willStart", "A:willRender", "A:rendered", "A:mounted"]).toBeLogged();
expect(steps.splice(0)).toMatchInlineSnapshot(`
Array [
"A:setup",
"A:willStart",
"A:willRender",
"A:rendered",
"A:mounted",
]
`);

comp.state.value = true;
await nextTick();
expect(["A:willRender", "B:setup", "B:willStart", "A:rendered"]).toBeLogged();
expect(steps.splice(0)).toMatchInlineSnapshot(`
Array [
"A:willRender",
"B:setup",
"B:willStart",
"A:rendered",
]
`);

// rerender to force the instantiation of a new B component (and cancelling the first)
comp.render();
await nextMicroTick();
expect(["A:willRender", "B:setup", "B:willStart", "A:rendered"]).toBeLogged();
expect(steps.splice(0)).toMatchInlineSnapshot(`
Array [
"A:willRender",
"B:setup",
"B:willStart",
"A:rendered",
]
`);

app.destroy();
expect([
"A:willUnmount",
"B:willDestroy",
"A:willDestroy",
"B:willDestroy", // make sure the 2 B instances have been destroyed synchronously
]).toBeLogged();
expect(steps.splice(0)).toMatchInlineSnapshot(`
Array [
"A:willUnmount",
"B:willDestroy",
"A:willDestroy",
"B:willDestroy",
]
`);
});
});
30 changes: 15 additions & 15 deletions tests/components/__snapshots__/concurrency.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ exports[`changing state before first render does not trigger a render (with pare
}"
`;

exports[`changing state before first render does not trigger a render (with parent) 2`] = `
exports[`changing state before first render does not trigger a render (with parent) 3`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
Expand Down Expand Up @@ -254,7 +254,7 @@ exports[`components are not destroyed between animation frame 1`] = `
}"
`;

exports[`components are not destroyed between animation frame 2`] = `
exports[`components are not destroyed between animation frame 3`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
Expand All @@ -268,7 +268,7 @@ exports[`components are not destroyed between animation frame 2`] = `
}"
`;

exports[`components are not destroyed between animation frame 3`] = `
exports[`components are not destroyed between animation frame 5`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
Expand Down Expand Up @@ -748,7 +748,7 @@ exports[`concurrent renderings scenario 10 2`] = `
}"
`;

exports[`concurrent renderings scenario 10 3`] = `
exports[`concurrent renderings scenario 10 4`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
Expand Down Expand Up @@ -993,7 +993,7 @@ exports[`concurrent renderings scenario 16 3`] = `
}"
`;

exports[`concurrent renderings scenario 16 4`] = `
exports[`concurrent renderings scenario 16 6`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
Expand Down Expand Up @@ -1024,7 +1024,7 @@ exports[`creating two async components, scenario 1 1`] = `
}"
`;

exports[`creating two async components, scenario 1 2`] = `
exports[`creating two async components, scenario 1 3`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
Expand All @@ -1038,7 +1038,7 @@ exports[`creating two async components, scenario 1 2`] = `
}"
`;

exports[`creating two async components, scenario 1 3`] = `
exports[`creating two async components, scenario 1 5`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
Expand Down Expand Up @@ -1085,7 +1085,7 @@ exports[`creating two async components, scenario 2 2`] = `
}"
`;

exports[`creating two async components, scenario 2 3`] = `
exports[`creating two async components, scenario 2 5`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
Expand Down Expand Up @@ -1133,7 +1133,7 @@ exports[`creating two async components, scenario 3 (patching in the same frame)
}"
`;

exports[`creating two async components, scenario 3 (patching in the same frame) 3`] = `
exports[`creating two async components, scenario 3 (patching in the same frame) 5`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
Expand Down Expand Up @@ -1308,7 +1308,7 @@ exports[`delayed render does not go through when t-component value changed 2`] =
}"
`;

exports[`delayed render does not go through when t-component value changed 3`] = `
exports[`delayed render does not go through when t-component value changed 4`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
Expand Down Expand Up @@ -1617,7 +1617,7 @@ exports[`destroyed component causes other soon to be destroyed component to rere
}"
`;

exports[`destroyed component causes other soon to be destroyed component to rerender, weird stuff happens 2`] = `
exports[`destroyed component causes other soon to be destroyed component to rerender, weird stuff happens 3`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
Expand All @@ -1628,7 +1628,7 @@ exports[`destroyed component causes other soon to be destroyed component to rere
}"
`;

exports[`destroyed component causes other soon to be destroyed component to rerender, weird stuff happens 3`] = `
exports[`destroyed component causes other soon to be destroyed component to rerender, weird stuff happens 4`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
Expand Down Expand Up @@ -1656,7 +1656,7 @@ exports[`destroying/recreating a subcomponent, other scenario 1`] = `
}"
`;

exports[`destroying/recreating a subcomponent, other scenario 2`] = `
exports[`destroying/recreating a subcomponent, other scenario 3`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
Expand Down Expand Up @@ -1685,7 +1685,7 @@ exports[`destroying/recreating a subwidget with different props (if start is not
}"
`;

exports[`destroying/recreating a subwidget with different props (if start is not over) 2`] = `
exports[`destroying/recreating a subwidget with different props (if start is not over) 3`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
Expand Down Expand Up @@ -1787,7 +1787,7 @@ exports[`rendering component again in next microtick 1`] = `
}"
`;

exports[`rendering component again in next microtick 2`] = `
exports[`rendering component again in next microtick 3`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
Expand Down
2 changes: 1 addition & 1 deletion tests/components/__snapshots__/error_handling.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ exports[`can catch errors an error in onWillDestroy, variation 1`] = `
}"
`;

exports[`can catch errors an error in onWillDestroy, variation 2`] = `
exports[`can catch errors an error in onWillDestroy, variation 3`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
Expand Down
12 changes: 6 additions & 6 deletions tests/components/__snapshots__/lifecycle.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ exports[`lifecycle hooks component semantics 5`] = `
}"
`;

exports[`lifecycle hooks component semantics 6`] = `
exports[`lifecycle hooks component semantics 7`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
Expand Down Expand Up @@ -185,7 +185,7 @@ exports[`lifecycle hooks destroy new children before being mountged 1`] = `
}"
`;

exports[`lifecycle hooks destroy new children before being mountged 2`] = `
exports[`lifecycle hooks destroy new children before being mountged 3`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
Expand Down Expand Up @@ -291,7 +291,7 @@ exports[`lifecycle hooks lifecycle semantics, part 2 1`] = `
}"
`;

exports[`lifecycle hooks lifecycle semantics, part 2 2`] = `
exports[`lifecycle hooks lifecycle semantics, part 2 3`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
Expand All @@ -303,7 +303,7 @@ exports[`lifecycle hooks lifecycle semantics, part 2 2`] = `
}"
`;

exports[`lifecycle hooks lifecycle semantics, part 2 3`] = `
exports[`lifecycle hooks lifecycle semantics, part 2 4`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
Expand Down Expand Up @@ -348,7 +348,7 @@ exports[`lifecycle hooks lifecycle semantics, part 4 1`] = `
}"
`;

exports[`lifecycle hooks lifecycle semantics, part 4 2`] = `
exports[`lifecycle hooks lifecycle semantics, part 4 3`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
Expand All @@ -360,7 +360,7 @@ exports[`lifecycle hooks lifecycle semantics, part 4 2`] = `
}"
`;

exports[`lifecycle hooks lifecycle semantics, part 4 3`] = `
exports[`lifecycle hooks lifecycle semantics, part 4 4`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
Expand Down
2 changes: 1 addition & 1 deletion tests/components/__snapshots__/t_component.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ exports[`t-component switching dynamic component 2`] = `
}"
`;
exports[`t-component switching dynamic component 3`] = `
exports[`t-component switching dynamic component 4`] = `
"function anonymous(app, bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, comment } = bdom;
Expand Down
Loading

0 comments on commit 0048205

Please sign in to comment.