1 const t = require('tap')
2 const fm = require('front-matter')
3
4 const transform = ({id, path}) => {
5 const Transform = t.mockRequire('../lib/transform', {
6 '../lib/gh.js': {nwo: 'npm/cli'},
7 })
8 const transformed = Transform.sync('---\n---\n', {
9 release: {
10 id: id,
11 default: id === 'v8',
12 src: 'docs/content',
13 url: `/cli/${id}/${path}`,
14 urlPrefixes: ['/cli'],
15 },
16 path,
17 })
18 return fm(transformed).attributes
19 }
20
21 t.test('v6 default page', async t => {
22 const v6 = transform({id: 'v6', path: 'configuring-npm/package-locks'})
23 const v7 = transform({id: 'v7', path: 'configuring-npm/package-locks'})
24
25 t.strictSame(v6.redirect_from, [
26 '/cli/configuring-npm/package-locks',
27 '/cli/files/package-locks',
28 '/cli/v6/configuring-npm/package-locks',
29 '/cli/v6/files/package-locks',
30 '/configuring-npm/package-locks',
31 '/files/package-locks',
32 ])
33 t.strictSame(v7.redirect_from, ['/cli/v7/configuring-npm/package-locks', '/cli/v7/files/package-locks'])
34 })
35
36 t.test('command', async t => {
37 const v7 = transform({id: 'v7', path: 'commands/npm-bin'})
38 const v8 = transform({id: 'v8', path: 'commands/npm-bin'})
39
40 t.strictSame(v7.redirect_from, [
41 '/cli/v7/bin',
42 '/cli/v7/cli-commands/bin',
43 '/cli/v7/cli-commands/npm-bin',
44 '/cli/v7/commands/bin',
45 '/cli/v7/commands/npm-bin',
46 '/cli/v7/npm-bin',
47 ])
48 t.strictSame(v8.redirect_from, [
49 '/cli-commands/bin',
50 '/cli-commands/npm-bin',
51 '/cli/bin',
52 '/cli/cli-commands/bin',
53 '/cli/cli-commands/npm-bin',
54 '/cli/commands/bin',
55 '/cli/commands/npm-bin',
56 '/cli/npm-bin',
57 '/cli/v8/bin',
58 '/cli/v8/cli-commands/bin',
59 '/cli/v8/cli-commands/npm-bin',
60 '/cli/v8/commands/bin',
61 '/cli/v8/commands/npm-bin',
62 '/cli/v8/npm-bin',
63 '/commands/bin',
64 '/commands/npm-bin',
65 ])
66 })
67
68 t.test('package-json files', async t => {
69 const v7 = transform({id: 'v7', path: 'configuring-npm/package-json'})
70 const v8 = transform({id: 'v8', path: 'configuring-npm/package-json'})
71
72 t.strictSame(v7.redirect_from, [
73 '/cli/v7/configuring-npm/package-json',
74 '/cli/v7/configuring-npm/package.json',
75 '/cli/v7/files/package-json',
76 '/cli/v7/files/package.json',
77 ])
78 t.strictSame(v8.redirect_from, [
79 '/cli/configuring-npm/package-json',
80 '/cli/configuring-npm/package.json',
81 '/cli/files/package-json',
82 '/cli/files/package.json',
83 '/cli/v8/configuring-npm/package-json',
84 '/cli/v8/configuring-npm/package.json',
85 '/cli/v8/files/package-json',
86 '/cli/v8/files/package.json',
87 '/configuring-npm/package-json',
88 '/configuring-npm/package.json',
89 '/files/package-json',
90 '/files/package.json',
91 ])
92 })
93
94 t.test('registry signatures', async t => {
95 t.strictSame(
96 transform({
97 id: 'v8',
98 path: 'about-pgp-signatures-for-packages-in-the-public-registry',
99 }).redirect_from,
100 [
101 '/about-registry-signatures',
102 '/cli/about-pgp-signatures-for-packages-in-the-public-registry',
103 '/cli/v8/about-pgp-signatures-for-packages-in-the-public-registry',
104 ],
105 )
106 t.strictSame(
107 transform({
108 id: 'v8',
109 path: 'verifying-the-pgp-signature-for-a-package-from-the-npm-public-registry',
110 }).redirect_from,
111 [
112 '/cli/v8/verifying-the-pgp-signature-for-a-package-from-the-npm-public-registry',
113 '/cli/verifying-the-pgp-signature-for-a-package-from-the-npm-public-registry',
114 '/verifying-registry-signatures',
115 ],
116 )
117 })