Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: delete useless mocking in e2e tests #2103

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 13 additions & 29 deletions __e2e__/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import {
writeFiles,
} from '../jest/helpers';
import slash from 'slash';
import prompts from 'prompts';

jest.mock('prompts', () => jest.fn());

const DIR = getTempDirectory('command-init');
const PROJECT_NAME = 'TestInit';

function createCustomTemplateFiles() {
writeFiles(DIR, {
Expand Down Expand Up @@ -51,31 +49,18 @@ if (process.platform === 'win32') {
}

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

const {stderr} = runCLI(DIR, ['init', 'TestInit'], {expectedFailure: true});
const {stderr} = runCLI(DIR, ['init', PROJECT_NAME], {expectedFailure: true});
expect(stderr).toContain(
'error Cannot initialize new project because directory "TestInit" already exists.',
`error Cannot initialize new project because directory "${PROJECT_NAME}" already exists.`,
);
});

test('init should prompt for the project name', () => {
createCustomTemplateFiles();
const {stdout} = runCLI(DIR, [
'init',
'test',
'--template',
templatePath,
'--install-pods',
'false',
]);
const {stdout} = runCLI(DIR, ['init']);

(prompts as jest.MockedFunction<typeof prompts>).mockReturnValue(
Promise.resolve({
name: 'TestInit',
}),
);
expect(stdout).toContain('Run instructions');
expect(stdout).toContain('How would you like to name the app?');
});

test('init --template filepath', () => {
Expand All @@ -85,7 +70,7 @@ test('init --template filepath', () => {
'init',
'--template',
templatePath,
'TestInit',
PROJECT_NAME,
'--install-pods',
'false',
]);
Expand All @@ -95,21 +80,20 @@ test('init --template filepath', () => {
// make sure we don't leave garbage
expect(fs.readdirSync(DIR)).toContain('custom');

let dirFiles = fs.readdirSync(path.join(DIR, 'TestInit'));
let dirFiles = fs.readdirSync(path.join(DIR, PROJECT_NAME));

expect(dirFiles).toEqual(customTemplateCopiedFiles);
});

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

const {stdout} = runCLI(DIR, [
'init',
'--template',
templatePath,
projectName,
PROJECT_NAME,
'--directory',
'custom-path',
'--install-pods',
Expand All @@ -133,7 +117,7 @@ test('init skips installation of dependencies with --skip-install', () => {
'init',
'--template',
templatePath,
'TestInit',
PROJECT_NAME,
'--skip-install',
]);

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

let dirFiles = fs.readdirSync(path.join(DIR, 'TestInit'));
let dirFiles = fs.readdirSync(path.join(DIR, PROJECT_NAME));

expect(dirFiles).toEqual(
customTemplateCopiedFiles.filter(
Expand All @@ -158,7 +142,7 @@ test('init uses npm as the package manager with --npm', () => {
'init',
'--template',
templatePath,
'TestInit',
PROJECT_NAME,
'--npm',
'--install-pods',
'false',
Expand All @@ -169,7 +153,7 @@ test('init uses npm as the package manager with --npm', () => {
// make sure we don't leave garbage
expect(fs.readdirSync(DIR)).toContain('custom');

const initDirPath = path.join(DIR, 'TestInit');
const initDirPath = path.join(DIR, PROJECT_NAME);

// Remove yarn.lock and node_modules
const filteredFiles = customTemplateCopiedFiles.filter(
Expand Down