Switch to more resilient testing (#343)

This commit is contained in:
Seth Vargo 2023-11-15 22:27:04 -05:00 committed by GitHub
parent 04900d1e97
commit 292d120a9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 7 deletions

19
bin/runTests.sh Normal file
View File

@ -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
package-lock.json generated
View File

@ -11,7 +11,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",
@ -130,11 +130,11 @@
}
},
"node_modules/@google-github-actions/actions-utils": {
"version": "0.4.9",
"resolved": "https://registry.npmjs.org/@google-github-actions/actions-utils/-/actions-utils-0.4.9.tgz",
"integrity": "sha512-DRZp7LnPDzCzZ2m//hOO2LB2Kv72Ljzq/33CT+DWSNucTgz4B579TvJyth6uVro9cF9iQ8c6ELmEDg81Oypy7w==",
"version": "0.4.10",
"resolved": "https://registry.npmjs.org/@google-github-actions/actions-utils/-/actions-utils-0.4.10.tgz",
"integrity": "sha512-bvMdDmsjIggEZYFwX5jmZCQVlzkW+hYk9U4+M79PJjnD8lfl4/imCUTRmfSyqZcEdIas8bvmQb2+ObBUYKXAtw==",
"dependencies": {
"yaml": "^2.3.3"
"yaml": "^2.3.4"
}
},
"node_modules/@humanwhocodes/config-array": {

View File

@ -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",
@ -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",