-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathlts.test.js
More file actions
48 lines (39 loc) · 1.42 KB
/
lts.test.js
File metadata and controls
48 lines (39 loc) · 1.42 KB
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
import allNodeVersions from 'all-node-versions'
import test from 'ava'
import nodeVersionAlias from 'node-version-alias'
import semver from 'semver'
import { each } from 'test-each'
import { LATEST_BORON } from './helpers/versions.test.js'
const getLatestFromMajor = async (version) => {
const { versions } = await allNodeVersions()
const versionsA = versions.map(getNodeVersion)
const majorVersion = semver.major(version)
return versionsA.find((versionA) => semver.major(versionA) === majorVersion)
}
const getNodeVersion = ({ node }) => node
each(['lts/-99', 'lts/-0', 'lts/unknown'], ({ title }, alias) => {
test(`Validates "lts/" | ${title}`, async (t) => {
await t.throwsAsync(nodeVersionAlias(alias))
})
})
each(['lts', 'lts/*'], ({ title }, alias) => {
test(`Can target latest LTS | ${title}`, async (t) => {
const version = await nodeVersionAlias(alias)
t.is(await getLatestFromMajor(version), version)
})
})
test('Can use "lts/-number"', async (t) => {
const [ltsOne, ltsTwo] = await Promise.all([
nodeVersionAlias('lts/-1'),
nodeVersionAlias('lts/-2'),
])
t.is(await getLatestFromMajor(ltsOne), ltsOne)
t.is(await getLatestFromMajor(ltsTwo), ltsTwo)
t.true(semver.gt(ltsOne, ltsTwo))
})
each(['lts/boron', 'boron'], ({ title }, alias) => {
test(`Can use "lts" by name | ${title}`, async (t) => {
const version = await nodeVersionAlias(alias)
t.is(version, LATEST_BORON)
})
})