Skip to content

Commit 22663cb

Browse files
committed
feat: handle edge cases
1 parent 21dc1aa commit 22663cb

File tree

7 files changed

+119
-3
lines changed

7 files changed

+119
-3
lines changed

lib/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,20 @@ internals.detectFromTravisYaml = (travisYaml) => {
2323

2424
const matches = env.match(/(?:NODEJS_VER|TRAVIS_NODE_VERSION|NODE_VER)="?(node\/)?(?<version>[\w./*]+)"?/); /* hack syntax highlighter 🤦‍♂️ */
2525

26-
raw.add(matches.groups.version);
26+
if (matches) {
27+
raw.add(matches.groups.version);
28+
}
2729
}
2830
}
2931

3032
if (travisYaml.matrix && travisYaml.matrix.include) {
3133

32-
for (const include of travisYaml.matrix.include) {
34+
const includes = Array.isArray(travisYaml.matrix.include) ? travisYaml.matrix.include : [travisYaml.matrix.include];
35+
for (const include of includes) {
3336

34-
raw.add(include.node_js);
37+
if (include.node_js) {
38+
raw.add(include.node_js);
39+
}
3540
}
3641
}
3742

test/fixtures/caolan-async.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Source: https://github.com/caolan/async/blob/f9ad468f7b464f5ef88116def2399a5c6e59e21d/.travis.yml
2+
3+
sudo: false
4+
dist: xenial
5+
language: node_js
6+
node_js:
7+
- "8"
8+
- "10"
9+
- "12"
10+
11+
services:
12+
- xvfb
13+
14+
matrix:
15+
include:
16+
- node_js: "10"
17+
addons:
18+
firefox: "60.0"
19+
env: BROWSER=true MAKE_TEST=true
20+
env:
21+
matrix: BROWSER=false MAKE_TEST=false
22+
23+
after_success: npm run coveralls
24+
25+
26+
# Needed to run Karma with Firefox on Travis
27+
# http://karma-runner.github.io/0.13/plus/travis.html
28+
before_script:
29+
- sudo apt-get install -y make
30+
- make --version
31+
32+
script:
33+
- "[ $BROWSER == true ] || npm test"
34+
# ensure buildable
35+
- "[ $MAKE_TEST == false ] || make -j 4"
36+
# test in firefox
37+
- "[ $BROWSER == false ] || npm run mocha-browser-test"

test/fixtures/nodejs-nan.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Source: https://github.com/nodejs/nan/blob/60e86a9d4c4536fbbd2a76814470edd66b23114e/.travis.yml
2+
13
os:
24
- linux
35
- osx

test/fixtures/nodejs-readable-stream.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Source: https://github.com/nodejs/readable-stream/blob/ed213f0dfdc0da6ed94f1aefc54808cc1f74da7c/.travis.yml
2+
13
language: node_js
24
notifications:
35
email: false
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Source: https://github.com/postcss/autoprefixer/blob/0ee84d70f3f474e6f408c3078fe61db65a26ee0a/.travis.yml
2+
3+
language: node_js
4+
cache: yarn
5+
node_js:
6+
- node
7+
- "10"
8+
- "12"
9+
- "8"
10+
install:
11+
- yarn install --ignore-engines
12+
matrix:
13+
include:
14+
node_js: "6"
15+
script: yarn run jest

test/fixtures/shinn-is-resolvable.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Source: https://github.com/shinnn/is-resolvable/blob/ad414e366d58ab47ae44099415fffac5d14b627a/.travis.yml#L1
2+
3+
if: branch !~ ^v\d
4+
language: node_js
5+
node_js: node
6+
matrix:
7+
include:
8+
- after_script: node_modules/.bin/nyc report | npx coveralls
9+
- os: windows
10+
script: node test.js

test/index.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,21 @@ describe('node-support', () => {
152152
});
153153
});
154154

155+
it('handles non-matching matrix env vars', async () => {
156+
157+
const path = internals.prepareFixture('caolan-async.yml');
158+
159+
const result = await NodeSupport.detect({ path });
160+
161+
expect(result).to.equal({
162+
name: 'test-module',
163+
version: '0.0.0-development',
164+
travis: {
165+
raw: ['8', '10', '12']
166+
}
167+
});
168+
});
169+
155170
it('returns node versions from matrix include', async () => {
156171

157172
const path = internals.prepareFixture('nodejs-readable-stream.yml');
@@ -167,6 +182,36 @@ describe('node-support', () => {
167182
});
168183
});
169184

185+
it('handles single matrix include', async () => {
186+
187+
const path = internals.prepareFixture('postcss-autoprefixer.yml');
188+
189+
const result = await NodeSupport.detect({ path });
190+
191+
expect(result).to.equal({
192+
name: 'test-module',
193+
version: '0.0.0-development',
194+
travis: {
195+
raw: ['node', '10', '12', '8', '6']
196+
}
197+
});
198+
});
199+
200+
it('handles matrix includes without node versions', async () => {
201+
202+
const path = internals.prepareFixture('shinn-is-resolvable.yml');
203+
204+
const result = await NodeSupport.detect({ path });
205+
206+
expect(result).to.equal({
207+
name: 'test-module',
208+
version: '0.0.0-development',
209+
travis: {
210+
raw: ['node']
211+
}
212+
});
213+
});
214+
170215
it('handles missing env.matrix', async () => {
171216

172217
const path = internals.prepareFixture('_no-env-matrix.yml');

0 commit comments

Comments
 (0)