Skip to content

Commit e2afea0

Browse files
committed
👷 add CI
1 parent e9cf316 commit e2afea0

File tree

4 files changed

+279
-38
lines changed

4 files changed

+279
-38
lines changed

‎.github/workflows/ci.yml‎

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

7+
var servers = []
8+
79
describe('timeout()', function () {
810
it('should have a default timeout', function (done) {
911
this.timeout(10000)
@@ -43,7 +45,10 @@ describe('timeout()', function () {
4345
it('should respond with 503 Request timeout', function (done) {
4446
var server = createServer(null, null, function (req, res) {
4547
assert.ok(req.timedout)
46-
res.end('Hello')
48+
if (!(res.finished || res.writableEnded)) {
49+
// check response is writable for node 14
50+
res.end('Hello')
51+
}
4752
})
4853

4954
request(server)
@@ -54,7 +59,10 @@ describe('timeout()', function () {
5459
it('should pass the error to next()', function (done) {
5560
var server = createServer(null, null, function (req, res) {
5661
assert.ok(req.timedout)
57-
res.end('Hello')
62+
if (!(res.finished || res.writableEnded)) {
63+
// check response is writable for node 14
64+
res.end('Hello')
65+
}
5866
})
5967

6068
request(server)
@@ -188,7 +196,7 @@ function createServer (options, before, after) {
188196

189197
var _timeout = timeout(_ms, options)
190198

191-
return http.createServer(function (req, res) {
199+
var server = http.createServer(function (req, res) {
192200
_timeout(req, res, function (err) {
193201
if (err) {
194202
res.statusCode = err.status || 500
@@ -207,4 +215,26 @@ function createServer (options, before, after) {
207215
}
208216
})
209217
})
218+
219+
servers.push(server)
220+
221+
return server
210222
}
223+
224+
afterEach(function (done) {
225+
if (servers.length === 0) {
226+
return done()
227+
}
228+
229+
var closed = 0
230+
231+
for (let i = 0; i < servers.length; i++) {
232+
const s = servers[i]
233+
s.close(function () {
234+
if (closed + 1 === servers.length) {
235+
servers = []
236+
done()
237+
}
238+
})
239+
}
240+
})

0 commit comments

Comments
 (0)