Skip to content
Merged
Show file tree
Hide file tree
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
Next Next commit
fix integration test
- actually create directory with real test
- check for directory, then delete
- use rimraf.sync
- remove temp var
  • Loading branch information
tabrindle committed Oct 11, 2017
commit 613feca79ec67fc83b0a1a50bbb7c90de092e24b
19 changes: 8 additions & 11 deletions integration_tests/__tests__/clear_cache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,23 @@
const fs = require('fs');
const os = require('os');
const path = require('path');
const {cleanup, writeFiles} = require('../utils');
const runJest = require('../runJest');
const skipOnWindows = require('../../scripts/skip_on_windows');
const rimraf = require('rimraf');

const CACHE = path.resolve(os.tmpdir(), 'clear_cache_directory');
const DIR = path.resolve(os.tmpdir(), 'clear_cache');

skipOnWindows.suite();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Necessary, or copypasta? (Just asking, fine if needed 😄)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

skipOnWindows? I assumed it was part of the test convention as I saw it everywhere. I can remove it if it isn't necessary.


beforeEach(() => cleanup(DIR));
afterAll(() => cleanup(DIR));

describe('jest --clearCache', () => {
test('clearing cache results in exit status 0', () => {
writeFiles(DIR, {
'.watchmanconfig': '',
'package.json': '{}',
});
test('normal run results in cache directory being written', () => {
const {status} = runJest('clear_cache', [`--cacheDirectory=${CACHE}`]);

const {status, stdout, stderr} = runJest(DIR, [
expect(fs.existsSync(CACHE)).toBe(true);
expect(status).toBe(0);
});
test('clearCache results in deleted directory and exit status 0', () => {
const {status, stdout, stderr} = runJest('clear_cache', [
'--clearCache',
`--cacheDirectory=${CACHE}`,
]);
Expand Down
10 changes: 10 additions & 0 deletions integration_tests/clear_cache/__tests__/clear_cache.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';

test('stub', () => expect(1).toBe(1));
5 changes: 5 additions & 0 deletions integration_tests/clear_cache/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"jest": {
"testEnvironment": "node"
}
}
11 changes: 1 addition & 10 deletions packages/jest-cli/src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,11 @@ export const runCLI = async (
);

if (argv.clearCache) {
let clearCacheError;

configs.map(config => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forEach over map. (You ignore the return value anyways)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually prefer map to prevent accidental mutation. I suppose here it doesn't matter as the process is about to end. I will defer to you on this.

rimraf(config.cacheDirectory, [], () => {
clearCacheError = true;
process.stderr.write(`Unable to clear ${config.cacheDirectory}\n`);
});
rimraf.sync(config.cacheDirectory);
process.stdout.write(`Cleared ${config.cacheDirectory}\n`);
});

if (clearCacheError) {
process.exit(1);
}

process.exit(0);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to clear the cache for certain project or all projects, right now it's only for the first one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure how this worked: should I just map over the configs array?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, should be fine


Expand Down