From 8c4dff72a70b5656d6e0bb9f90626f4112bedbf2 Mon Sep 17 00:00:00 2001 From: UnderKoen Date: Wed, 17 Jan 2024 19:57:15 +0100 Subject: [PATCH] chore: split snapshots --- test.js | 6 +- test/bin.snapshot | 44 ----------- test/bin.ts | 76 +++++++++++++------ .../testing.args -- WOWOWOW.snapshot | 11 +++ test/snapshots/testing.array.snapshot | 8 ++ test/snapshots/testing.default.snapshot | 4 + test/snapshots/testing.env.file.snapshot | 9 +++ test/snapshots/testing.env.overrides.snapshot | 5 ++ test/snapshots/testing.env.snapshot | 5 ++ test/snapshots/testing.error.all.snapshot | 11 +++ test/snapshots/testing.error.catch.snapshot | 5 ++ test/snapshots/testing.error.finally.snapshot | 8 ++ test/snapshots/testing.error.onError.snapshot | 8 ++ test/snapshots/testing.functions.snapshot | 13 ++++ test/snapshots/testing.hooks.snapshot | 10 +++ test/snapshots/testing.relative.snapshot | 5 ++ 16 files changed, 158 insertions(+), 70 deletions(-) delete mode 100644 test/bin.snapshot create mode 100644 test/snapshots/testing.args -- WOWOWOW.snapshot create mode 100644 test/snapshots/testing.array.snapshot create mode 100644 test/snapshots/testing.default.snapshot create mode 100644 test/snapshots/testing.env.file.snapshot create mode 100644 test/snapshots/testing.env.overrides.snapshot create mode 100644 test/snapshots/testing.env.snapshot create mode 100644 test/snapshots/testing.error.all.snapshot create mode 100644 test/snapshots/testing.error.catch.snapshot create mode 100644 test/snapshots/testing.error.finally.snapshot create mode 100644 test/snapshots/testing.error.onError.snapshot create mode 100644 test/snapshots/testing.functions.snapshot create mode 100644 test/snapshots/testing.hooks.snapshot create mode 100644 test/snapshots/testing.relative.snapshot diff --git a/test.js b/test.js index c8e6b02..efa77cc 100644 --- a/test.js +++ b/test.js @@ -64,7 +64,7 @@ module.exports = { _catch: "exit 3", _finally: "echo finally", }, - _catch: "echo %BSM_ERROR%", + _catch: () => `echo ${process.env.BSM_ERROR}`, }, functions: { _default: "bsm ~.*", @@ -82,10 +82,10 @@ module.exports = { return() { return "exit 1"; }, - _onError: "echo %BSM_ERROR%", + _onError: () => `echo ${process.env.BSM_ERROR}`, }, _pre: { - _default: 'echo "pre test"', + _default: "echo pre test", }, }, env: { diff --git a/test/bin.snapshot b/test/bin.snapshot deleted file mode 100644 index cb83e5d..0000000 --- a/test/bin.snapshot +++ /dev/null @@ -1,44 +0,0 @@ -> echo default (testing.default._default) -default -> echo Windows (testing.os._win32) -Windows -> echo pre args (testing.args._pre) -pre args -> bsm testing.args.* -- (testing.args._default) -> echo pre args (testing.args._pre) -pre args -> echo (testing.args.echo) -ECHO is on. -> echo (testing.args.echo2) -ECHO is on. -> echo 1 (testing.array.0) -1 -> echo 2 (testing.array.1) -2 -> echo 3 (testing.array.2) -3 -> echo pre hooks (testing.hooks._pre) -pre hooks -> echo hooks1 (testing.hooks._default.0) -hooks1 -> echo hooks2 (testing.hooks._default.1) -hooks2 -> echo post (testing.hooks._post) -post -> bsm ~.test (testing.relative._default) -> echo test (testing.relative.test) -test -> echo "pre test" (testing.functions._pre._default) -"pre test" -> bsm ~.* (testing.functions._default) -> echo "pre test" (testing.functions._pre._default) -"pre test" -> Executing JavaScript function (testing.functions.return) -wow cool function bro -> echo evil (testing.functions.return) -evil -> Executing JavaScript function (testing.functions.empty) -wow cool function bro -> Executing JavaScript function (testing.env._default) -true -123 diff --git a/test/bin.ts b/test/bin.ts index caa44bd..31f5615 100644 --- a/test/bin.ts +++ b/test/bin.ts @@ -1,37 +1,67 @@ -import { test, exec } from "uvu"; +import { test } from "uvu"; import * as assert from "uvu/assert"; import child_process from "node:child_process"; import fs from "fs"; -test("bsm testing.*", async () => { - let text = ""; +const commands = [ + "testing.default", + // "testing.os", //Skip on CI + "testing.args -- WOWOWOW", + "testing.array", + "testing.hooks", + "testing.relative", + "testing.error.onError", + "testing.error.catch", + "testing.error.finally", + "testing.error.all", + "testing.functions", + "testing.env", + "testing.env.overrides", + "testing.env.file", +]; - const code = await new Promise((resolve, reject) => { - const s = child_process.spawn("node ./dist/index testing.*", [], { - shell: true, - cwd: process.cwd(), - }); +for (const command of commands) { + test(`bsm ${command}`, async () => { + let text = ""; - s.stdout.setEncoding("utf8"); - s.stdout.on("data", function (data) { - text += data; - }); + const code = await new Promise((resolve) => { + const s = child_process.spawn( + `node ./dist/index --config ./test ${command}`, + [], + { + shell: true, + cwd: process.cwd(), + }, + ); - s.stderr.setEncoding("utf8"); - s.stderr.on("data", function (data) { - text += data; - }); + s.stdout.setEncoding("utf8"); + s.stdout.on("data", function (data) { + text += data; + }); - s.on("close", (code: number) => { - resolve(code); + s.stderr.setEncoding("utf8"); + s.stderr.on("data", function (data) { + text += data; + }); + + s.on("close", resolve); }); - }); - assert.is(code, 0); + const snapshot = `exitcode: ${code}\n\n${text}`; - // fs.writeFileSync("./test/bin.snapshot", text, "utf8"); + if (!fs.existsSync(`./test/snapshots/${command}.snapshot`)) { + fs.writeFileSync( + `./test/snapshots/${command}.snapshot`, + snapshot, + "utf8", + ); + } - assert.is(text, fs.readFileSync("./test/bin.snapshot", "utf8")); -}); + assert.snapshot( + snapshot, + fs.readFileSync(`./test/snapshots/${command}.snapshot`, "utf8"), + ); + }); +} test.run(); diff --git a/test/snapshots/testing.args -- WOWOWOW.snapshot b/test/snapshots/testing.args -- WOWOWOW.snapshot new file mode 100644 index 0000000..a1bebef --- /dev/null +++ b/test/snapshots/testing.args -- WOWOWOW.snapshot @@ -0,0 +1,11 @@ +exitcode: 0 + +> echo pre args (testing.args._pre) +pre args +> bsm testing.args.* -- WOWOWOW (testing.args._default) +> echo pre args (testing.args._pre) +pre args +> echo WOWOWOW (testing.args.echo) +WOWOWOW +> echo WOWOWOW (testing.args.echo2) +WOWOWOW diff --git a/test/snapshots/testing.array.snapshot b/test/snapshots/testing.array.snapshot new file mode 100644 index 0000000..e43517b --- /dev/null +++ b/test/snapshots/testing.array.snapshot @@ -0,0 +1,8 @@ +exitcode: 0 + +> echo 1 (testing.array.0) +1 +> echo 2 (testing.array.1) +2 +> echo 3 (testing.array.2) +3 diff --git a/test/snapshots/testing.default.snapshot b/test/snapshots/testing.default.snapshot new file mode 100644 index 0000000..bbe0876 --- /dev/null +++ b/test/snapshots/testing.default.snapshot @@ -0,0 +1,4 @@ +exitcode: 0 + +> echo default (testing.default._default) +default diff --git a/test/snapshots/testing.env.file.snapshot b/test/snapshots/testing.env.file.snapshot new file mode 100644 index 0000000..096ef09 --- /dev/null +++ b/test/snapshots/testing.env.file.snapshot @@ -0,0 +1,9 @@ +exitcode: 0 + +> Executing JavaScript function (testing.env.file._default) +false +'test" +first\nsecond\nthird +first line\nsecond line\nthird line +first line\\\\tsecond line +third line diff --git a/test/snapshots/testing.env.overrides.snapshot b/test/snapshots/testing.env.overrides.snapshot new file mode 100644 index 0000000..c8d6b7f --- /dev/null +++ b/test/snapshots/testing.env.overrides.snapshot @@ -0,0 +1,5 @@ +exitcode: 0 + +> Executing JavaScript function (testing.env.overrides._default) +false +undefined diff --git a/test/snapshots/testing.env.snapshot b/test/snapshots/testing.env.snapshot new file mode 100644 index 0000000..163c4dd --- /dev/null +++ b/test/snapshots/testing.env.snapshot @@ -0,0 +1,5 @@ +exitcode: 0 + +> Executing JavaScript function (testing.env._default) +true +123 diff --git a/test/snapshots/testing.error.all.snapshot b/test/snapshots/testing.error.all.snapshot new file mode 100644 index 0000000..44ae669 --- /dev/null +++ b/test/snapshots/testing.error.all.snapshot @@ -0,0 +1,11 @@ +exitcode: 0 + +> exit 4 (testing.error.all._default) +> echo onError (testing.error.all._onError) +onError +> exit 3 (testing.error.all._catch) +> echo finally (testing.error.all._finally) +finally +> Executing JavaScript function (testing.error._catch) +> echo 3 (testing.error._catch) +3 diff --git a/test/snapshots/testing.error.catch.snapshot b/test/snapshots/testing.error.catch.snapshot new file mode 100644 index 0000000..35e4f56 --- /dev/null +++ b/test/snapshots/testing.error.catch.snapshot @@ -0,0 +1,5 @@ +exitcode: 0 + +> exit 4 (testing.error.catch._default) +> echo catch (testing.error.catch._catch) +catch diff --git a/test/snapshots/testing.error.finally.snapshot b/test/snapshots/testing.error.finally.snapshot new file mode 100644 index 0000000..bc26f0f --- /dev/null +++ b/test/snapshots/testing.error.finally.snapshot @@ -0,0 +1,8 @@ +exitcode: 0 + +> exit 4 (testing.error.finally._default) +> echo finally (testing.error.finally._finally) +finally +> Executing JavaScript function (testing.error._catch) +> echo 4 (testing.error._catch) +4 diff --git a/test/snapshots/testing.error.onError.snapshot b/test/snapshots/testing.error.onError.snapshot new file mode 100644 index 0000000..fca1bfe --- /dev/null +++ b/test/snapshots/testing.error.onError.snapshot @@ -0,0 +1,8 @@ +exitcode: 0 + +> exit 4 (testing.error.onError._default) +> echo onError (testing.error.onError._onError) +onError +> Executing JavaScript function (testing.error._catch) +> echo 4 (testing.error._catch) +4 diff --git a/test/snapshots/testing.functions.snapshot b/test/snapshots/testing.functions.snapshot new file mode 100644 index 0000000..cc04b0c --- /dev/null +++ b/test/snapshots/testing.functions.snapshot @@ -0,0 +1,13 @@ +exitcode: 0 + +> echo pre test (testing.functions._pre._default) +pre test +> bsm ~.* (testing.functions._default) +> echo pre test (testing.functions._pre._default) +pre test +> Executing JavaScript function (testing.functions.return) +wow cool function bro +> echo evil (testing.functions.return) +evil +> Executing JavaScript function (testing.functions.empty) +wow cool function bro diff --git a/test/snapshots/testing.hooks.snapshot b/test/snapshots/testing.hooks.snapshot new file mode 100644 index 0000000..804631a --- /dev/null +++ b/test/snapshots/testing.hooks.snapshot @@ -0,0 +1,10 @@ +exitcode: 0 + +> echo pre hooks (testing.hooks._pre) +pre hooks +> echo hooks1 (testing.hooks._default.0) +hooks1 +> echo hooks2 (testing.hooks._default.1) +hooks2 +> echo post (testing.hooks._post) +post diff --git a/test/snapshots/testing.relative.snapshot b/test/snapshots/testing.relative.snapshot new file mode 100644 index 0000000..7bdad26 --- /dev/null +++ b/test/snapshots/testing.relative.snapshot @@ -0,0 +1,5 @@ +exitcode: 0 + +> bsm ~.test (testing.relative._default) +> echo test (testing.relative.test) +test