Skip to content

Commit fec00ef

Browse files
committed
👷 add CI
1 parent e9cf316 commit fec00ef

File tree

4 files changed

+244
-36
lines changed

4 files changed

+244
-36
lines changed

‎.github/workflows/ci.yml‎

Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
name: ci
2+
3+
on:
4+
- pull_request
5+
- push
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
test:
12+
permissions:
13+
checks: write # for coverallsapp/github-action to create new checks
14+
contents: read # for actions/checkout to fetch code
15+
runs-on: ubuntu-latest
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
name:
20+
- Node.js 0.8
21+
- Node.js 0.10
22+
- Node.js 0.12
23+
- io.js 1.x
24+
- io.js 2.x
25+
- io.js 3.x
26+
- Node.js 4.x
27+
- Node.js 5.x
28+
- Node.js 6.x
29+
- Node.js 7.x
30+
- Node.js 8.x
31+
- Node.js 9.x
32+
- Node.js 10.x
33+
- Node.js 11.x
34+
- Node.js 12.x
35+
- Node.js 13.x
36+
- Node.js 14.x
37+
- Node.js 15.x
38+
- Node.js 16.x
39+
- Node.js 17.x
40+
- Node.js 18.x
41+
- Node.js 19.x
42+
- Node.js 20.x
43+
- Node.js 21.x
44+
- Node.js 22.x
45+
46+
include:
47+
- name: Node.js 0.8
48+
node-version: "0.8"
49+
50+
npm-rm: nyc
51+
52+
- name: Node.js 0.10
53+
node-version: "0.10"
54+
55+
56+
- name: Node.js 0.12
57+
node-version: "0.12"
58+
59+
60+
- name: io.js 1.x
61+
node-version: "1.8"
62+
63+
64+
- name: io.js 2.x
65+
node-version: "2.5"
66+
67+
68+
- name: io.js 3.x
69+
node-version: "3.3"
70+
71+
72+
- name: Node.js 4.x
73+
node-version: "4.9"
74+
75+
76+
- name: Node.js 5.x
77+
node-version: "5.12"
78+
79+
80+
- name: Node.js 6.x
81+
node-version: "6.17"
82+
83+
84+
- name: Node.js 7.x
85+
node-version: "7.10"
86+
87+
88+
- name: Node.js 8.x
89+
node-version: "8.17"
90+
91+
92+
- name: Node.js 9.x
93+
node-version: "9.11"
94+
95+
96+
- name: Node.js 10.x
97+
node-version: "10.24"
98+
99+
100+
- name: Node.js 11.x
101+
node-version: "11.15"
102+
103+
104+
- name: Node.js 12.x
105+
node-version: "12.22"
106+
107+
108+
- name: Node.js 13.x
109+
node-version: "13.14"
110+
111+
112+
- name: Node.js 14.x
113+
node-version: "14.21"
114+
115+
- name: Node.js 15.x
116+
node-version: "15.14"
117+
118+
- name: Node.js 16.x
119+
node-version: "16.20"
120+
121+
- name: Node.js 17.x
122+
node-version: "17.9"
123+
124+
- name: Node.js 18.x
125+
node-version: "18.18"
126+
127+
- name: Node.js 19.x
128+
node-version: "19.9"
129+
130+
- name: Node.js 20.x
131+
node-version: "20.9"
132+
133+
- name: Node.js 21.x
134+
node-version: "21.1"
135+
136+
- name: Node.js 22.x
137+
node-version: "22.0"
138+
139+
steps:
140+
- uses: actions/checkout@v3
141+
142+
- name: Install Node.js ${{ matrix.node-version }}
143+
shell: bash -eo pipefail -l {0}
144+
run: |
145+
nvm install --default ${{ matrix.node-version }}
146+
if [[ "${{ matrix.node-version }}" == 0.* && "$(cut -d. -f2 <<< "${{ matrix.node-version }}")" -lt 10 ]]; then
147+
nvm install --alias=npm 0.10
148+
nvm use ${{ matrix.node-version }}
149+
if [[ "$(npm -v)" == 1.1.* ]]; then
150+
nvm exec npm npm install -g [email protected]
151+
ln -fs "$(which npm)" "$(dirname "$(nvm which npm)")/npm"
152+
else
153+
sed -i '1s;^.*$;'"$(printf '#!%q' "$(nvm which npm)")"';' "$(readlink -f "$(which npm)")"
154+
fi
155+
npm config set strict-ssl false
156+
fi
157+
dirname "$(nvm which ${{ matrix.node-version }})" >> "$GITHUB_PATH"
158+
159+
- name: Configure npm
160+
run: |
161+
if [[ "$(npm config get package-lock)" == "true" ]]; then
162+
npm config set package-lock false
163+
else
164+
npm config set shrinkwrap false
165+
fi
166+
167+
- name: Remove npm module(s) ${{ matrix.npm-rm }}
168+
run: npm rm --silent --save-dev ${{ matrix.npm-rm }}
169+
if: matrix.npm-rm != ''
170+
171+
- name: Install npm module(s) ${{ matrix.npm-i }}
172+
run: npm install --save-dev ${{ matrix.npm-i }}
173+
if: matrix.npm-i != ''
174+
175+
- name: Setup Node.js version-specific dependencies
176+
shell: bash
177+
run: |
178+
# eslint for linting
179+
# - remove on Node.js < 12
180+
if [[ "$(cut -d. -f1 <<< "${{ matrix.node-version }}")" -lt 12 ]]; then
181+
node -pe 'Object.keys(require("./package").devDependencies).join("\n")' | \
182+
grep -E '^eslint(-|$)' | \
183+
sort -r | \
184+
xargs -n1 npm rm --silent --save-dev
185+
fi
186+
187+
- name: Install Node.js dependencies
188+
run: npm install
189+
190+
- name: List environment
191+
id: list_env
192+
shell: bash
193+
run: |
194+
echo "node@$(node -v)"
195+
echo "npm@$(npm -v)"
196+
npm -s ls ||:
197+
(npm -s ls --depth=0 ||:) | awk -F'[ @]' 'NR>1 && $2 { print $2 "=" $3 }' >> "$GITHUB_OUTPUT"
198+
199+
- name: Run tests
200+
shell: bash
201+
run: |
202+
if npm -ps ls nyc | grep -q nyc; then
203+
npm run test-ci
204+
else
205+
npm test
206+
fi
207+
208+
- name: Lint code
209+
if: steps.list_env.outputs.eslint != ''
210+
run: npm run lint
211+
212+
- name: Collect code coverage
213+
uses: coverallsapp/github-action@master
214+
if: steps.list_env.outputs.nyc != ''
215+
with:
216+
github-token: ${{ secrets.GITHUB_TOKEN }}
217+
flag-name: run-${{ matrix.test_number }}
218+
parallel: true
219+
220+
coverage:
221+
permissions:
222+
checks: write # for coverallsapp/github-action to create new checks
223+
needs: test
224+
runs-on: ubuntu-latest
225+
steps:
226+
- name: Upload code coverage
227+
uses: coverallsapp/github-action@master
228+
with:
229+
github-token: ${{ secrets.GITHUB_TOKEN }}
230+
parallel-finished: true

‎.travis.yml‎

Lines changed: 0 additions & 30 deletions
This file was deleted.

‎package.json‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
"eslint-plugin-node": "4.2.2",
2323
"eslint-plugin-promise": "3.5.0",
2424
"eslint-plugin-standard": "3.0.1",
25-
"istanbul": "0.4.5",
2625
"mocha": "2.5.3",
26+
"nyc": "15.1.0",
2727
"supertest": "1.1.0"
2828
},
2929
"files": [
@@ -36,8 +36,8 @@
3636
},
3737
"scripts": {
3838
"lint": "eslint --plugin markdown --ext js,md .",
39-
"test": "mocha --reporter spec --bail --check-leaks test/",
40-
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
41-
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter dot --check-leaks test/"
39+
"test": "mocha --reporter spec --check-leaks test/",
40+
"test-ci": "nyc --reporter=lcov --reporter=text npm test",
41+
"test-cov": "nyc --reporter=html --reporter=text npm test"
4242
}
4343
}

‎test/test.js‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ describe('timeout()', function () {
4343
it('should respond with 503 Request timeout', function (done) {
4444
var server = createServer(null, null, function (req, res) {
4545
assert.ok(req.timedout)
46-
res.end('Hello')
46+
try {
47+
res.end('Hello')
48+
} catch (error) {
49+
// ignore, node 14 will fail with Uncaught Error [ERR_STREAM_WRITE_AFTER_END]: write after end
50+
}
4751
})
4852

4953
request(server)
@@ -54,7 +58,11 @@ describe('timeout()', function () {
5458
it('should pass the error to next()', function (done) {
5559
var server = createServer(null, null, function (req, res) {
5660
assert.ok(req.timedout)
57-
res.end('Hello')
61+
try {
62+
res.end('Hello')
63+
} catch (error) {
64+
// ignore, node 14 will fail with Uncaught Error [ERR_STREAM_WRITE_AFTER_END]: write after end
65+
}
5866
})
5967

6068
request(server)

0 commit comments

Comments
 (0)