-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhelpers.spec.js
65 lines (53 loc) · 1.66 KB
/
helpers.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* eslint-env jest */
const delMock = jest.fn()
jest.doMock('del', () => delMock)
jest.doMock('os', () => ({ homedir: () => '$HOMEDIR' }))
process.argv = [ 'node', 'meteor-hero', '-e', 'something', '-e', 'anotherarg' ]
const mockLog = jest.spyOn(console, 'log').mockImplementation(() => {})
const {
args,
logger,
objToEnvStr,
meteorBuildDir,
clearBuildFolder
} = require('./helpers')
it('args', () => {
expect(args).toMatchObject({ e: ['something', 'anotherarg'] })
})
it('clearBuildFolder', () => {
clearBuildFolder('somepath')
expect(delMock).toHaveBeenCalledWith('somepath', { force: true })
})
it('explain', () => {
const mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {})
const mockLog = jest.spyOn(console, 'log').mockImplementation(() => {})
const { explain } = require('./helpers')
explain()
expect(mockLog).toHaveBeenCalled()
expect(mockExit).toHaveBeenCalledWith(1)
})
it('logger', () => {
const mockLog = jest.spyOn(console, 'log').mockImplementation(() => {})
logger.success('Worked!')
expect(mockLog).toHaveBeenCalled()
})
it('objToEnvStr', () => {
const obj = { ROOT_URL: 'https://example.com' }
expect(objToEnvStr(obj)).toBe('ROOT_URL=https://example.com')
})
describe('meteorBuildDir', () => {
it('defaults to $HOMEDIR', () => {
expect(meteorBuildDir).toBe('$HOMEDIR/.meteor-hero/builds')
})
it('accepts -b param', () => {
jest.resetModules() // this is important - it clears the cache
process.argv = [
'node',
'meteor-hero',
'-b',
'/something/custom'
]
const { meteorBuildDir } = require('./helpers')
expect(meteorBuildDir).toBe('/something/custom')
})
})