Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Replace 'del' dependency by built-in recursive fs.rm #3198

Merged
merged 2 commits into from
May 24, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Remove unnecessary guards, match existing log output
novemberborn committed May 21, 2023

Verified

This commit was signed with the committer’s verified signature.
novemberborn Mark Wubben
commit 9f2c8c6c1ba9726073e054a04345f36c741967e5
23 changes: 18 additions & 5 deletions lib/cli.js
Original file line number Diff line number Diff line change
@@ -261,12 +261,25 @@ export default async function loadCli() { // eslint-disable-line complexity
if (resetCache) {
const cacheDir = path.join(projectDir, 'node_modules', '.cache', 'ava');
try {
if (fs.existsSync(cacheDir)) {
fs.rmSync(cacheDir, {recursive: true, force: true});
fs.mkdirSync(cacheDir);
console.log(`\n${chalk.green(figures.tick)} Emptied AVA cache cache directory ${cacheDir}`);
let entries;
try {
entries = fs.readdirSync(cacheDir);
} catch (error) {
if (error.code === 'ENOENT') {
entries = [];
} else {
throw error;
}
}

for (const entry of entries) {
fs.rmSync(path.join(cacheDir, entry), {recursive: true, force: true});
}

if (entries.length === 0) {
console.log(`\n${chalk.green(figures.tick)} No cache files to remove`);
} else {
console.log(`\n${chalk.green(figures.tick)} No cache directory to remove`);
console.log(`\n${chalk.green(figures.tick)} Removed AVA cache files in ${cacheDir}`);
}

process.exit(0); // eslint-disable-line unicorn/no-process-exit
10 changes: 2 additions & 8 deletions test-tap/api.js
Original file line number Diff line number Diff line change
@@ -379,10 +379,7 @@ for (const opt of options) {
});

test(`caching is enabled by default - workerThreads: ${opt.workerThreads}`, async t => {
const nodeModulesPath = path.join(__dirname, 'fixture/caching/node_modules');
if (fs.existsSync(nodeModulesPath)) {
fs.rmSync(nodeModulesPath, {recursive: true, force: true});
}
fs.rmSync(path.join(__dirname, 'fixture/caching/node_modules'), {recursive: true, force: true});

const api = await apiCreator({
...opt,
@@ -402,10 +399,7 @@ for (const opt of options) {
});

test(`caching can be disabled - workerThreads: ${opt.workerThreads}`, async t => {
const nodeModulesPath = path.join(__dirname, 'fixture/caching/node_modules');
if (fs.existsSync(nodeModulesPath)) {
fs.rmSync(nodeModulesPath, {recursive: true, force: true});
}
fs.rmSync(path.join(__dirname, 'fixture/caching/node_modules'), {recursive: true, force: true});

const api = await apiCreator({
...opt,