forked from expressjs/body-parser
-
Notifications
You must be signed in to change notification settings - Fork 2
/
.travis.yml
116 lines (116 loc) · 3.24 KB
/
.travis.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
language: node_js
node_js:
- "0.8"
- "0.10"
- "0.12"
- "1.8"
- "2.5"
- "3.3"
- "4.9"
- "5.12"
- "6.17"
- "7.10"
- "8.17"
- "9.11"
- "10.19"
- "11.15"
- "12.16"
- "13.11"
cache:
directories:
- node_modules
before_install:
- |
# Setup utility functions
function node_version_lt () {
[[ "$(v "$TRAVIS_NODE_VERSION")" -lt "$(v "${1}")" ]]
}
function npm_module_installed () {
npm -lsp ls | grep -Fq "$(pwd)/node_modules/${1}:${1}@"
}
function npm_remove_module_re () {
node -e '
fs = require("fs");
p = JSON.parse(fs.readFileSync("package.json", "utf8"));
r = RegExp(process.argv[1]);
for (k in p.devDependencies) {
if (r.test(k)) delete p.devDependencies[k];
}
fs.writeFileSync("package.json", JSON.stringify(p, null, 2) + "\n");
' "$@"
}
function npm_use_module () {
node -e '
fs = require("fs");
p = JSON.parse(fs.readFileSync("package.json", "utf8"));
p.devDependencies[process.argv[1]] = process.argv[2];
fs.writeFileSync("package.json", JSON.stringify(p, null, 2) + "\n");
' "$@"
}
function v () {
tr '.' '\n' <<< "${1}" \
| awk '{ printf "%03d", $0 }' \
| sed 's/^0*//'
}
# Configure npm
- |
# Skip updating shrinkwrap / lock
npm config set shrinkwrap false
# Remove all non-test dependencies
- |
# Remove benchmark dependencies
npm_remove_module_re '(^|-)benchmark$'
npm_remove_module_re '^fast-url-parser$'
# Setup Node.js version-specific dependencies
- |
# Configure eslint for linting
if node_version_lt '8.0'; then npm_remove_module_re '^eslint(-|$)'
fi
- |
# Configure mocha for testing
if node_version_lt '0.10'; then npm_use_module 'mocha' '2.5.3'
elif node_version_lt '4.0' ; then npm_use_module 'mocha' '3.5.3'
elif node_version_lt '6.0' ; then npm_use_module 'mocha' '5.2.0'
elif node_version_lt '8.0' ; then npm_use_module 'mocha' '6.2.2'
fi
- |
# Configure nyc for coverage
if node_version_lt '0.10'; then npm_remove_module_re '^nyc$'
elif node_version_lt '4.0' ; then npm_use_module 'nyc' '10.3.2'
elif node_version_lt '6.0' ; then npm_use_module 'nyc' '11.9.0'
elif node_version_lt '8.0' ; then npm_use_module 'nyc' '14.1.1'
fi
- |
# Configure supertest for http calls
if node_version_lt '0.10'; then npm_use_module 'supertest' '1.1.0'
elif node_version_lt '4.0' ; then npm_use_module 'supertest' '2.0.0'
elif node_version_lt '6.0' ; then npm_use_module 'supertest' '3.4.2'
fi
# Update Node.js modules
- |
# Prune & rebuild node_modules
if [[ -d node_modules ]]; then
npm prune
npm rebuild
fi
before_scrpt:
- |
# Contents of node_modules
npm -s ls ||:
script:
- |
# Run test script, depending on nyc install
if npm_module_installed 'nyc'; then npm run-script test-travis
else npm test
fi
- |
# Run linting, if eslint exists
if npm_module_installed 'eslint'; then npm run-script lint
fi
after_script:
- |
# Upload coverage to coveralls
if [[ -d .nyc_output ]]; then
npm install --save-dev coveralls@2
nyc report --reporter=text-lcov | coveralls
fi