Skip to content

Commit

Permalink
chore: pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
molant committed May 8, 2020
1 parent 1a0b9bb commit 4b7b5f0
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 30 deletions.
6 changes: 3 additions & 3 deletions __e2e__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {wrap} from 'jest-snapshot-serializer-raw';
import {
runCLI,
getTempDirectory,
cleanup,
cleanupSync,
writeFiles,
spawnScript,
replaceProjectRootInOutput,
Expand Down Expand Up @@ -44,7 +44,7 @@ beforeAll(() => {
}

// Clean up folder and re-create a new project
cleanup(DIR, false);
cleanupSync(DIR);
writeFiles(DIR, {});

// Initialise React Native project
Expand All @@ -63,7 +63,7 @@ beforeAll(() => {
});

afterAll(() => {
cleanup(DIR, false);
cleanupSync(DIR);
});

test('shows up current config without unnecessary output', () => {
Expand Down
11 changes: 8 additions & 3 deletions __e2e__/default.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import {runCLI, getTempDirectory, cleanup, writeFiles} from '../jest/helpers';
import {
runCLI,
getTempDirectory,
cleanupSync,
writeFiles,
} from '../jest/helpers';

const DIR = getTempDirectory('test_default_behavior');

beforeEach(async () => {
cleanup(DIR, false);
cleanupSync(DIR);
writeFiles(DIR, {});
});
afterEach(async () => {
cleanup(DIR, false);
cleanupSync(DIR);
});

test('shows up help information without passing in any args', () => {
Expand Down
11 changes: 8 additions & 3 deletions __e2e__/init.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import fs from 'fs';
import path from 'path';
import {runCLI, getTempDirectory, cleanup, writeFiles} from '../jest/helpers';
import {
runCLI,
getTempDirectory,
cleanupSync,
writeFiles,
} from '../jest/helpers';

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

Expand All @@ -27,11 +32,11 @@ const customTemplateCopiedFiles = [
];

beforeEach(() => {
cleanup(DIR, false);
cleanupSync(DIR);
writeFiles(DIR, {});
});
afterEach(() => {
cleanup(DIR, false);
cleanupSync(DIR);
});

test('init --template fails without package name', () => {
Expand Down
11 changes: 8 additions & 3 deletions __e2e__/install.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import path from 'path';
import {runCLI, getTempDirectory, cleanup, writeFiles} from '../jest/helpers';
import {
runCLI,
getTempDirectory,
cleanupSync,
writeFiles,
} from '../jest/helpers';

const DIR = getTempDirectory('command-install-test');
const pkg = 'react-native-config';

beforeEach(() => {
cleanup(DIR, false);
cleanupSync(DIR);
writeFiles(DIR, {
'node_modules/react-native/package.json': '{}',
'package.json': '{}',
});
});
afterEach(() => cleanup(DIR, false));
afterEach(() => cleanupSync(DIR));

test.each(['yarn', 'npm'])('install module with %s', pm => {
if (pm === 'yarn') {
Expand Down
6 changes: 3 additions & 3 deletions __e2e__/legacyInit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import fs from 'fs';
import path from 'path';
// @ts-ignore
import execa from 'execa';
import {getTempDirectory, cleanup, writeFiles} from '../jest/helpers';
import {getTempDirectory, cleanupSync, writeFiles} from '../jest/helpers';

const DIR = getTempDirectory('command-legacy-init');

beforeEach(() => {
cleanup(DIR, false);
cleanupSync(DIR);
writeFiles(DIR, {});
});
afterEach(() => {
cleanup(DIR, false);
cleanupSync(DIR);
});

// We skip this test, because it's flaky and we don't really update
Expand Down
6 changes: 3 additions & 3 deletions __e2e__/root.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
spawnScript,
runCLI,
getTempDirectory,
cleanup,
cleanupSync,
writeFiles,
} from '../jest/helpers';

Expand All @@ -19,7 +19,7 @@ beforeAll(() => {
}

// Clean up folder and re-create a new project
cleanup(cwd, false);
cleanupSync(cwd);
writeFiles(cwd, {});

// Initialise React Native project
Expand All @@ -37,7 +37,7 @@ beforeAll(() => {
});

afterAll(() => {
cleanup(cwd, false);
cleanupSync(cwd);
});

test('works when Gradle is run outside of the project hierarchy', () => {
Expand Down
11 changes: 8 additions & 3 deletions __e2e__/uninstall.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import {runCLI, getTempDirectory, cleanup, writeFiles} from '../jest/helpers';
import {
runCLI,
getTempDirectory,
cleanupSync,
writeFiles,
} from '../jest/helpers';

const DIR = getTempDirectory('command-uninstall-test');
const pkg = 'react-native-config';

beforeEach(() => {
cleanup(DIR, false);
cleanupSync(DIR);
writeFiles(DIR, {
'node_modules/react-native/package.json': '{}',
'node_modules/react-native-config/package.json': '{}',
Expand All @@ -15,7 +20,7 @@ beforeEach(() => {
}`,
});
});
afterEach(() => cleanup(DIR, false));
afterEach(() => cleanupSync(DIR));

test('uninstall fails when package is not defined', () => {
writeFiles(DIR, {
Expand Down
11 changes: 8 additions & 3 deletions __e2e__/unknown.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import {runCLI, getTempDirectory, cleanup, writeFiles} from '../jest/helpers';
import {
runCLI,
getTempDirectory,
cleanupSync,
writeFiles,
} from '../jest/helpers';

const DIR = getTempDirectory('test_unknown');

beforeEach(() => {
cleanup(DIR, false);
cleanupSync(DIR);
writeFiles(DIR, {});
});
afterEach(() => {
cleanup(DIR, false);
cleanupSync(DIR);
});

test('warn for passing in unknown commands', () => {
Expand Down
12 changes: 6 additions & 6 deletions jest/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ export const makeTemplate = (
return values[number - 1];
});

export const cleanup = (directory: string, async = true) => {
if (!async) {
return rimraf.sync(directory);
} else {
return rimrafAsync(directory);
}
export const cleanup = (directory: string) => {
return rimrafAsync(directory);
};

export const cleanupSync = (directory: string) => {
rimraf.sync(directory);
};

/**
Expand Down

0 comments on commit 4b7b5f0

Please sign in to comment.