Skip to content

Commit

Permalink
fix: remove usage of rimraf (#2141)
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonrybczak authored Oct 30, 2023
1 parent dc9ef03 commit 8e068ce
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 73 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,
cleanupSync,
cleanup,
writeFiles,
spawnScript,
replaceProjectRootInOutput,
Expand Down Expand Up @@ -44,7 +44,7 @@ beforeAll(() => {
}

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

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

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

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

const DIR = getTempDirectory('test_default_behavior');

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

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

const DIR = getTempDirectory('command-init');
Expand Down Expand Up @@ -34,11 +29,11 @@ const customTemplateCopiedFiles = [
];

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

let templatePath = path.resolve(DIR, 'custom', 'template');
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,
cleanupSync,
cleanup,
writeFiles,
} from '../jest/helpers';

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

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

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

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

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

const DIR = getTempDirectory('test_unknown');

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

test('warn for passing in unknown commands', () => {
Expand Down
10 changes: 1 addition & 9 deletions jest/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import fs from 'fs';
import os from 'os';
import path from 'path';
import {promisify} from 'util';
import {createDirectory} from 'jest-util';
import rimraf from 'rimraf';
import execa from 'execa';
import chalk from 'chalk';
import slash from 'slash';
import {Writable} from 'readable-stream';

const rimrafAsync = promisify(rimraf);

const CLI_PATH = path.resolve(__dirname, '../packages/cli/build/bin.js');

type RunOptions = {
Expand Down Expand Up @@ -79,11 +75,7 @@ export const makeTemplate =
});

export const cleanup = (directory: string) => {
return rimrafAsync(directory);
};

export const cleanupSync = (directory: string) => {
rimraf.sync(directory);
fs.rmSync(directory, {recursive: true, force: true});
};

/**
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,15 @@
"@types/node": "^18.0.0",
"@types/node-fetch": "^2.3.7",
"@types/readable-stream": "^2.3.0",
"@types/rimraf": "^3.0.2",
"babel-jest": "^26.6.2",
"babel-plugin-module-resolver": "^3.2.0",
"chalk": "^4.1.2",
"chokidar": "^3.3.1",
"eslint": "^8.23.1",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-ft-flow": "^2.0.1",
"prettier": "2.8.8",
"eslint-plugin-import": "^2.25.3",
"execa": "^5.0.0",
"glob": "^7.1.3",
"husky": "^8.0.2",
Expand All @@ -55,7 +53,7 @@
"lint-staged": "^13.1.0",
"metro-memory-fs": "0.78.0",
"micromatch": "^4.0.4",
"rimraf": "^3.0.2",
"prettier": "2.8.8",
"slash": "^3.0.0",
"string-length": "^2.0.0",
"typescript": "^5.2.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/cli-config/src/__tests__/findDependencies-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import findDependencies from '../findDependencies';
import {cleanup, writeFiles, getTempDirectory} from '../../../../jest/helpers';

beforeEach(async () => {
await cleanup(DIR);
cleanup(DIR);
jest.resetModules();
});

afterEach(async () => await cleanup(DIR));
afterEach(() => cleanup(DIR));

const DIR = getTempDirectory('find_dependencies_test');

Expand Down
4 changes: 2 additions & 2 deletions packages/cli-config/src/__tests__/index-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ const removeString = (config, str) =>
);

beforeEach(async () => {
await cleanup(DIR);
cleanup(DIR);
jest.resetModules();
jest.clearAllMocks();
});

afterEach(async () => await cleanup(DIR));
afterEach(() => cleanup(DIR));

test('should have a valid structure by default', () => {
DIR = getTempDirectory('config_test_structure');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ describe('androidSDK', () => {
});
});

afterAll(
async () => await cleanup(join(mockWorkingDir, 'android/build.gradle')),
);
afterAll(async () => cleanup(join(mockWorkingDir, 'android/build.gradle')));

let environmentInfo: EnvironmentInfo;

Expand Down Expand Up @@ -175,7 +173,7 @@ describe('androidSDK', () => {
stdout: 'build-tools;28.0.3',
});

await cleanup(join(mockWorkingDir, 'android/build.gradle'));
cleanup(join(mockWorkingDir, 'android/build.gradle'));

const diagnostics = await androidSDK.getDiagnostics(environmentInfo);
expect(diagnostics.needsToBeFixed).toBe(true);
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-platform-ios/src/__tests__/pods.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const createTempFiles = (rest?: Record<string, string>) => {
};

beforeEach(async () => {
await cleanup(DIR);
cleanup(DIR);
jest.resetAllMocks();
});

Expand Down
4 changes: 2 additions & 2 deletions packages/cli-tools/src/__tests__/findProjectRoot-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import findProjectRoot from '../findProjectRoot';
import {cleanup, writeFiles, getTempDirectory} from '../../../../jest/helpers';

beforeEach(async () => {
await cleanup(DIR);
cleanup(DIR);
jest.resetModules();
});

afterEach(async () => await cleanup(DIR));
afterEach(() => cleanup(DIR));

const DIR = getTempDirectory('find_project_root_test');

Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/tools/__tests__/copyFiles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import replacePathSepForRegex from '../replacePathSepForRegex';
const DIR = getTempDirectory('copyFiles-test');

beforeEach(async () => {
await cleanup(DIR);
cleanup(DIR);
fs.mkdirSync(DIR);
});

afterEach(async () => {
await cleanup(DIR);
afterEach(() => {
cleanup(DIR);
});

test('copies text and binary files from source to destination', async () => {
Expand Down
19 changes: 3 additions & 16 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2243,14 +2243,6 @@
dependencies:
"@types/node" "*"

"@types/glob@*":
version "8.0.0"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-8.0.0.tgz#321607e9cbaec54f687a0792b2d1d370739455d2"
integrity sha512-l6NQsDDyQUVeoTynNpC9uRvCUint/gSUXQA2euwmTuWGvPY5LSDUu6tkCtJB2SvGQlJQzLaKqcGZP4//7EDveA==
dependencies:
"@types/minimatch" "*"
"@types/node" "*"

"@types/glob@^7.1.1":
version "7.1.1"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.1.tgz#aa59a1c6e3fbc421e07ccd31a944c30eba521575"
Expand Down Expand Up @@ -2408,14 +2400,6 @@
"@types/node" "*"
safe-buffer "~5.1.1"

"@types/rimraf@^3.0.2":
version "3.0.2"
resolved "https://registry.yarnpkg.com/@types/rimraf/-/rimraf-3.0.2.tgz#a63d175b331748e5220ad48c901d7bbf1f44eef8"
integrity sha512-F3OznnSLAUxFrCEu/L5PY8+ny8DtcFRjx7fZZ9bycvXRi3KPTRS9HOitGZwvPg0juRhXFWIeKX58cnX5YqLohQ==
dependencies:
"@types/glob" "*"
"@types/node" "*"

"@types/semver@^6.0.2":
version "6.2.1"
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-6.2.1.tgz#a236185670a7860f1597cf73bea2e16d001461ba"
Expand Down Expand Up @@ -11843,6 +11827,7 @@ string-natural-compare@^3.0.1:
integrity sha512-n3sPwynL1nwKi3WJ6AIsClwBMa0zTi54fn2oLU6ndfTSIO05xaznjSf15PcBZU6FNWbmN5Q6cxT4V5hGvB4taw==

"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
name string-width-cjs
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down Expand Up @@ -11942,6 +11927,7 @@ string_decoder@~1.1.1:
safe-buffer "~5.1.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
name strip-ansi-cjs
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down Expand Up @@ -13049,6 +13035,7 @@ wordwrap@^1.0.0:
integrity sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
name wrap-ansi-cjs
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand Down

0 comments on commit 8e068ce

Please sign in to comment.