node.js - GitHub 操作 CI 检查 npm 测试保持不间断运行
问题描述
我github actions
以前在设置时使用过github-workflow
,但这是我第一次为npm test
.
我已将其配置为根据拉取请求运行操作以像往常一样开发分支......但测试从未在 github 操作作业中完成运行。我一直在谷歌搜索,但似乎找不到相关的解决方案。
Github拉取请求截图1
Github拉取请求截图2
我正在使用nodejs
,测试是用jasmine
. 我不知道它是否与我自己设置的设置或测试配置有关,所以我还在下面包含了一些相关的代码/文件以防万一。
.github/workflows/node.js.yml
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Node.js CI
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.x, 14.x, 15.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build --if-present
- run: npm test
上面的node.js.yml
文件☝已经在develop branch
.
包.json
{
//scripts
"scripts": {
"prestart": "node -r esm src/startMessage.js",
"start": "npm-run-all --parallel lint:watch",
"lint": "esw src --color",
"lint:watch": "npm run lint -- --watch",
"test": "nodemon --exec babel-node spec/run.js"
},
//dependencies
"dependencies": {
"arg": "^5.0.0",
"chalk": "^4.1.0",
"esm": "^3.2.25",
"execa": "^5.0.0",
"inquirer": "^8.0.0",
"listr": "^0.14.3",
"ncp": "^2.0.0",
"npm-run-all": "^4.1.5",
"pkg-install": "^1.0.0"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-preset-env": "^1.7.0",
"babel-register": "^6.26.0",
"eslint": "^7.21.0",
"eslint-plugin-import": "^2.22.1",
"eslint-watch": "^7.0.0"
"eslint-watch": "^7.0.0",
"jasmine": "^3.6.4",
"nodemon": "^2.0.7"
}
}
src/cli.js
export let cli = (args) => {
console.log(args);
}
规范/cli.spec.js
import { cli as cli } from '../src/cli';
describe('cli function', () => {
it('should return undefined', () => {
let test = cli();
expect(test).toBeUndefined();
});
});
规范/run.js
import Jasmine from 'jasmine';
const jasmine = new Jasmine();
jasmine.loadConfigFile('spec/support/jasmine.json');
jasmine.execute();
规范/支持/jasmine.json
{
"spec_dir": "spec",
"spec_files": [
"**/*[sS]pec.js"
],
"helpers": [
"helpers/**/*.js"
],
"stopSpecOnExpectationFailure": false,
"random": true
}
.babelrc
{
"presets": [
"env"
]
}
当我npm test
在终端中运行时,测试在本地运行良好。我需要有关推送或拉取请求的 github 操作/工作流程的帮助(以便我可以将包含测试的功能分支合并到开发分支中):
是什么让测试在 GitHub 操作中不停地运行?
如何让 github 操作检查通过并成功运行?
解决方案
虽然我没有机会查看您的 GitHub 存储库,但根据您在此处发布的内容,我建议的一种解决方案是:
- 将 dev-test 作为脚本的一部分,将
nodemon --exec babel-node spec/run.js
在 package.json 配置中运行 - 将 package.json 的测试脚本更改为
babel-node spec/run.js
.
这将确保在推送更改时仅运行一次测试。因此,在本地工作时,您可以使用在npm run dev-test
本地进行更改的整个期间保持测试。
推荐阅读
- python-3.x - 训练 GAN 时出现 InvalidArgumentError
- node.js - JSON中的意外令牌o - 节点/ API
- html - 创建具有 6 个角度而不是 4 个角度的自定义 HTML div
- python - 如何有效地为多个矩阵中的每个元素分别找到 N 个最大值?
- java - Minecraft Forge - 显式调用构造函数时无法引用实例字段
- php - PHP 根据数据库中的数据填充表头
- ansible - ansible 在不包含某个子文件夹的路径中查找文件夹失败
- intellij-idea - IntelliJ - 如何禁用“@NotNull”注释的生成?
- apache-kafka - 卡夫卡消息是日志的一部分吗?
- html - 具有嵌套悬停动画的等距形状的无限 360 度 3d 旋转