-
Notifications
You must be signed in to change notification settings - Fork 339
/
Copy pathformat.test.ts
180 lines (172 loc) · 4.86 KB
/
format.test.ts
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import { expect } from 'chai'
import fs from 'fs/promises'
import os from 'os'
import path from 'path'
import spawn from 'spawn-please'
import chaiSetup from './helpers/chaiSetup'
import stubVersions from './helpers/stubVersions'
chaiSetup()
const bin = path.join(__dirname, '../build/cli.js')
describe('format', () => {
// do not stubVersions here, because we need to test if if time is parsed correctly from npm-registry-fetch
it('--format time', async () => {
const timestamp = '2020-04-27T21:48:11.660Z'
const packageData = {
dependencies: {
'ncu-test-v2': '^1.0.0',
},
}
const { stdout } = await spawn('node', [bin, '--format', 'time', '--stdin'], { stdin: JSON.stringify(packageData) })
expect(stdout).contains(timestamp)
})
it('--format repo', async () => {
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'npm-check-updates-'))
const pkgFile = path.join(tempDir, 'package.json')
await fs.writeFile(
pkgFile,
JSON.stringify({
dependencies: {
'modern-diacritics': '^1.0.0',
},
}),
'utf-8',
)
try {
await spawn('npm', ['install'], {}, { cwd: tempDir })
const { stdout } = await spawn('node', [bin, '--format', 'repo'], {}, { cwd: tempDir })
stdout.should.include('https://github.com/Mitsunee/modern-diacritics')
} finally {
await fs.rm(tempDir, { recursive: true, force: true })
}
})
it('--format lines', async () => {
const stub = stubVersions(
{
'ncu-test-v2': '2.0.0',
'ncu-test-tag': '1.1.0',
},
{ spawn: true },
)
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'npm-check-updates-'))
const pkgFile = path.join(tempDir, 'package.json')
await fs.writeFile(
pkgFile,
JSON.stringify({
dependencies: {
'ncu-test-v2': '^1.0.0',
'ncu-test-tag': '^1.0.0',
},
}),
'utf-8',
)
try {
const { stdout } = await spawn('node', [bin, '--format', 'lines'], {}, { cwd: tempDir })
stdout.should.equals('ncu-test-v2@^2.0.0\nncu-test-tag@^1.1.0\n')
} finally {
await fs.rm(tempDir, { recursive: true, force: true })
stub.restore()
}
})
it('disallow --format lines with --jsonUpgraded', async () => {
const stub = stubVersions(
{
'ncu-test-v2': '2.0.0',
'ncu-test-tag': '1.1.0',
},
{ spawn: true },
)
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'npm-check-updates-'))
const pkgFile = path.join(tempDir, 'package.json')
await fs.writeFile(
pkgFile,
JSON.stringify({
dependencies: {
'ncu-test-v2': '^1.0.0',
'ncu-test-tag': '^1.0.0',
},
}),
'utf-8',
)
try {
await spawn(
'node',
[bin, '--format', 'lines', '--jsonUpgraded'],
{},
{
cwd: tempDir,
},
).should.eventually.be.rejectedWith('Cannot specify both --format lines and --jsonUpgraded.')
} finally {
await fs.rm(tempDir, { recursive: true, force: true })
stub.restore()
}
})
it('disallow --format lines with --jsonAll', async () => {
const stub = stubVersions(
{
'ncu-test-v2': '2.0.0',
'ncu-test-tag': '1.1.0',
},
{ spawn: true },
)
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'npm-check-updates-'))
const pkgFile = path.join(tempDir, 'package.json')
await fs.writeFile(
pkgFile,
JSON.stringify({
dependencies: {
'ncu-test-v2': '^1.0.0',
'ncu-test-tag': '^1.0.0',
},
}),
'utf-8',
)
try {
await spawn(
'node',
[bin, '--format', 'lines', '--jsonAll'],
{},
{
cwd: tempDir,
},
).should.eventually.be.rejectedWith('Cannot specify both --format lines and --jsonAll.')
} finally {
await fs.rm(tempDir, { recursive: true, force: true })
stub.restore()
}
})
it('disallow --format lines with other format options', async () => {
const stub = stubVersions(
{
'ncu-test-v2': '2.0.0',
'ncu-test-tag': '1.1.0',
},
{ spawn: true },
)
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'npm-check-updates-'))
const pkgFile = path.join(tempDir, 'package.json')
await fs.writeFile(
pkgFile,
JSON.stringify({
dependencies: {
'ncu-test-v2': '^1.0.0',
'ncu-test-tag': '^1.0.0',
},
}),
'utf-8',
)
try {
await spawn(
'node',
[bin, '--format', 'lines,group'],
{},
{
cwd: tempDir,
},
).should.eventually.be.rejectedWith('Cannot use --format lines with other formatting options.')
} finally {
await fs.rm(tempDir, { recursive: true, force: true })
stub.restore()
}
})
})