Skip to content

Commit

Permalink
fix: dynamically assign expected failes if initialising git repo fails
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonrybczak committed Nov 4, 2023
1 parent aebdd0a commit ac4fac1
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions __e2e__/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import slash from 'slash';

const DIR = getTempDirectory('command-init');
const PROJECT_NAME = 'TestInit';
const createGitRepoError =
'Could not create an empty Git repository, see debug logs with --verbose';

function createCustomTemplateFiles() {
writeFiles(DIR, {
Expand All @@ -21,7 +23,6 @@ function createCustomTemplateFiles() {
}

const customTemplateCopiedFiles = [
'.git',
'dir',
'file',
'node_modules',
Expand Down Expand Up @@ -79,7 +80,11 @@ test('init --template filepath', () => {

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

expect(dirFiles).toEqual(customTemplateCopiedFiles);
let copiedFiles = stdout.includes(createGitRepoError)
? customTemplateCopiedFiles
: ['.git', ...customTemplateCopiedFiles];

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

test('init --template file with custom directory', () => {
Expand All @@ -104,7 +109,12 @@ test('init --template file with custom directory', () => {
expect(fs.readdirSync(DIR)).toContain(customPath);

let dirFiles = fs.readdirSync(path.join(DIR, customPath));
expect(dirFiles).toEqual(customTemplateCopiedFiles);

let copiedFiles = stdout.includes(createGitRepoError)
? customTemplateCopiedFiles
: ['.git', ...customTemplateCopiedFiles];

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

test('init skips installation of dependencies with --skip-install', () => {
Expand All @@ -125,10 +135,12 @@ test('init skips installation of dependencies with --skip-install', () => {

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

let copiedFiles = stdout.includes(createGitRepoError)
? customTemplateCopiedFiles
: ['.git', ...customTemplateCopiedFiles];

expect(dirFiles).toEqual(
customTemplateCopiedFiles.filter(
(file) => !['node_modules', 'yarn.lock'].includes(file),
),
copiedFiles.filter((file) => !['node_modules', 'yarn.lock'].includes(file)),
);
});

Expand All @@ -152,8 +164,12 @@ test('init uses npm as the package manager with --npm', () => {

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

let copiedFiles = stdout.includes(createGitRepoError)
? customTemplateCopiedFiles
: ['.git', ...customTemplateCopiedFiles];

// Remove yarn.lock and node_modules
const filteredFiles = customTemplateCopiedFiles.filter(
const filteredFiles = copiedFiles.filter(
(file) => !['yarn.lock', 'node_modules'].includes(file),
);

Expand Down

0 comments on commit ac4fac1

Please sign in to comment.