Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dmail committed Aug 19, 2024
1 parent 1757e9e commit dac1979
Show file tree
Hide file tree
Showing 16 changed files with 125 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ import { createReplaceFilesystemWellKnownValues } from "../filesystem_well_known
import { filesystemSideEffects } from "./filesystem/filesystem_side_effects.js";
import { logSideEffects } from "./log/log_side_effects.js";

const executionEffectsDefault = {
catch: true,
return: true,
};

export const createCaptureSideEffects = ({
sourceFileUrl,
logEffects = true,
filesystemEffects = true,
filesystemActions,
executionEffects = {},
executionEffects = executionEffectsDefault,
rootDirectoryUrl,
replaceFilesystemWellKnownValues = createReplaceFilesystemWellKnownValues({
rootDirectoryUrl,
Expand All @@ -21,6 +26,7 @@ export const createCaptureSideEffects = ({
return: false,
};
}
executionEffects = { ...executionEffectsDefault, ...executionEffects };

const detectors = [];
if (logEffects) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ import { snapshotSideEffects } from "@jsenv/snapshot";
throw new Error("in the end we throw");
},
{
executionEffects: { catch: true },
sideEffectMdFileUrl: new URL(
"./output/6_console_and_file.md",
import.meta.url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ await snapshotTests(
});
},
{
executionEffects: { catch: true },
outFilePattern: "./git_ignored/[filename]",
},
);
Expand All @@ -46,6 +47,7 @@ await snapshotSideEffects(
});
},
{
executionEffect: { catch: true },
throwWhenDiff: true,
outFilePattern: "./git_ignored/[filename]",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ const run = async ({ browserLauncher }) => {
});
};

await snapshotDevSideEffects(import.meta.url, ({ test }) => {
test("0_chromium", () => run({ browserLauncher: chromium }));
});
await snapshotDevSideEffects(
import.meta.url,
({ test }) => {
test("0_chromium", () => run({ browserLauncher: chromium }));
},
{
executionEffects: { catch: true },
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,25 @@ const run = async ({ runtime }) => {
});
};

await snapshotFileExecutionSideEffects(import.meta.url, async ({ test }) => {
test("0_chromium", () =>
run({
runtime: chromium(),
}));
test("1_firefox", () =>
run({
runtime: firefox({
disableOnWindowsBecauseFlaky: false,
}),
}));
test("2_webkit", () =>
run({
runtime: webkit(),
}));
});
await snapshotFileExecutionSideEffects(
import.meta.url,
async ({ test }) => {
test("0_chromium", () =>
run({
runtime: chromium(),
}));
test("1_firefox", () =>
run({
runtime: firefox({
disableOnWindowsBecauseFlaky: false,
}),
}));
test("2_webkit", () =>
run({
runtime: webkit(),
}));
},
{
executionEffects: { catch: true },
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ const run = async ({ runtime }) => {
});
};

await snapshotFileExecutionSideEffects(import.meta.url, async ({ test }) => {
test("0_worker_thread", () =>
run({
runtime: nodeWorkerThread(),
}));
test("0_child_process", () =>
run({
runtime: nodeChildProcess(),
}));
});
await snapshotFileExecutionSideEffects(
import.meta.url,
async ({ test }) => {
test("0_worker_thread", () =>
run({
runtime: nodeWorkerThread(),
}));
test("0_child_process", () =>
run({
runtime: nodeChildProcess(),
}));
},
{
executionEffects: { catch: true },
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,23 @@ const run = async ({ runtime }) => {
});
};

await snapshotFileExecutionSideEffects(import.meta.url, async ({ test }) => {
test("0_chromium", () =>
run({
runtime: chromium(),
}));
test("1_firefox", () =>
run({
runtime: firefox({ disableOnWindowsBecauseFlaky: false }),
}));
test("2_webkit", () =>
run({
runtime: webkit(),
}));
});
await snapshotFileExecutionSideEffects(
import.meta.url,
async ({ test }) => {
test("0_chromium", () =>
run({
runtime: chromium(),
}));
test("1_firefox", () =>
run({
runtime: firefox({ disableOnWindowsBecauseFlaky: false }),
}));
test("2_webkit", () =>
run({
runtime: webkit(),
}));
},
{
executionEffects: { catch: true },
},
);
12 changes: 10 additions & 2 deletions packages/related/test/tests/snapshot_execution_side_effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ export const snapshotFileExecutionSideEffects = async (
options = {},
) =>
snapshotTests(testFileUrl, fnRegisteringTests, {
...options,
filesystemActions: {
"**": "compare",
"**/.jsenv/": "undo",
},
...options,
executionEffects: {
catch: false,
...options.executionEffects,
},
});

export const snapshotTestPlanSideEffects = async (
Expand All @@ -19,12 +23,16 @@ export const snapshotTestPlanSideEffects = async (
options = {},
) =>
snapshotTests(testFileUrl, fnRegisteringTests, {
...options,
filesystemActions: {
"**": "compare",
"**/.jsenv/": "undo",
"**/*.png": process.env.CI ? "compare_presence_only" : "compare",
"**/*.gif": "ignore",
"**/.coverage/": "ignore",
},
...options,
executionEffects: {
catch: false,
...options.executionEffects,
},
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [0_chromium](../../js_export_missing_dev.test.mjs#L26)
# [0_chromium](../../js_export_missing_dev.test.mjs#L28)

```js
run({ browserLauncher: chromium })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ const run = async () => {
});
};

await snapshotDevSideEffects(import.meta.url, ({ test }) => {
test("0_chromium", () => run({ browserLauncher: chromium }));
});
await snapshotDevSideEffects(
import.meta.url,
({ test }) => {
test("0_chromium", () => run({ browserLauncher: chromium }));
},
{
executionEffects: { catch: true },
},
);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [0_chromium](../../js_syntax_error_dev.test.mjs#L26)
# [0_chromium](../../js_syntax_error_dev.test.mjs#L28)

```js
run({ browserLauncher: chromium })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ const run = async () => {
});
};

await snapshotDevSideEffects(import.meta.url, ({ test }) => {
test("0_chromium", () => run({ browserLauncher: chromium }));
});
await snapshotDevSideEffects(
import.meta.url,
({ test }) => {
test("0_chromium", () => run({ browserLauncher: chromium }));
},
{
executionEffects: { catch: true },
},
);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [0_chromium](../../js_throw_dev.test.mjs#L26)
# [0_chromium](../../js_throw_dev.test.mjs#L28)

```js
run({ browserLauncher: chromium })
Expand Down
12 changes: 9 additions & 3 deletions tests/dev_and_build/errors/js_throw/js_throw_dev.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ const run = async () => {
});
};

await snapshotDevSideEffects(import.meta.url, ({ test }) => {
test("0_chromium", () => run({ browserLauncher: chromium }));
});
await snapshotDevSideEffects(
import.meta.url,
({ test }) => {
test("0_chromium", () => run({ browserLauncher: chromium }));
},
{
executionEffects: { catch: true },
},
);
4 changes: 4 additions & 0 deletions tests/snapshot_build_side_effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ export const snapshotBuildTests = async (
level: "warn",
...(options.logEffects === true ? {} : options.logEffects),
},
executionEffects: {
catch: false,
...options.executionEffects,
},
});
4 changes: 4 additions & 0 deletions tests/snapshot_dev_side_effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ export const snapshotDevSideEffects = async (
level: "warn",
...(options.logEffects === true ? {} : options.logEffects),
},
executionEffects: {
catch: false,
...options.executionEffects,
},
});

0 comments on commit dac1979

Please sign in to comment.