Skip to content

Commit 3f0de48

Browse files
author
Nick Balestra
committed
cca tests cleanup
1 parent e22441c commit 3f0de48

File tree

7 files changed

+51
-47
lines changed

7 files changed

+51
-47
lines changed

packages/create-cycle-app/test/integration/createCycleApp.spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ describe('create-cycle-app', () => {
1111
path.resolve(__dirname, '../../index.js'),
1212
appName,
1313
'--flavour',
14-
'cycle-scripts@1.0.3'
14+
'cycle-scripts@1.0.3',
15+
'--noyarn'
1516
])
1617
).toThrowError()
1718
})
@@ -35,7 +36,8 @@ describe('create-cycle-app', () => {
3536
path.resolve(__dirname, '../../index.js'),
3637
appName,
3738
'--flavor',
38-
'cycle-scripts@1.0.3'
39+
'cycle-scripts@1.0.3',
40+
'--noyarn'
3941
])
4042
dir = fs.readdirSync(appName)
4143
done()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
jest.mock('fs')
2+
const fs = require('fs')
3+
jest.mock('../../src/isSafeToCreateApp')
4+
const isSafeToCreateApp = require('../../src/isSafeToCreateApp')
5+
6+
const createAppDir = require('../../src/createAppDir')
7+
8+
describe('createAppDir module', () => {
9+
afterEach(() => {
10+
fs.existsSync.mockClear()
11+
isSafeToCreateApp.mockClear()
12+
})
13+
14+
describe('when calling it and the directory does not exist', () => {
15+
test('should create it', (done) => {
16+
fs.existsSync.mockReturnValue(false)
17+
createAppDir('./appFolder')
18+
expect(fs.existsSync).toBeCalledWith('./appFolder')
19+
expect(fs.mkdirSync).toBeCalledWith('./appFolder')
20+
expect(isSafeToCreateApp).not.toBeCalled()
21+
done()
22+
})
23+
})
24+
})

packages/create-cycle-app/test/unit/preparePackageJson.spec.js renamed to packages/create-cycle-app/test/unit/createPackageJson.spec.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
const preparePackageJson = require('../../src/preparePackageJson')
1+
const createPackageJson = require('../../src/createPackageJson')
22
jest.mock('fs')
33
const fs = require('fs')
4+
jest.mock('console')
5+
const console = require('console')
6+
const chalk = require('chalk')
47

5-
describe('preparePackageJson module', () => {
8+
describe('createPackageJson module', () => {
69
describe('when calling it', () => {
710
test('should correctly prepare package.json and write it to disk', () => {
8-
const callback = jest.fn()
9-
preparePackageJson('testPath', 'testName', callback)
11+
createPackageJson('testPath', 'testName')
1012

1113
expect(fs.writeFileSync.mock.calls[0][0]).toBe('testPath/package.json')
1214
expect(fs.writeFileSync.mock.calls[0][1]).toBe(JSON.stringify({
1315
name: 'testName',
1416
version: '0.1.0',
1517
private: true
1618
}, null, 2))
17-
expect(callback).toBeCalled()
19+
expect(console.log).toHaveBeenCalledTimes(2)
20+
expect(console.log).toHaveBeenCalledWith(chalk.green('Creating a new Cycle.js app in testPath.'))
1821
})
1922
})
2023
})

packages/create-cycle-app/test/unit/createProjectIn.spec.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

packages/create-cycle-app/test/unit/initQuestions.spec.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,13 @@ const inquirer = require('inquirer')
44

55
describe('initQuedstion module', () => {
66
describe('when calling it', () => {
7-
test('should not prompt for question if a custom flavor is provided', () => {
8-
const callback = jest.fn()
9-
initQuestions('customFlavor', callback)
10-
expect(callback).toBeCalledWith(false)
11-
expect(inquirer.prompt).not.toBeCalled()
12-
})
13-
test('should prompt for question if no custom flavor is provided', () => {
7+
test('should prompt for question', () => {
148
const callback = jest.fn()
159
const answer = {language: 'javascript', streamLib: 'xstream'}
1610
inquirer.prompt.mockReturnValue({
1711
then: jest.fn(answers => callback(answer))
1812
})
19-
initQuestions(undefined, callback)
13+
initQuestions(callback)
2014
expect(callback).toBeCalledWith(answer)
2115
expect(inquirer.prompt).toBeCalled()
2216
})

packages/create-cycle-app/test/unit/installScripts.spec.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ const getPackageName = require('../../src/getPackageName')
77
jest.mock('console')
88
const consoleMock = require('console')
99
const installScripts = require('../../src/installScripts')
10-
10+
// installScripts(appFolder, appName, { flavor, verbose, answers: false })
1111
describe('installScripts module', () => {
12-
test('should be a function with arity 5', () => {
12+
test('should be a function with arity 3', () => {
1313
expect(typeof installScripts).toBe('function')
14-
expect(installScripts.length).toBe(5)
14+
expect(installScripts.length).toBe(3)
1515
})
1616

1717
describe('when invoked with a flavor published on npm', () => {
1818
getPackageName.mockImplementation(name => name)
19-
installScripts('./', 'appName', 'cycle-scripts')
19+
installScripts('./', 'appName', { flavor: 'cycle-scripts', cli: 'npm' })
2020

2121
test('should call getPackageName with the name of the npm module', () => {
2222
expect(getPackageName).toBeCalledWith('cycle-scripts')
@@ -31,7 +31,7 @@ describe('installScripts module', () => {
3131
'--save-exact',
3232
'cycle-scripts'
3333
],
34-
{'stdio': 'inherit'}
34+
{'cwd': './', 'stdio': 'inherit'}
3535
)
3636
})
3737

@@ -48,7 +48,7 @@ describe('installScripts module', () => {
4848

4949
describe('when invoked with a local flavor', () => {
5050
getPackageName.mockImplementation(name => path.basename(name))
51-
installScripts('./', 'appName', './cycle-scripts')
51+
installScripts('./', 'appName', { flavor: './cycle-scripts', cli: 'npm' })
5252

5353
test('should console log the correct information', () => {
5454
expect(consoleMock.log.mock.calls[4][0]).toContain(
@@ -57,13 +57,13 @@ describe('installScripts module', () => {
5757
})
5858

5959
test('should call spawn with the correct arguments', () => {
60-
expect(spawn.mock.calls[1][1][3]).toContain('/create-cycle-app/packages/create-cycle-app/cycle-scripts')
60+
expect(spawn.mock.calls[1][1][3]).toContain('./cycle-scripts')
6161
})
6262
})
6363

6464
describe('when invoked with a verbose flag', () => {
6565
getPackageName.mockImplementation(name => name)
66-
installScripts('./', 'appName', 'cycle-scripts', true)
66+
installScripts('./', 'appName', { flavor: 'cycle-scripts', verbose: true, cli: 'npm' })
6767

6868
test('should call spawn with the correct arguments', () => {
6969
expect(spawn.mock.calls[2]).toMatchObject([
@@ -75,7 +75,7 @@ describe('installScripts module', () => {
7575
'--save-exact',
7676
'cycle-scripts'
7777
],
78-
{'stdio': 'inherit'}
78+
{'cwd': './', 'stdio': 'inherit'}
7979
])
8080
})
8181
})

packages/create-cycle-app/test/unit/isSafeToCreateProjectIn.spec.js renamed to packages/create-cycle-app/test/unit/isSafeToCreateApp.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
jest.mock('fs')
22
const fs = require('fs')
3-
const isSafeToCreateProjectIn = require('../../src/isSafeToCreateProjectIn')
3+
const isSafeToCreateApp = require('../../src/isSafeToCreateApp')
44
const whiteList = [
55
'.DS_Store',
66
'Thumbs.db',
@@ -11,19 +11,19 @@ const whiteList = [
1111
'LICENSE'
1212
]
1313

14-
describe('isSafeToCreateProjectIn module', () => {
14+
describe('isSafeToCreateApp module', () => {
1515
describe('when calling it with a directory containing files not white-listened', () => {
1616
test('should return false', () => {
1717
fs.readdirSync.mockImplementation(() => whiteList.concat('index.js'))
18-
const isSafe = isSafeToCreateProjectIn('./someFolder')
18+
const isSafe = isSafeToCreateApp('./someFolder')
1919
expect(isSafe).toBe(false)
2020
})
2121
})
2222

2323
describe('when calling it with a directory containing only white-listened files', () => {
2424
test('should return true', () => {
2525
fs.readdirSync.mockImplementation(() => whiteList)
26-
const isSafe = isSafeToCreateProjectIn('./someFolder')
26+
const isSafe = isSafeToCreateApp('./someFolder')
2727
expect(isSafe).toBe(true)
2828
})
2929
})

0 commit comments

Comments
 (0)