Repository navigation
Expand file tree
/
Copy pathtest.js
More file actions
125 lines (118 loc) · 4.71 KB
/
Copy pathtest.js
File metadata and controls
125 lines (118 loc) · 4.71 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
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
117
118
119
120
121
122
123
124
125
'use strict'
const { execFileSync } = require('child_process')
const fs = require('fs')
const path = require('path')
const tap = require('tap')
const { Linker } = require('./common.js')
tap.test('Linker', async t => {
const linker = new Linker({ baseDir: 'base', docsDir: 'docs' })
const links = await linker.getLinks(
['v19.8.0/', 'v19.8.1/', 'v19.9.0/', 'v20.7.0/', 'v20.8.0/'],
async () => ['docs/', 'win-x64/', 'node-v20.8.0-aix-ppc64.tar.gz', 'node-v20.8.0-arm64.msi', 'node-v20.8.0-headers.tar.gz', 'node-v20.8.0.tar.gz']
)
t.same(links, new Map([
['base/latest-v19.x', 'base/v19.9.0'],
['docs/latest-v19.x', 'base/v19.9.0/docs'],
['base/latest-v20.x', 'base/v20.8.0'],
['docs/latest-v20.x', 'base/v20.8.0/docs'],
['base/latest-iron', 'base/v20.8.0'],
['docs/latest-iron', 'base/v20.8.0/docs'],
['docs/v19.8.0', 'base/v19.8.0/docs'],
['docs/v19.8.1', 'base/v19.8.1/docs'],
['docs/v19.9.0', 'base/v19.9.0/docs'],
['docs/v20.7.0', 'base/v20.7.0/docs'],
['docs/v20.8.0', 'base/v20.8.0/docs'],
['base/latest', 'base/v20.8.0'],
['docs/latest', 'base/v20.8.0/docs'],
['base/node-latest.tar.gz', 'base/latest/node-v20.8.0.tar.gz']
]))
t.end()
})
tap.test('basic test', t => {
const dir = t.testdir({
'v4.0.0': {
'node-v4.0.0.tar.gz': ''
},
'v4.1.0': {
'node-v4.1.0.tar.gz': ''
}
})
const targetDir = path.join(dir, 'v4.1.0')
const links = [
['latest', targetDir],
['latest-argon', targetDir],
['latest-v4.x', targetDir],
['node-latest.tar.gz', path.join(dir, 'latest', 'node-v4.1.0.tar.gz')]
]
execFileSync(process.execPath, ['latest-linker.js', dir])
for (const [link, target] of links) {
const src = path.join(dir, link)
t.ok(fs.existsSync(src), `${link} was created`)
const stats = fs.lstatSync(src)
t.ok(stats.isSymbolicLink(), `${link} is a symbolic link`)
t.same(fs.readlinkSync(src), target, `${link} points to ${target}`)
}
t.end()
})
tap.test('latest does not link to alphas', async t => {
const linker = new Linker({ baseDir: 'base', docsDir: 'docs' })
const fakeReaddir = async (v) => {
const version = path.basename(v)
// Mimimum expected content are the `docs` directory, and
// the source tarball which gets mapped to `nodejs-latest.tar.gz`.
return ['docs/', `node-${version}.tar.gz`]
}
const expected = []
const fixtures = []
for (const version of ['v26.13.0', 'v27.0.0-alpha.0.0.0']) {
const line = version.split('.')[0]
fixtures.push(version)
// Link under docs
expected.push([`docs/${version}`, `base/${version}/docs`])
// `latest-v.x` links
expected.push([`base/latest-${line}.x`, `base/${version}`])
expected.push([`docs/latest-${line}.x`, `base/${version}/docs`])
}
// v26.13.0 should result in `latest-lithium` links
expected.push(['base/latest-lithium', 'base/v26.13.0'])
expected.push(['docs/latest-lithium', 'base/v26.13.0/docs'])
// Expect `latest` to point to the non-alpha release
expected.push(['base/latest', 'base/v26.13.0'])
expected.push(['base/node-latest.tar.gz', 'base/latest/node-v26.13.0.tar.gz'])
expected.push(['docs/latest', 'base/v26.13.0/docs'])
const links = await linker.getLinks(fixtures, fakeReaddir)
t.same(links, new Map(expected))
t.end()
})
tap.test('alphas are ignored after current release', async t => {
const linker = new Linker({ baseDir: 'base', docsDir: 'docs' })
const fakeReaddir = async (v) => {
const version = path.basename(v)
// Mimimum expected content are the `docs` directory, and
// the source tarball which gets mapped to `nodejs-latest.tar.gz`.
return ['docs/', `node-${version}.tar.gz`]
}
const expected = []
const fixtures = []
for (const version of ['v26.13.0', 'v27.0.0-alpha.0.0.0', 'v27.0.0']) {
const line = version.split('.')[0]
fixtures.push(version)
// Link under docs
expected.push([`docs/${version}`, `base/${version}/docs`])
// `latest-v.x` links
expected.push([`base/latest-${line}.x`, `base/${version}`])
expected.push([`docs/latest-${line}.x`, `base/${version}/docs`])
}
// v26.13.0 should result in `latest-lithium` links
expected.push(['base/latest-lithium', 'base/v26.13.0'])
expected.push(['docs/latest-lithium', 'base/v26.13.0/docs'])
// TODO: test will need to be updated to expect `latest-magnesium`
// when mapping in `common.js` is in place for `27: 'magnesium'`.
// Expect `latest` to point to the non-alpha 27.0.0 release
expected.push(['base/latest', 'base/v27.0.0'])
expected.push(['base/node-latest.tar.gz', 'base/latest/node-v27.0.0.tar.gz'])
expected.push(['docs/latest', 'base/v27.0.0/docs'])
const links = await linker.getLinks(fixtures, fakeReaddir)
t.same(links, new Map(expected))
t.end()
})