Skip to content

Commit

Permalink
Remove unnecessary guards, match existing log output
Browse files Browse the repository at this point in the history
  • Loading branch information
novemberborn committed May 21, 2023
1 parent bde891f commit 9f2c8c6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
23 changes: 18 additions & 5 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Check warning on line 273 in lib/cli.js

View check run for this annotation

Codecov / codecov/patch

lib/cli.js#L268-L273

Added lines #L268 - L273 were not covered by tests

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
Expand Down
10 changes: 2 additions & 8 deletions test-tap/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 9f2c8c6

Please sign in to comment.