Skip to content

Commit 28a75d5

Browse files
fix: delete useless mocking in e2e tests (#2103)
* fix: delete useless mocking * chore: extract value to constant
1 parent dea0642 commit 28a75d5

File tree

1 file changed

+13
-29
lines changed

1 file changed

+13
-29
lines changed

__e2e__/init.test.ts

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ import {
77
writeFiles,
88
} from '../jest/helpers';
99
import slash from 'slash';
10-
import prompts from 'prompts';
11-
12-
jest.mock('prompts', () => jest.fn());
1310

1411
const DIR = getTempDirectory('command-init');
12+
const PROJECT_NAME = 'TestInit';
1513

1614
function createCustomTemplateFiles() {
1715
writeFiles(DIR, {
@@ -51,31 +49,18 @@ if (process.platform === 'win32') {
5149
}
5250

5351
test('init fails if the directory already exists', () => {
54-
fs.mkdirSync(path.join(DIR, 'TestInit'));
52+
fs.mkdirSync(path.join(DIR, PROJECT_NAME));
5553

56-
const {stderr} = runCLI(DIR, ['init', 'TestInit'], {expectedFailure: true});
54+
const {stderr} = runCLI(DIR, ['init', PROJECT_NAME], {expectedFailure: true});
5755
expect(stderr).toContain(
58-
'error Cannot initialize new project because directory "TestInit" already exists.',
56+
`error Cannot initialize new project because directory "${PROJECT_NAME}" already exists.`,
5957
);
6058
});
6159

6260
test('init should prompt for the project name', () => {
63-
createCustomTemplateFiles();
64-
const {stdout} = runCLI(DIR, [
65-
'init',
66-
'test',
67-
'--template',
68-
templatePath,
69-
'--install-pods',
70-
'false',
71-
]);
61+
const {stdout} = runCLI(DIR, ['init']);
7262

73-
(prompts as jest.MockedFunction<typeof prompts>).mockReturnValue(
74-
Promise.resolve({
75-
name: 'TestInit',
76-
}),
77-
);
78-
expect(stdout).toContain('Run instructions');
63+
expect(stdout).toContain('How would you like to name the app?');
7964
});
8065

8166
test('init --template filepath', () => {
@@ -85,7 +70,7 @@ test('init --template filepath', () => {
8570
'init',
8671
'--template',
8772
templatePath,
88-
'TestInit',
73+
PROJECT_NAME,
8974
'--install-pods',
9075
'false',
9176
]);
@@ -95,21 +80,20 @@ test('init --template filepath', () => {
9580
// make sure we don't leave garbage
9681
expect(fs.readdirSync(DIR)).toContain('custom');
9782

98-
let dirFiles = fs.readdirSync(path.join(DIR, 'TestInit'));
83+
let dirFiles = fs.readdirSync(path.join(DIR, PROJECT_NAME));
9984

10085
expect(dirFiles).toEqual(customTemplateCopiedFiles);
10186
});
10287

10388
test('init --template file with custom directory', () => {
10489
createCustomTemplateFiles();
105-
const projectName = 'TestInit';
10690
const customPath = 'custom-path';
10791

10892
const {stdout} = runCLI(DIR, [
10993
'init',
11094
'--template',
11195
templatePath,
112-
projectName,
96+
PROJECT_NAME,
11397
'--directory',
11498
'custom-path',
11599
'--install-pods',
@@ -133,7 +117,7 @@ test('init skips installation of dependencies with --skip-install', () => {
133117
'init',
134118
'--template',
135119
templatePath,
136-
'TestInit',
120+
PROJECT_NAME,
137121
'--skip-install',
138122
]);
139123

@@ -142,7 +126,7 @@ test('init skips installation of dependencies with --skip-install', () => {
142126
// make sure we don't leave garbage
143127
expect(fs.readdirSync(DIR)).toContain('custom');
144128

145-
let dirFiles = fs.readdirSync(path.join(DIR, 'TestInit'));
129+
let dirFiles = fs.readdirSync(path.join(DIR, PROJECT_NAME));
146130

147131
expect(dirFiles).toEqual(
148132
customTemplateCopiedFiles.filter(
@@ -158,7 +142,7 @@ test('init uses npm as the package manager with --npm', () => {
158142
'init',
159143
'--template',
160144
templatePath,
161-
'TestInit',
145+
PROJECT_NAME,
162146
'--npm',
163147
'--install-pods',
164148
'false',
@@ -169,7 +153,7 @@ test('init uses npm as the package manager with --npm', () => {
169153
// make sure we don't leave garbage
170154
expect(fs.readdirSync(DIR)).toContain('custom');
171155

172-
const initDirPath = path.join(DIR, 'TestInit');
156+
const initDirPath = path.join(DIR, PROJECT_NAME);
173157

174158
// Remove yarn.lock and node_modules
175159
const filteredFiles = customTemplateCopiedFiles.filter(

0 commit comments

Comments
 (0)