Skip to content

Commit 292d120

Browse files
authored
Switch to more resilient testing (#343)
1 parent 04900d1 commit 292d120

3 files changed

Lines changed: 26 additions & 7 deletions

File tree

bin/runTests.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
set -eEuo pipefail
3+
4+
#
5+
# As of Node 20, the --test parameter does not support globbing, and it does not
6+
# support variable Windows paths. We also cannot invoke the test runner
7+
# directly, because while it has an API, there's no way to force it to transpile
8+
# the Typescript into JavaScript before passing it to the runner.
9+
#
10+
# So we're left with this solution, which shells out to Node to list all files
11+
# that end in *.test.ts (excluding node_modules/), and then execs out to that
12+
# process. We have to exec so the stderr/stdout and exit code is appropriately
13+
# fed to the caller.
14+
#
15+
16+
FILES="$(node -e "process.stdout.write(require('node:fs').readdirSync('./', { recursive: true }).filter((e) => {return e.endsWith('.test.ts') && !e.startsWith('node_modules');}).sort().join(' '));")"
17+
18+
set -x
19+
exec node --require ts-node/register --test-reporter spec --test ${FILES}

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"build": "ncc build -m src/main.ts -o dist/main && ncc build -m src/post.ts -o dist/post",
88
"lint": "eslint . --ext .ts,.tsx",
99
"format": "prettier --write **/*.ts",
10-
"test": " node --require ts-node/register --test **/*.test.ts **/**/*.test.ts"
10+
"test": "bash ./bin/runTests.sh"
1111
},
1212
"repository": {
1313
"type": "git",
@@ -25,7 +25,7 @@
2525
"dependencies": {
2626
"@actions/core": "^1.10.1",
2727
"@actions/http-client": "^2.2.0",
28-
"@google-github-actions/actions-utils": "^0.4.9"
28+
"@google-github-actions/actions-utils": "^0.4.10"
2929
},
3030
"devDependencies": {
3131
"@types/node": "^20.9.0",

0 commit comments

Comments
 (0)