-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
index.ts
112 lines (89 loc) · 2.37 KB
/
index.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
jest.mock(`../reporter`, () => {
return {
panic: jest.fn(),
log: jest.fn(),
stripIndent: jest.fn(str => str),
warn: jest.fn(),
}
})
jest.mock(`../create-cli`)
interface IGetCLI {
reporter: {
panic: jest.Mock
log: jest.Mock
stripIndent: jest.Mock
warn: jest.Mock
}
createCli: jest.Mock
}
const getCLI = (): IGetCLI => {
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?: string): ReturnType<typeof getCLI> => {
if (version) {
Object.defineProperty(__process__, `version`, {
get: () => version,
})
}
return getCLI()
}
describe(`error handling`, () => {
it(`panics on Node < 14.15.0`, () => {
;[`6.0.0`, `8.0.0`, `12.13.0`, `13.0.0`].forEach(version => {
const { reporter } = setup(version)
expect(reporter.panic).toHaveBeenCalledTimes(1)
reporter.panic.mockClear()
})
})
it(`shows error with link to more info`, () => {
const { reporter } = setup(`v6.0.0`)
expect(reporter.panic).toHaveBeenCalledWith(
expect.stringContaining(`https://gatsby.dev/upgrading-node-js`)
)
})
it(`allows prerelease versions`, () => {
const { reporter } = setup(`v15.0.0-pre`)
expect(reporter.panic).not.toHaveBeenCalled()
})
it(`warns on prerelease versions`, () => {
const { reporter } = setup(`v15.0.0-pre`)
expect(reporter.warn).toHaveBeenCalledWith(
expect.stringContaining(`prerelease`)
)
})
})
// describe(`deprecation warning`, () => {
// it(`warns on Node < 10.13.0`, () => {
// const { reporter } = setup(`v10.12.0`)
// expect(reporter.warn).toHaveBeenCalledWith(
// expect.stringContaining(`https://gatsby.dev/upgrading-node-js`)
// )
// })
// })
describe(`normal behavior`, () => {
it(`does not panic on Node >= 14.15.0`, () => {
;[`14.15.0`, `15.0.0`, `16.3.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)
})
})