-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
index.js
74 lines (58 loc) · 1.43 KB
/
index.js
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
jest.mock(`../reporter`, () => {
return {
panic: jest.fn(),
log: jest.fn(),
stripIndent: jest.fn(str => str),
}
})
jest.mock(`../create-cli`)
const getCLI = () => {
jest.resetModules()
const reporter = require(`../reporter`)
const createCLI = require(`../create-cli`)
require(`../`)
return {
reporter,
createCLI,
}
}
let __process__
beforeAll(() => {
__process__ = global.process
})
beforeEach(() => {
global.process = __process__
})
const setup = version => {
if (version) {
Object.defineProperty(__process__, `version`, {
get: () => version,
})
}
return getCLI()
}
describe(`error handling`, () => {
it(`panics on Node < 10.0.0`, () => {
const { reporter } = setup(`v8.0.0`)
expect(reporter.panic).toHaveBeenCalledTimes(1)
})
it(`shows error with link to more info`, () => {
const { reporter } = setup(`v8.0.0`)
expect(reporter.panic).toHaveBeenCalledWith(
expect.stringContaining(`https://gatsby.dev/upgrading-node-js`)
)
})
})
describe(`normal behavior`, () => {
it(`does not panic on Node >= 10.0.0`, () => {
;[`10.0.0`, `11.0.0`, `12.0.0`].forEach(version => {
const { reporter } = setup(version)
expect(reporter.panic).not.toHaveBeenCalled()
})
})
it(`invokes createCLI`, () => {
const { createCLI } = setup()
expect(createCLI).toHaveBeenCalledTimes(1)
expect(createCLI).toHaveBeenCalledWith(process.argv)
})
})