Skip to content

Commit

Permalink
Switch to more resilient testing
Browse files Browse the repository at this point in the history
  • Loading branch information
sethvargo committed Nov 16, 2023
1 parent 04900d1 commit 4eaa7e3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
19 changes: 19 additions & 0 deletions bin/runTests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -eEuo pipefail

#
# As of Node 20, the --test parameter does not support globbing, and it does not
# support variable Windows paths. We also cannot invoke the test runner
# directly, because while it has an API, there's no way to force it to transpile
# the Typescript into JavaScript before passing it to the runner.
#
# So we're left with this solution, which shells out to Node to list all files
# that end in *.test.ts (excluding node_modules/), and then execs out to that
# process. We have to exec so the stderr/stdout and exit code is appropriately
# fed to the caller.
#

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(' '));")"

set -x
exec node --require ts-node/register --test-reporter spec --test ${FILES}
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"build": "ncc build -m src/main.ts -o dist/main && ncc build -m src/post.ts -o dist/post",
"lint": "eslint . --ext .ts,.tsx",
"format": "prettier --write **/*.ts",
"test": " node --require ts-node/register --test **/*.test.ts **/**/*.test.ts"
"test": "bash ./bin/runTests.sh"
},
"repository": {
"type": "git",
Expand All @@ -25,7 +25,7 @@
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/http-client": "^2.2.0",
"@google-github-actions/actions-utils": "^0.4.9"
"@google-github-actions/actions-utils": "^0.4.10"
},
"devDependencies": {
"@types/node": "^20.9.0",
Expand Down

0 comments on commit 4eaa7e3

Please sign in to comment.