diff --git a/__e2e__/config.test.ts b/__e2e__/config.test.ts index c452dd540..f4c86659e 100644 --- a/__e2e__/config.test.ts +++ b/__e2e__/config.test.ts @@ -4,7 +4,7 @@ import {wrap} from 'jest-snapshot-serializer-raw'; import { runCLI, getTempDirectory, - cleanup, + cleanupSync, writeFiles, spawnScript, replaceProjectRootInOutput, @@ -44,7 +44,7 @@ beforeAll(() => { } // Clean up folder and re-create a new project - cleanup(DIR); + cleanupSync(DIR); writeFiles(DIR, {}); // Initialise React Native project @@ -63,7 +63,7 @@ beforeAll(() => { }); afterAll(() => { - cleanup(DIR); + cleanupSync(DIR); }); test('shows up current config without unnecessary output', () => { diff --git a/__e2e__/default.test.ts b/__e2e__/default.test.ts index 31bb9a785..12292a603 100644 --- a/__e2e__/default.test.ts +++ b/__e2e__/default.test.ts @@ -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(() => { - cleanup(DIR); + cleanupSync(DIR); writeFiles(DIR, {}); }); afterEach(() => { - cleanup(DIR); + cleanupSync(DIR); }); test('shows up help information without passing in any args', () => { diff --git a/__e2e__/init.test.ts b/__e2e__/init.test.ts index e492377e4..cd7a4b635 100644 --- a/__e2e__/init.test.ts +++ b/__e2e__/init.test.ts @@ -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'); @@ -27,11 +32,11 @@ const customTemplateCopiedFiles = [ ]; beforeEach(() => { - cleanup(DIR); + cleanupSync(DIR); writeFiles(DIR, {}); }); afterEach(() => { - cleanup(DIR); + cleanupSync(DIR); }); test('init --template fails without package name', () => { diff --git a/__e2e__/install.test.ts b/__e2e__/install.test.ts index 9294af60d..7bd0a58c3 100644 --- a/__e2e__/install.test.ts +++ b/__e2e__/install.test.ts @@ -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); + cleanupSync(DIR); writeFiles(DIR, { 'node_modules/react-native/package.json': '{}', 'package.json': '{}', }); }); -afterEach(() => cleanup(DIR)); +afterEach(() => cleanupSync(DIR)); test.each(['yarn', 'npm'])('install module with %s', pm => { if (pm === 'yarn') { diff --git a/__e2e__/legacyInit.test.ts b/__e2e__/legacyInit.test.ts index 8282bfc8c..2a01d308b 100644 --- a/__e2e__/legacyInit.test.ts +++ b/__e2e__/legacyInit.test.ts @@ -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); + cleanupSync(DIR); writeFiles(DIR, {}); }); afterEach(() => { - cleanup(DIR); + cleanupSync(DIR); }); // We skip this test, because it's flaky and we don't really update diff --git a/__e2e__/root.test.ts b/__e2e__/root.test.ts index 2497ee641..b93acc5aa 100644 --- a/__e2e__/root.test.ts +++ b/__e2e__/root.test.ts @@ -4,7 +4,7 @@ import { spawnScript, runCLI, getTempDirectory, - cleanup, + cleanupSync, writeFiles, } from '../jest/helpers'; @@ -19,7 +19,7 @@ beforeAll(() => { } // Clean up folder and re-create a new project - cleanup(cwd); + cleanupSync(cwd); writeFiles(cwd, {}); // Initialise React Native project @@ -37,7 +37,7 @@ beforeAll(() => { }); afterAll(() => { - cleanup(cwd); + cleanupSync(cwd); }); test('works when Gradle is run outside of the project hierarchy', () => { diff --git a/__e2e__/uninstall.test.ts b/__e2e__/uninstall.test.ts index efcfdf6fd..60d5d5203 100644 --- a/__e2e__/uninstall.test.ts +++ b/__e2e__/uninstall.test.ts @@ -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); + cleanupSync(DIR); writeFiles(DIR, { 'node_modules/react-native/package.json': '{}', 'node_modules/react-native-config/package.json': '{}', @@ -15,7 +20,7 @@ beforeEach(() => { }`, }); }); -afterEach(() => cleanup(DIR)); +afterEach(() => cleanupSync(DIR)); test('uninstall fails when package is not defined', () => { writeFiles(DIR, { diff --git a/__e2e__/unknown.test.ts b/__e2e__/unknown.test.ts index 23d699c09..fc873eddc 100644 --- a/__e2e__/unknown.test.ts +++ b/__e2e__/unknown.test.ts @@ -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); + cleanupSync(DIR); writeFiles(DIR, {}); }); afterEach(() => { - cleanup(DIR); + cleanupSync(DIR); }); test('warn for passing in unknown commands', () => { diff --git a/jest.config.js b/jest.config.js index f64bc3341..b596ac162 100644 --- a/jest.config.js +++ b/jest.config.js @@ -9,7 +9,7 @@ module.exports = { ...common, displayName: 'e2e', setupFiles: ['/jest/setupE2eTests.js'], - testMatch: ['/**/__e2e__/*{.,-}test.[jt]s'], + testMatch: ['/__e2e__/*{.,-}test.[jt]s'], }, { ...common, diff --git a/jest/helpers.ts b/jest/helpers.ts index d949bd382..6defd6333 100644 --- a/jest/helpers.ts +++ b/jest/helpers.ts @@ -1,6 +1,7 @@ import fs from 'fs'; import os from 'os'; import path from 'path'; +import {promisify} from 'util'; import {createDirectory} from 'jest-util'; // @ts-ignore jsfile import rimraf from 'rimraf'; @@ -10,6 +11,8 @@ import slash from 'slash'; // @ts-ignore jsfile import {Writable} from 'readable-stream'; +const rimrafAsync = promisify(rimraf); + const CLI_PATH = path.resolve(__dirname, '../packages/cli/build/bin.js'); type RunOptions = { @@ -77,7 +80,13 @@ export const makeTemplate = ( return values[number - 1]; }); -export const cleanup = (directory: string) => rimraf.sync(directory); +export const cleanup = (directory: string) => { + return rimrafAsync(directory); +}; + +export const cleanupSync = (directory: string) => { + rimraf.sync(directory); +}; /** * Creates a nested directory with files and their contents @@ -189,7 +198,7 @@ function handleTestFailure( ) { if (!options.expectedFailure && result.code !== 0) { console.log(`Running ${cmd} command failed for unexpected reason. Here's more info: -${chalk.bold('cmd:')} ${cmd} +${chalk.bold('cmd:')} ${cmd} ${chalk.bold('options:')} ${JSON.stringify(options)} ${chalk.bold('args:')} ${(args || []).join(' ')} ${chalk.bold('stderr:')} ${result.stderr} diff --git a/packages/cli/src/commands/doctor/healthchecks/__tests__/androidSDK.test.ts b/packages/cli/src/commands/doctor/healthchecks/__tests__/androidSDK.test.ts index 9252a4f7e..3341825ac 100644 --- a/packages/cli/src/commands/doctor/healthchecks/__tests__/androidSDK.test.ts +++ b/packages/cli/src/commands/doctor/healthchecks/__tests__/androidSDK.test.ts @@ -38,7 +38,9 @@ describe('androidSDK', () => { }); }); - afterAll(() => cleanup(join(mockWorkingDir, 'android/build.gradle'))); + afterAll( + async () => await cleanup(join(mockWorkingDir, 'android/build.gradle')), + ); let environmentInfo: EnvironmentInfo; @@ -99,7 +101,7 @@ describe('androidSDK', () => { stdout: 'build-tools;28.0.3', }); - cleanup(join(mockWorkingDir, 'android/build.gradle')); + await cleanup(join(mockWorkingDir, 'android/build.gradle')); const diagnostics = await androidSDK.getDiagnostics(environmentInfo); expect(diagnostics.needsToBeFixed).toBe(true); diff --git a/packages/cli/src/tools/__tests__/copyFiles.test.ts b/packages/cli/src/tools/__tests__/copyFiles.test.ts index e60493e62..7b02fe612 100644 --- a/packages/cli/src/tools/__tests__/copyFiles.test.ts +++ b/packages/cli/src/tools/__tests__/copyFiles.test.ts @@ -6,13 +6,13 @@ import replacePathSepForRegex from '../replacePathSepForRegex'; const DIR = getTempDirectory('copyFiles-test'); -beforeEach(() => { - cleanup(DIR); +beforeEach(async () => { + await cleanup(DIR); fs.mkdirSync(DIR); }); -afterEach(() => { - cleanup(DIR); +afterEach(async () => { + await cleanup(DIR); }); test('copies text and binary files from source to destination', async () => { diff --git a/packages/cli/src/tools/config/__tests__/findDependencies-test.ts b/packages/cli/src/tools/config/__tests__/findDependencies-test.ts index 2062a20ad..27b10bdb0 100644 --- a/packages/cli/src/tools/config/__tests__/findDependencies-test.ts +++ b/packages/cli/src/tools/config/__tests__/findDependencies-test.ts @@ -7,12 +7,12 @@ import { jest.mock('../resolveNodeModuleDir'); -beforeEach(() => { - cleanup(DIR); +beforeEach(async () => { + await cleanup(DIR); jest.resetModules(); }); -afterEach(() => cleanup(DIR)); +afterEach(async () => await cleanup(DIR)); const DIR = getTempDirectory('find_dependencies_test'); diff --git a/packages/cli/src/tools/config/__tests__/findProjectRoot-test.ts b/packages/cli/src/tools/config/__tests__/findProjectRoot-test.ts index 4504a2bfb..a1c8ad4e2 100644 --- a/packages/cli/src/tools/config/__tests__/findProjectRoot-test.ts +++ b/packages/cli/src/tools/config/__tests__/findProjectRoot-test.ts @@ -6,12 +6,12 @@ import { getTempDirectory, } from '../../../../../../jest/helpers'; -beforeEach(() => { - cleanup(DIR); +beforeEach(async () => { + await cleanup(DIR); jest.resetModules(); }); -afterEach(() => cleanup(DIR)); +afterEach(async () => await cleanup(DIR)); const DIR = getTempDirectory('find_project_root_test'); diff --git a/packages/cli/src/tools/config/__tests__/index-test.ts b/packages/cli/src/tools/config/__tests__/index-test.ts index 2fb0cec8c..20ea25d16 100644 --- a/packages/cli/src/tools/config/__tests__/index-test.ts +++ b/packages/cli/src/tools/config/__tests__/index-test.ts @@ -51,13 +51,13 @@ const removeString = (config, str) => ), ); -beforeEach(() => { - cleanup(DIR); +beforeEach(async () => { + await cleanup(DIR); jest.resetModules(); jest.clearAllMocks(); }); -afterEach(() => cleanup(DIR)); +afterEach(async () => await cleanup(DIR)); test('should have a valid structure by default', () => { writeFiles(DIR, {