Skip to content

Commit

Permalink
chore: split snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
UnderKoen committed Jan 17, 2024
1 parent 3757353 commit 8c4dff7
Show file tree
Hide file tree
Showing 16 changed files with 158 additions and 70 deletions.
6 changes: 3 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ~.*",
Expand All @@ -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: {
Expand Down
44 changes: 0 additions & 44 deletions test/bin.snapshot

This file was deleted.

76 changes: 53 additions & 23 deletions test/bin.ts
Original file line number Diff line number Diff line change
@@ -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<number>((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<number>((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();
11 changes: 11 additions & 0 deletions test/snapshots/testing.args -- WOWOWOW.snapshot
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions test/snapshots/testing.array.snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
exitcode: 0

> echo 1 (testing.array.0)
1
> echo 2 (testing.array.1)
2
> echo 3 (testing.array.2)
3
4 changes: 4 additions & 0 deletions test/snapshots/testing.default.snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
exitcode: 0

> echo default (testing.default._default)
default
9 changes: 9 additions & 0 deletions test/snapshots/testing.env.file.snapshot
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions test/snapshots/testing.env.overrides.snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
exitcode: 0

> Executing JavaScript function (testing.env.overrides._default)
false
undefined
5 changes: 5 additions & 0 deletions test/snapshots/testing.env.snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
exitcode: 0

> Executing JavaScript function (testing.env._default)
true
123
11 changes: 11 additions & 0 deletions test/snapshots/testing.error.all.snapshot
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions test/snapshots/testing.error.catch.snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
exitcode: 0

> exit 4 (testing.error.catch._default)
> echo catch (testing.error.catch._catch)
catch
8 changes: 8 additions & 0 deletions test/snapshots/testing.error.finally.snapshot
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions test/snapshots/testing.error.onError.snapshot
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions test/snapshots/testing.functions.snapshot
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions test/snapshots/testing.hooks.snapshot
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions test/snapshots/testing.relative.snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
exitcode: 0

> bsm ~.test (testing.relative._default)
> echo test (testing.relative.test)
test

0 comments on commit 8c4dff7

Please sign in to comment.