Skip to content

Commit bdfa4e3

Browse files
committed
ci: run test for windows and linux
1 parent 66a16f2 commit bdfa4e3

File tree

5 files changed

+81
-74
lines changed

5 files changed

+81
-74
lines changed

.github/workflows/ci.yml

Lines changed: 70 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,38 @@
11
name: ci
22

33
on:
4-
- pull_request
5-
- push
4+
push:
5+
branches:
6+
- main
7+
paths-ignore:
8+
- '*.md'
9+
pull_request:
10+
paths-ignore:
11+
- '*.md'
612

713
permissions:
814
contents: read
9-
1015
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
16+
lint:
17+
name: Lint
1518
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
- name: Setup Node.js
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: 'lts/*'
25+
26+
- name: Install dependencies
27+
run: npm install --ignore-scripts --include=dev
28+
29+
- name: Run lint
30+
run: npm run lint
31+
test:
1632
strategy:
1733
fail-fast: false
1834
matrix:
35+
os: [ubuntu-latest, windows-latest]
1936
name:
2037
- Node.js 10.x
2138
- Node.js 11.x
@@ -55,23 +72,23 @@ jobs:
5572
5673

5774
- name: Node.js 15.x
58-
node-version: "15.14"
75+
node-version: "15.14.0"
5976
6077

6178
- name: Node.js 16.x
62-
node-version: "16.20"
79+
node-version: "16.20.2"
6380

6481
- name: Node.js 17.x
65-
node-version: "17.9"
82+
node-version: "17.9.1"
6683

6784
- name: Node.js 18.x
68-
node-version: "18.18"
85+
node-version: "18.20.8"
6986

7087
- name: Node.js 19.x
71-
node-version: "19.9"
88+
node-version: "19.9.0"
7289

7390
- name: Node.js 20.x
74-
node-version: "20.9"
91+
node-version: "20.19.2"
7592

7693
- name: Node.js 21.x
7794
node-version: "21"
@@ -85,26 +102,16 @@ jobs:
85102
- name: Node.js 24.x
86103
node-version: "24"
87104

105+
runs-on: ${{ matrix.os }}
88106
steps:
89-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
90-
91-
- name: Install Node.js ${{ matrix.node-version }}
92-
shell: bash -eo pipefail -l {0}
93-
run: |
94-
nvm install --default ${{ matrix.node-version }}
95-
if [[ "${{ matrix.node-version }}" == 0.* && "$(cut -d. -f2 <<< "${{ matrix.node-version }}")" -lt 10 ]]; then
96-
nvm install --alias=npm 0.10
97-
nvm use ${{ matrix.node-version }}
98-
if [[ "$(npm -v)" == 1.1.* ]]; then
99-
nvm exec npm npm install -g [email protected]
100-
ln -fs "$(which npm)" "$(dirname "$(nvm which npm)")/npm"
101-
else
102-
sed -i '1s;^.*$;'"$(printf '#!%q' "$(nvm which npm)")"';' "$(readlink -f "$(which npm)")"
103-
fi
104-
npm config set strict-ssl false
105-
fi
106-
dirname "$(nvm which ${{ matrix.node-version }})" >> "$GITHUB_PATH"
107+
- uses: actions/checkout@v4
108+
with:
109+
persist-credentials: false
107110

111+
- name: Setup Node.js ${{ matrix.node-version }}
112+
uses: actions/setup-node@v4
113+
with:
114+
node-version: ${{ matrix.node-version }}
108115
- name: Remove npm module(s) ${{ matrix.npm-rm }}
109116
run: npm rm --silent --save-dev ${{ matrix.npm-rm }}
110117
if: matrix.npm-rm != ''
@@ -116,43 +123,41 @@ jobs:
116123
- name: Install Node.js dependencies
117124
run: npm install
118125

119-
- name: List environment
120-
id: list_env
121-
shell: bash
122-
run: |
123-
echo "node@$(node -v)"
124-
echo "npm@$(npm -v)"
125-
npm -s ls ||:
126-
(npm -s ls --depth=0 ||:) | awk -F'[ @]' 'NR>1 && $2 { print $2 "=" $3 }' >> "$GITHUB_OUTPUT"
127-
128-
- name: Lint code
129-
run: npm run lint
130-
131126
- name: Run tests
132127
shell: bash
133-
run: |
134-
if npm -ps ls nyc | grep -q nyc; then
135-
npm run test-ci
136-
else
137-
npm test
138-
fi
128+
run: npm run test-ci
139129

140-
- name: Collect code coverage
141-
uses: coverallsapp/github-action@09b709cf6a16e30b0808ba050c7a6e8a5ef13f8d # master
142-
if: steps.list_env.outputs.nyc != ''
130+
- name: Upload code coverage
131+
uses: actions/upload-artifact@v4
143132
with:
144-
github-token: ${{ secrets.GITHUB_TOKEN }}
145-
flag-name: run-${{ matrix.test_number }}
146-
parallel: true
133+
name: coverage-node-${{ matrix.node-version }}-${{ matrix.os }}
134+
path: ./coverage/lcov.info
135+
retention-days: 1
147136

148137
coverage:
149-
permissions:
150-
checks: write # for coverallsapp/github-action to create new checks
151-
needs: test
152-
runs-on: ubuntu-latest
153-
steps:
154-
- name: Upload code coverage
155-
uses: coverallsapp/github-action@09b709cf6a16e30b0808ba050c7a6e8a5ef13f8d # master
156-
with:
157-
github-token: ${{ secrets.GITHUB_TOKEN }}
158-
parallel-finished: true
138+
needs: test
139+
runs-on: ubuntu-latest
140+
permissions:
141+
contents: read
142+
checks: write
143+
steps:
144+
- uses: actions/checkout@v4
145+
146+
- name: Install lcov
147+
shell: bash
148+
run: sudo apt-get -y install lcov
149+
150+
- name: Collect coverage reports
151+
uses: actions/download-artifact@v4
152+
with:
153+
path: ./coverage
154+
pattern: coverage-node-*
155+
156+
- name: Merge coverage reports
157+
shell: bash
158+
run: find ./coverage -name lcov.info -exec printf '-a %q\n' {} \; | xargs lcov -o ./lcov.info
159+
160+
- name: Upload coverage report
161+
uses: coverallsapp/github-action@v2
162+
with:
163+
file: ./lcov.info

test/disk-storage.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var temp = require('fs-temp')
1010
var rimraf = require('rimraf')
1111
var FormData = require('form-data')
1212

13-
function assertFileProperties(file, name) {
13+
function assertFileProperties (file, name) {
1414
const expectedSize = util.fileSizeByName(name)
1515
assert.strictEqual(file.fieldname, path.parse(name).name)
1616
assert.strictEqual(file.originalname, name)
@@ -44,7 +44,7 @@ describe('Disk Storage', function () {
4444

4545
util.submitForm(parser, form, function (err, req) {
4646
assert.ifError(err)
47-
47+
4848
assert.strictEqual(req.body.name, 'Multer')
4949

5050
assertFileProperties(req.file, 'small0.dat')
@@ -117,7 +117,7 @@ describe('Disk Storage', function () {
117117
assertFileProperties(req.files.small1[0], 'small1.dat')
118118
assertFileProperties(req.files.medium[0], 'medium.dat')
119119
assertFileProperties(req.files.large[0], 'large.jpg')
120-
120+
121121
done()
122122
})
123123
})

test/express-integration.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ describe('Express Integration', function () {
7070

7171
it('should work when receiving error from fileFilter', function (done) {
7272
function fileFilter (req, file, cb) {
73-
cb(new Error('TEST'))
73+
if (file.mimetype !== 'image/png') {
74+
return cb(new Error('Only PNG files are allowed'))
75+
}
7476
}
7577

7678
var upload = multer({ fileFilter: fileFilter })
@@ -80,15 +82,15 @@ describe('Express Integration', function () {
8082
var routeCalled = 0
8183
var errorCalled = 0
8284

83-
form.append('avatar', util.file('large.jpg'))
85+
form.append('avatar', util.file('small0.dat'))
8486

8587
router.post('/profile', upload.single('avatar'), function (req, res, next) {
8688
routeCalled++
8789
res.status(200).end('SUCCESS')
8890
})
8991

9092
router.use(function (err, req, res, next) {
91-
assert.strictEqual(err.message, 'TEST')
93+
assert.strictEqual(err.message, 'Only PNG files are allowed')
9294

9395
errorCalled++
9496
res.status(500).end('ERROR')

test/functionality.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ describe('Functionality', function () {
128128

129129
util.submitForm(parser, form, function (err, req) {
130130
assert.ifError(err)
131-
131+
132132
assert.strictEqual(req.files.length, 2)
133133
assert.ok(req.files[0].path.indexOf(`${path.sep}testforme-`) >= 0)
134134
assert.ok(req.files[1].path.indexOf(`${path.sep}testforme-`) >= 0)

test/memory-storage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var util = require('./_util')
77
var multer = require('../')
88
var FormData = require('form-data')
99

10-
function assertFileProperties(file, name) {
10+
function assertFileProperties (file, name) {
1111
const expectedSize = util.fileSizeByName(name)
1212
assert.strictEqual(file.fieldname, path.parse(name).name)
1313
assert.strictEqual(file.originalname, name)
@@ -69,7 +69,7 @@ describe('Memory Storage', function () {
6969
assert(deepEqual(req.body.checkboxempty, ['', '']))
7070

7171
assertFileProperties(req.file, 'empty.dat')
72-
72+
7373
done()
7474
})
7575
})

0 commit comments

Comments
 (0)