Skip to content

Commit da1e842

Browse files
committedOct 3, 2022
ci: added ci
1 parent 8847310 commit da1e842

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed
 

Diff for: ‎.github/workflows/node.js.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3+
4+
name: Node.js CI
5+
6+
on: [push, pull_request]
7+
8+
jobs:
9+
build:
10+
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
include:
16+
- node-version: 10.x
17+
test-on-old-node: 1
18+
- node-version: 12.x
19+
test-on-old-node: 1
20+
- node-version: 14.x
21+
- node-version: 16.x
22+
- node-version: 18.x
23+
24+
steps:
25+
- uses: actions/checkout@v3
26+
- name: Use Node.js ${{ matrix.node-version }}
27+
uses: actions/setup-node@v3
28+
with:
29+
node-version: ${{ matrix.node-version }}
30+
cache: 'npm'
31+
- name: Install Dependencies On Old Node ${{ matrix.node-version }}
32+
if: ${{ matrix.test-on-old-node == '1' }}
33+
run: node ci/remove-deps-4-old-node.js && yarn install --ignore-scripts
34+
- name: Install Dependencies On Node ${{ matrix.node-version }}
35+
if: ${{ matrix.test-on-old-node != '1' }}
36+
run: yarn install
37+
- run: npm test
38+
- name: Coverage On Node ${{ matrix.node-version }}
39+
run:
40+
npm run coverage

Diff for: ‎ci/remove-deps-4-old-node.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const package = require('../package.json');
4+
5+
const UNSUPPORT_DEPS_4_OLD = {
6+
'eslint': undefined,
7+
'mocha': '6.x'
8+
};
9+
10+
const deps = Object.keys(UNSUPPORT_DEPS_4_OLD);
11+
for (const item in package.devDependencies) {
12+
if (deps.includes(item)) {
13+
package.devDependencies[item] = UNSUPPORT_DEPS_4_OLD[item];
14+
}
15+
}
16+
17+
delete package.scripts.lint;
18+
19+
fs.writeFileSync(
20+
path.join(__dirname, '../package.json'),
21+
JSON.stringify(package, null, 2)
22+
);

Diff for: ‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"scripts": {
2828
"lint": "eslint lib/**/*.js test/**/*.js index.js",
2929
"lint:fix": "eslint --fix lib/**/*.js test/**/*.js index.js",
30-
"pretest": "npm run lint",
30+
"pretest": "npm run lint --if-present",
3131
"test": "nyc --reporter=html --reporter=text mocha --exit --require should --reporter spec --check-leaks",
3232
"coverage": "nyc report --reporter=text-lcov | coveralls"
3333
},

0 commit comments

Comments
 (0)