我在
package.json
中有以下测试命令:
"test": "node --test --enable-source-maps --loader ts-node/esm lib/**/*.test.ts && node --test index.test.js"
它在本地运行,但在 CI 上失败:
yarn run v1.22.21
$ node --test --enable-source-maps --loader ts-node/esm lib/**/*.test.ts && node --test index.test.js
Could not find '/home/runner/work/assert-raisins/assert-raisins/lib/**/*.test.ts'
看起来
**
没有被扩展。我尝试在任何地方插入 shopt -s globstar
,但无济于事。
完整工作流程 YAML:
name: Node.js CI
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
with:
cache: 'npm'
- run: yarn
- name: Run tests
run: yarn test
sh
中的 PATH
。在某些系统(如 macOS)上,这个“sh”实际上只是伪装的 bash
,但在 Github Action Runner 中似乎并非如此。与
sh
不同,
bash
不支持 globstar,因此您需要更改 NPM 要使用的 shell。这可以通过将
.npmrc
文件添加到您的项目,并将
script-shell
选项设置为
bash
来完成。