Skip to content

Commit 2f4a522

Browse files
committed
👷 add CI
1 parent e9cf316 commit 2f4a522

File tree

4 files changed

+264
-38
lines changed

4 files changed

+264
-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+
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+
npm-i: mocha@9.2.2
120+
121+
- name: Node.js 15.x
122+
node-version: "15"
123+
npm-i: mocha@9.2.2
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 npm@1.1
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: 16 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)
@@ -162,6 +170,7 @@ describe('timeout()', function () {
162170
describe('when request aborted', function () {
163171
it('should clear timeout', function (done) {
164172
var aborted = false
173+
165174
var server = createServer(null,
166175
function (req, res) {
167176
req.on('aborted', function () { aborted = true })
@@ -170,8 +179,12 @@ describe('timeout()', function () {
170179
function (req, res) {
171180
assert.ok(aborted)
172181
assert.ok(!req.timedout)
173-
done()
182+
183+
server.close(function () {
184+
done()
185+
})
174186
})
187+
175188
var test = request(server).post('/')
176189
test.write('0')
177190
})

0 commit comments

Comments
 (0)