From 121c89771cd6c020d8d5cb0113d9f283a878a78c Mon Sep 17 00:00:00 2001 From: szymonrybczak Date: Tue, 7 Nov 2023 23:13:44 +0100 Subject: [PATCH] fix: tests --- __e2e__/init.test.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/__e2e__/init.test.ts b/__e2e__/init.test.ts index 3a68483a2..63c7769ea 100644 --- a/__e2e__/init.test.ts +++ b/__e2e__/init.test.ts @@ -46,15 +46,33 @@ if (process.platform === 'win32') { templatePath = `file://${templatePath}`; } -test('init fails if the directory already exists', () => { +test('init fails if the directory already exists and --replace-directory false', () => { fs.mkdirSync(path.join(DIR, PROJECT_NAME)); - const {stderr} = runCLI(DIR, ['init', PROJECT_NAME], {expectedFailure: true}); + const {stderr} = runCLI( + DIR, + ['init', PROJECT_NAME, '--replace-directory', 'false'], + {expectedFailure: true}, + ); + expect(stderr).toContain( `error Cannot initialize new project because directory "${PROJECT_NAME}" already exists.`, ); }); +test('init should ask and print files in directory if exist', () => { + fs.mkdirSync(path.join(DIR, PROJECT_NAME)); + fs.writeFileSync(path.join(DIR, PROJECT_NAME, 'package.json'), '{}'); + + const {stdout, stderr} = runCLI(DIR, ['init', PROJECT_NAME]); + + expect(stderr).toContain( + `warn The directory ${PROJECT_NAME} contains files that will be overwritten:`, + ); + expect(stdout).toContain(`package.json`); + expect(stdout).toContain(`Do you want to replace existing files?`); +}); + test('init should prompt for the project name', () => { const {stdout} = runCLI(DIR, ['init']);