-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.test.js
88 lines (78 loc) · 2.51 KB
/
cli.test.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const chalk = require('chalk');
const execSync = require('child_process').execSync;
const originalConsoleLog = console.log;
console.log = jest.fn(() => true);
const originalConsoleError = console.error;
console.error = jest.fn();
jest.mock('child_process', () => {
const execSync = jest.fn();
return {execSync};
});
jest.mock('chalk', () => {
const red = jest.fn((text) => text);
const cyan = jest.fn((text) => text);
const green = jest.fn((text) => text);
const magenta = jest.fn((text) => text);
return {
red,
cyan,
green,
magenta,
};
});
describe('cli runs properly', () => {
it('cli runs with argument and logs info', (done) => {
process.argv[2] = 'myFakeName';
jest.requireActual('./cli');
let isYarnAvailable;
try {
execSync('yarnpkg --version', {stdio: 'ignore'});
isYarnAvailable = true;
} catch (e) {
isYarnAvailable = false;
}
const packageManagerRunCommand = isYarnAvailable ? 'yarn' : 'npm run';
process.nextTick(() => {
expect(chalk.red.mock.calls).toEqual([]);
expect(chalk.cyan.mock.calls).toEqual([
['⏳ Creating React Once App by the name of myFakeName'],
['cd myFakeName'],
['Then run the these commands to get started:'],
[`${packageManagerRunCommand} web`],
[`${packageManagerRunCommand} android`],
[`${packageManagerRunCommand} ios`],
[`${packageManagerRunCommand} test`],
[`${packageManagerRunCommand} build`],
]);
expect(chalk.green.mock.calls).toEqual([['<project-directory>']]);
expect(chalk.magenta.mock.calls).toEqual([
['*'],
['change directory to your new project'],
['*'],
['To run development Web server'],
['*'],
[
'To run Android on connected device (after installing Android Debug Bridge "adb" - https://developer.android.com/studio/releases/platform-tools)',
],
['*'],
[
'To run ios simulator (after installing Xcode - only on Apple devices)',
],
['*'],
['To run tests for Native and Web'],
['*'],
['To run build for Web'],
]);
expect(execSync.mock.calls).toEqual([
[
'npx react-native init myFakeName --template https://gitlab.com/NoahGray/react-once-template.git',
{stdio: [0, 1, 2]},
],
['yarnpkg --version', {stdio: 'ignore'}],
['cd myFakeName && git init'],
['yarnpkg --version', {stdio: 'ignore'}],
]);
});
done();
});
});