From c9957458e64ece05986bc92b4b3560bb25c52bb6 Mon Sep 17 00:00:00 2001 From: Matthew Espino <65783406+mcecode@users.noreply.github.com> Date: Wed, 28 Jul 2021 02:50:07 +0800 Subject: [PATCH 1/6] Update reset-cache command --- lib/cli.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index 2985b1f49..afe654ce3 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -1,3 +1,4 @@ +import fsPromises from 'fs/promises'; import {createRequire} from 'module'; import path from 'path'; @@ -244,18 +245,21 @@ export default async () => { // eslint-disable-line complexity const {nonSemVerExperiments: experiments, projectDir} = conf; if (resetCache) { const cacheDir = path.join(projectDir, 'node_modules', '.cache', 'ava'); + try { - await del('*', { - cwd: cacheDir, - nodir: true - }); - console.error(`\n${chalk.green(figures.tick)} Removed AVA cache files in ${cacheDir}`); + await fsPromises.access(cacheDir); + } catch { + console.log(`\n${chalk.green(figures.tick)} No cache files to remove`); + process.exit(0); // eslint-disable-line unicorn/no-process-exit + } + + try { + await del('*', {cwd: cacheDir}); + console.log(`\n${chalk.green(figures.tick)} Removed AVA cache files in ${cacheDir}`); process.exit(0); // eslint-disable-line unicorn/no-process-exit } catch (error) { exit(`Error removing AVA cache files in ${cacheDir}\n\n${chalk.gray((error && error.stack) || error)}`); } - - return; } if (argv.watch) { From 5feb035c7a3cf65675ff8da3577430936672069b Mon Sep 17 00:00:00 2001 From: Matthew Espino <65783406+mcecode@users.noreply.github.com> Date: Wed, 28 Jul 2021 03:09:11 +0800 Subject: [PATCH 2/6] Update docs about caching --- docs/05-command-line.md | 4 ++-- docs/06-configuration.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/05-command-line.md b/docs/05-command-line.md index a8e8cc413..2a0c99ab7 100644 --- a/docs/05-command-line.md +++ b/docs/05-command-line.md @@ -218,13 +218,13 @@ When running a file with and without line numbers, line numbers take precedence. ## Resetting AVA's cache -AVA may cache certain files, especially when you use our [`@ava/babel`](https://github.com/avajs/babel) provider. If it seems like your latest changes aren't being picked up by AVA you can reset the cache by running: +AVA itself does not cache files unless used with our [`@ava/babel`](https://github.com/avajs/babel) provider. However, if it seems like your latest changes aren't being picked up by AVA you can try resetting the cache by running: ```console npx ava reset-cache ``` -This deletes all files in the `node_modules/.cache/ava` directory. +This notifies you if cache files within the `node_modules/.cache/ava` directory are deleted or if there are no cache files to be deleted. ## Reporters diff --git a/docs/06-configuration.md b/docs/06-configuration.md index 63f20aed6..4c36c03ad 100644 --- a/docs/06-configuration.md +++ b/docs/06-configuration.md @@ -45,7 +45,7 @@ Arguments passed to the CLI will always take precedence over the CLI options con - `files`: an array of glob patterns to select test files. Files with an underscore prefix are ignored. By default only selects files with `cjs`, `mjs` & `js` extensions, even if the pattern matches other files. Specify `extensions` to allow other file extensions - `ignoredByWatcher`: an array of glob patterns to match files that, even if changed, are ignored by the watcher. See the [watch mode recipe for details](https://github.com/avajs/ava/blob/main/docs/recipes/watch-mode.md) - `match`: not typically useful in the `package.json` configuration, but equivalent to [specifying `--match` on the CLI](./05-command-line.md#running-tests-with-matching-titles) -- `cache`: cache compiled files under `node_modules/.cache/ava`. If `false`, files are cached in a temporary directory instead +- `cache`: a boolean value on whether to cache compiled files under `node_modules/.cache/ava`. If `false`, files are cached in a temporary directory instead - `concurrency`: max number of test files running at the same time (default: CPU cores) - `workerThreads`: use worker threads to run tests (requires AVA 4, enabled by default). If `false`, tests will run in child processes (how AVA 3 behaves) - `failFast`: stop running further tests once a test fails From c40d6312637b91332610923c558c9db33da51e32 Mon Sep 17 00:00:00 2001 From: Matthew Espino <65783406+mcecode@users.noreply.github.com> Date: Mon, 9 Aug 2021 01:06:25 +0800 Subject: [PATCH 3/6] Update cache check --- lib/cli.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index afe654ce3..39983822e 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -1,4 +1,3 @@ -import fsPromises from 'fs/promises'; import {createRequire} from 'module'; import path from 'path'; @@ -247,15 +246,14 @@ export default async () => { // eslint-disable-line complexity const cacheDir = path.join(projectDir, 'node_modules', '.cache', 'ava'); try { - await fsPromises.access(cacheDir); - } catch { - console.log(`\n${chalk.green(figures.tick)} No cache files to remove`); - process.exit(0); // eslint-disable-line unicorn/no-process-exit - } + const deletedFilePaths = await del('*', {cwd: cacheDir}); + + if (deletedFilePaths.length === 0) { + console.log(`\n${chalk.green(figures.tick)} No cache files to remove`); + } else { + console.log(`\n${chalk.green(figures.tick)} Removed AVA cache files in ${cacheDir}`); + } - try { - await del('*', {cwd: cacheDir}); - console.log(`\n${chalk.green(figures.tick)} Removed AVA cache files in ${cacheDir}`); process.exit(0); // eslint-disable-line unicorn/no-process-exit } catch (error) { exit(`Error removing AVA cache files in ${cacheDir}\n\n${chalk.gray((error && error.stack) || error)}`); From 69bac609f7cd95bcfccd72d41eebe18308e27fbb Mon Sep 17 00:00:00 2001 From: Matthew Espino <65783406+mcecode@users.noreply.github.com> Date: Mon, 9 Aug 2021 01:13:18 +0800 Subject: [PATCH 4/6] Revert part of docs changes --- docs/05-command-line.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/05-command-line.md b/docs/05-command-line.md index 2a0c99ab7..9dc4bcd98 100644 --- a/docs/05-command-line.md +++ b/docs/05-command-line.md @@ -224,7 +224,7 @@ AVA itself does not cache files unless used with our [`@ava/babel`](https://gith npx ava reset-cache ``` -This notifies you if cache files within the `node_modules/.cache/ava` directory are deleted or if there are no cache files to be deleted. +This deletes all files in the `node_modules/.cache/ava` directory. ## Reporters From dcdae28b79b315258c787832c9c01c909d344690 Mon Sep 17 00:00:00 2001 From: Matthew Espino <65783406+mcecode@users.noreply.github.com> Date: Mon, 9 Aug 2021 01:15:18 +0800 Subject: [PATCH 5/6] Remove unneeded however Co-authored-by: Mark Wubben --- docs/05-command-line.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/05-command-line.md b/docs/05-command-line.md index 9dc4bcd98..bd002f0fd 100644 --- a/docs/05-command-line.md +++ b/docs/05-command-line.md @@ -218,7 +218,7 @@ When running a file with and without line numbers, line numbers take precedence. ## Resetting AVA's cache -AVA itself does not cache files unless used with our [`@ava/babel`](https://github.com/avajs/babel) provider. However, if it seems like your latest changes aren't being picked up by AVA you can try resetting the cache by running: +AVA itself does not cache files unless used with our [`@ava/babel`](https://github.com/avajs/babel) provider. If it seems like your latest changes aren't being picked up by AVA you can try resetting the cache by running: ```console npx ava reset-cache From cc1f22f3ec6c1063c5962e95cf2fdb9bbbae42cd Mon Sep 17 00:00:00 2001 From: Matthew Espino <65783406+mcecode@users.noreply.github.com> Date: Mon, 9 Aug 2021 01:18:15 +0800 Subject: [PATCH 6/6] State more clearly that `cache` value is boolean Co-authored-by: Mark Wubben --- docs/06-configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/06-configuration.md b/docs/06-configuration.md index 4c36c03ad..dce63e608 100644 --- a/docs/06-configuration.md +++ b/docs/06-configuration.md @@ -45,7 +45,7 @@ Arguments passed to the CLI will always take precedence over the CLI options con - `files`: an array of glob patterns to select test files. Files with an underscore prefix are ignored. By default only selects files with `cjs`, `mjs` & `js` extensions, even if the pattern matches other files. Specify `extensions` to allow other file extensions - `ignoredByWatcher`: an array of glob patterns to match files that, even if changed, are ignored by the watcher. See the [watch mode recipe for details](https://github.com/avajs/ava/blob/main/docs/recipes/watch-mode.md) - `match`: not typically useful in the `package.json` configuration, but equivalent to [specifying `--match` on the CLI](./05-command-line.md#running-tests-with-matching-titles) -- `cache`: a boolean value on whether to cache compiled files under `node_modules/.cache/ava`. If `false`, files are cached in a temporary directory instead +- `cache`: defaults to `true` to cache compiled files under `node_modules/.cache/ava`. If `false`, files are cached in a temporary directory instead - `concurrency`: max number of test files running at the same time (default: CPU cores) - `workerThreads`: use worker threads to run tests (requires AVA 4, enabled by default). If `false`, tests will run in child processes (how AVA 3 behaves) - `failFast`: stop running further tests once a test fails