用于 npm 测试的 GitHub 操作 CI 检查保持不间断运行

如何解决用于 npm 测试的 GitHub 操作 CI 检查保持不间断运行

我之前在设置 github actions 时曾与 github-workflow 合作过,但这是我第一次为 npm test 包含操作/作业。

我已将其配置为在拉取请求上运行操作以像往常一样开发分支……但测试从未在 github 操作作业中完成运行。我一直在谷歌搜索,但似乎找不到相关的解决方案。

Github 拉取请求截图 1

github-action-still-running

Github 拉取请求截图 2

github-action-still-running-jobs

我使用的是 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中了。

package.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);
}

spec/cli.spec.js

import { cli as cli } from '../src/cli';

describe('cli function',() => {

  it('should return undefined',() => {
    let test = cli();
    expect(test).toBeUndefined();
  });
});

spec/run.js

import Jasmine from 'jasmine';

const jasmine = new Jasmine();
jasmine.loadConfigFile('spec/support/jasmine.json');

jasmine.execute();

spec/support/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 存储库,但根据您在此处发布的内容,我建议的一种解决方案是:

  1. 将 dev-test 作为脚本的一部分,在 package.json 配置中运行 nodemon --exec babel-node spec/run.js
  2. 将 package.json 的测试脚本更改为 babel-node spec/run.js

这将确保在推送更改时测试只会运行一次。因此,在本地工作时,您可以使用 npm run dev-test 在本地进行更改的整个期间保持测试。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?