Skip to content

Commit 76221da

Browse files
committed
Add more tests
1 parent 0a323e8 commit 76221da

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

test/helpers/versions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export const FULL_VERSION = '6.0.0'
22
export const MAJOR_VERSION = '6'
33
export const MAJOR_FULL_VERSION = '6.17.1'
4+
export const LATEST_BORON = '6.17.1'
45
export const UNKNOWN_VERSION = '6.99.0'
56
export const UNKNOWN_ALIAS = 'unknown'
67
export const IOJS_VERSION = '4.0.0'

test/lts.js

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,45 @@
11
import allNodeVersions from 'all-node-versions'
22
import test from 'ava'
3-
import { major as getMajor } from 'semver'
3+
import { major as getMajor, gt as gtVersion } from 'semver'
44
import { each } from 'test-each'
55

66
import nodeVersionAlias from '../src/main.js'
77

8+
import { LATEST_BORON } from './helpers/versions.js'
9+
10+
const getLatestFromMajor = async function (version) {
11+
const { versions } = await allNodeVersions()
12+
const majorVersion = getMajor(version)
13+
return versions.find((versionA) => getMajor(versionA) === majorVersion)
14+
}
15+
816
each(['lts', 'lts/*', 'lts/-0'], ({ title }, alias) => {
917
test(`Can target latest LTS | ${title}`, async (t) => {
10-
const [version, { majors }] = await Promise.all([
11-
nodeVersionAlias(alias),
12-
allNodeVersions(),
13-
])
14-
const majorVersion = getMajor(version)
15-
// eslint-disable-next-line max-nested-callbacks
16-
const latestLts = majors.find(({ major }) => major === majorVersion).latest
18+
const version = await nodeVersionAlias(alias)
19+
const latestLts = await getLatestFromMajor(version)
1720
t.is(version, latestLts)
1821
})
1922
})
2023

24+
test('Can use "lts/-number"', async (t) => {
25+
const [ltsOne, ltsTwo] = await Promise.all([
26+
nodeVersionAlias('lts/-1'),
27+
nodeVersionAlias('lts/-2'),
28+
])
29+
30+
const latestLtsOne = await getLatestFromMajor(ltsOne)
31+
t.is(ltsOne, latestLtsOne)
32+
const latestLtsTwo = await getLatestFromMajor(ltsTwo)
33+
t.is(ltsTwo, latestLtsTwo)
34+
35+
t.true(gtVersion(ltsOne, ltsTwo))
36+
})
37+
38+
test('Can use "lts/name"', async (t) => {
39+
const version = await nodeVersionAlias('lts/boron')
40+
t.is(version, LATEST_BORON)
41+
})
42+
2143
// This test requires non-implemented features:
2244
// - per-mirror `index.js` caching
2345
// - v8 canary mirror support

0 commit comments

Comments
 (0)