Skip to content

Commit

Permalink
Implement --reset-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
novemberborn committed May 20, 2018
1 parent 8c9c474 commit ebb3948
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
22 changes: 21 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
const path = require('path');
const del = require('del');
const updateNotifier = require('update-notifier');
const figures = require('figures');
const arrify = require('arrify');
Expand Down Expand Up @@ -38,6 +39,7 @@ exports.run = () => { // eslint-disable-line complexity
--tap, -t Generate TAP output
--color Force color output
--no-color Disable color output
--reset-cache Reset AVA's compilation cache and exit
Examples
ava
Expand Down Expand Up @@ -95,14 +97,32 @@ exports.run = () => { // eslint-disable-line complexity
type: 'boolean',
default: 'color' in conf ? conf.color : require('supports-color').stdout !== false
},
'reset-cache': {
type: 'boolean',
default: false
},
'--': {
type: 'string'
}
}
});

updateNotifier({pkg: cli.pkg}).notify();
require('./chalk').set({enabled: cli.flags.color});
const chalk = require('./chalk').set({enabled: cli.flags.color});

if (cli.flags.resetCache) {
const cacheDir = path.join(projectDir, 'node_modules', '.cache', 'ava');
del('*', {
cwd: cacheDir,
nodir: true
}).then(() => {
console.error(`\n${chalk.green(figures.tick)} Removed AVA cache files in ${cacheDir}`);
process.exit(0); // eslint-disable-line unicorn/no-process-exit
}, err => {
exit(`Error removing AVA cache files in ${cacheDir}\n\n${chalk.gray((err && err.stack) || err)}`);
});
return;
}

if (cli.flags.watch && cli.flags.tap && !conf.tap) {
exit('The TAP reporter is not available when using watch mode.');
Expand Down
14 changes: 14 additions & 0 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -836,3 +836,17 @@ test('additional arguments are forwarded to the worker', t => {
t.end();
});
});

test('--reset-cache resets cache', t => {
const cacheDir = path.join(__dirname, 'fixture', 'reset-cache', 'node_modules', '.cache', 'ava');
execCli([], {dirname: 'fixture/reset-cache'}, err => {
t.ifError(err);
t.true(fs.readdirSync(cacheDir).length > 0);

execCli(['--reset-cache'], {dirname: 'fixture/reset-cache'}, err => {
t.ifError(err);
t.true(fs.readdirSync(cacheDir).length === 0);
t.end();
});
});
});
1 change: 1 addition & 0 deletions test/fixture/reset-cache/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 3 additions & 0 deletions test/fixture/reset-cache/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import test from '../../..';

test('pass', t => t.pass());

0 comments on commit ebb3948

Please sign in to comment.