Skip to content

Commit da23262

Browse files
authored
👷 add CI (#63)
1 parent 4387398 commit da23262

File tree

4 files changed

+261
-38
lines changed

4 files changed

+261
-38
lines changed

‎.github/workflows/ci.yml‎

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

‎.travis.yml‎

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

‎package.json‎

Lines changed: 5 additions & 5 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",
26-
"mocha": "2.5.3",
25+
"mocha": "^11.7.1",
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=lcovonly --reporter=text npm test",
41+
"test-cov": "nyc --reporter=html --reporter=text npm test"
4242
}
4343
}

‎test/test.js‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var assert = require('assert')
33
var http = require('http')
44
var request = require('supertest')
55
var timeout = require('..')
6+
var isFinished = require('on-finished').isFinished
67

78
describe('timeout()', function () {
89
it('should have a default timeout', function (done) {
@@ -43,7 +44,10 @@ describe('timeout()', function () {
4344
it('should respond with 503 Request timeout', function (done) {
4445
var server = createServer(null, null, function (req, res) {
4546
assert.ok(req.timedout)
46-
res.end('Hello')
47+
if (!isFinished(res)) {
48+
// check response is writable for node 14
49+
res.end('Hello')
50+
}
4751
})
4852

4953
request(server)
@@ -54,7 +58,10 @@ 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+
if (!isFinished(res)) {
62+
// check response is writable for node 14
63+
res.end('Hello')
64+
}
5865
})
5966

6067
request(server)
@@ -170,7 +177,10 @@ describe('timeout()', function () {
170177
function (req, res) {
171178
assert.ok(aborted)
172179
assert.ok(!req.timedout)
173-
done()
180+
181+
server.close(function () {
182+
done()
183+
})
174184
})
175185
var test = request(server).post('/')
176186
test.write('0')

0 commit comments

Comments
 (0)