/
checkPkgScripts.spec.js
50 lines (42 loc) · 1.3 KB
/
checkPkgScripts.spec.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
import makeConsoleMock from 'consolemock'
import checkPkgScripts from '../src/checkPkgScripts'
describe('checkPkgScripts', () => {
describe('does not throw', () => {
it('if there are no scripts defined', () => {
expect(() => checkPkgScripts(null)).not.toThrow()
expect(() => checkPkgScripts({})).not.toThrow()
})
it('if the script cannot be found', () => {
expect(() => checkPkgScripts({ scripts: {} }, 'fmt')).not.toThrow()
})
})
describe('throws', () => {
const originalConsole = global.console
beforeAll(() => {
global.console = makeConsoleMock()
})
beforeEach(() => {
global.console.clearHistory()
})
afterAll(() => {
global.console = originalConsole
})
const pkg = {
scripts: {
lint: 'eslint .'
}
}
it('if the cmd is defined in script', () => {
expect(() => {
checkPkgScripts(pkg, 'lint', 'lint')
}).toThrow('Could not resolve binary for `lint`')
expect(console.printHistory()).toMatchSnapshot()
})
it('if the binary name is defined in script', () => {
expect(() => {
checkPkgScripts(pkg, 'lint --fix', 'lint', ['--fix'])
}).toThrow('Could not resolve binary for `lint --fix`')
expect(console.printHistory()).toMatchSnapshot()
})
})
})