-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
158 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
exitcode: 0 | ||
|
||
> echo pre args [90m(testing.args._pre)[0m | ||
pre args | ||
> bsm testing.args.* -- WOWOWOW [90m(testing.args._default)[0m | ||
> echo pre args [90m(testing.args._pre)[0m | ||
pre args | ||
> echo WOWOWOW [90m(testing.args.echo)[0m | ||
WOWOWOW | ||
> echo WOWOWOW [90m(testing.args.echo2)[0m | ||
WOWOWOW |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
exitcode: 0 | ||
|
||
> echo 1 [90m(testing.array.0)[0m | ||
1 | ||
> echo 2 [90m(testing.array.1)[0m | ||
2 | ||
> echo 3 [90m(testing.array.2)[0m | ||
3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
exitcode: 0 | ||
|
||
> echo default [90m(testing.default._default)[0m | ||
default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
exitcode: 0 | ||
|
||
> [93mExecuting JavaScript function[0m [90m(testing.env.file._default)[0m | ||
false | ||
'test" | ||
first\nsecond\nthird | ||
first line\nsecond line\nthird line | ||
first line\\\\tsecond line | ||
third line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
exitcode: 0 | ||
|
||
> [93mExecuting JavaScript function[0m [90m(testing.env.overrides._default)[0m | ||
false | ||
[90mundefined[39m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
exitcode: 0 | ||
|
||
> [93mExecuting JavaScript function[0m [90m(testing.env._default)[0m | ||
true | ||
123 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
exitcode: 0 | ||
|
||
> exit 4 [90m(testing.error.all._default)[0m | ||
> echo onError [90m(testing.error.all._onError)[0m | ||
onError | ||
> exit 3 [90m(testing.error.all._catch)[0m | ||
> echo finally [90m(testing.error.all._finally)[0m | ||
finally | ||
> [93mExecuting JavaScript function[0m [90m(testing.error._catch)[0m | ||
> echo 3 [90m(testing.error._catch)[0m | ||
3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
exitcode: 0 | ||
|
||
> exit 4 [90m(testing.error.catch._default)[0m | ||
> echo catch [90m(testing.error.catch._catch)[0m | ||
catch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
exitcode: 0 | ||
|
||
> exit 4 [90m(testing.error.finally._default)[0m | ||
> echo finally [90m(testing.error.finally._finally)[0m | ||
finally | ||
> [93mExecuting JavaScript function[0m [90m(testing.error._catch)[0m | ||
> echo 4 [90m(testing.error._catch)[0m | ||
4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
exitcode: 0 | ||
|
||
> exit 4 [90m(testing.error.onError._default)[0m | ||
> echo onError [90m(testing.error.onError._onError)[0m | ||
onError | ||
> [93mExecuting JavaScript function[0m [90m(testing.error._catch)[0m | ||
> echo 4 [90m(testing.error._catch)[0m | ||
4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
exitcode: 0 | ||
|
||
> echo pre test [90m(testing.functions._pre._default)[0m | ||
pre test | ||
> bsm ~.* [90m(testing.functions._default)[0m | ||
> echo pre test [90m(testing.functions._pre._default)[0m | ||
pre test | ||
> [93mExecuting JavaScript function[0m [90m(testing.functions.return)[0m | ||
wow cool function bro | ||
> echo evil [90m(testing.functions.return)[0m | ||
evil | ||
> [93mExecuting JavaScript function[0m [90m(testing.functions.empty)[0m | ||
wow cool function bro |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
exitcode: 0 | ||
|
||
> echo pre hooks [90m(testing.hooks._pre)[0m | ||
pre hooks | ||
> echo hooks1 [90m(testing.hooks._default.0)[0m | ||
hooks1 | ||
> echo hooks2 [90m(testing.hooks._default.1)[0m | ||
hooks2 | ||
> echo post [90m(testing.hooks._post)[0m | ||
post |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
exitcode: 0 | ||
|
||
> bsm ~.test [90m(testing.relative._default)[0m | ||
> echo test [90m(testing.relative.test)[0m | ||
test |