Skip to content

Commit 953dd8e

Browse files
committed
fix integration test
- actually create directory with real test - check for directory, then delete - use rimraf.sync - remove temp var
1 parent 51a66ee commit 953dd8e

4 files changed

Lines changed: 24 additions & 21 deletions

File tree

integration_tests/__tests__/clear_cache.test.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,23 @@
1212
const fs = require('fs');
1313
const os = require('os');
1414
const path = require('path');
15-
const {cleanup, writeFiles} = require('../utils');
1615
const runJest = require('../runJest');
1716
const skipOnWindows = require('../../scripts/skip_on_windows');
17+
const rimraf = require('rimraf');
1818

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

2221
skipOnWindows.suite();
2322

24-
beforeEach(() => cleanup(DIR));
25-
afterAll(() => cleanup(DIR));
26-
2723
describe('jest --clearCache', () => {
28-
test('clearing cache results in exit status 0', () => {
29-
writeFiles(DIR, {
30-
'.watchmanconfig': '',
31-
'package.json': '{}',
32-
});
24+
test('normal run results in cache directory being written', () => {
25+
const {status} = runJest('clear_cache', [`--cacheDirectory=${CACHE}`]);
3326

34-
const {status, stdout, stderr} = runJest(DIR, [
27+
expect(fs.existsSync(CACHE)).toBe(true);
28+
expect(status).toBe(0);
29+
});
30+
test('clearCache results in deleted directory and exit status 0', () => {
31+
const {status, stdout, stderr} = runJest('clear_cache', [
3532
'--clearCache',
3633
`--cacheDirectory=${CACHE}`,
3734
]);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
3+
*
4+
* This source code is licensed under the BSD-style license found in the
5+
* LICENSE file in the root directory of this source tree. An additional grant
6+
* of patent rights can be found in the PATENTS file in the same directory.
7+
*/
8+
'use strict';
9+
10+
test('stub', () => expect(1).toBe(1));
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"jest": {
3+
"testEnvironment": "node"
4+
}
5+
}

packages/jest-cli/src/cli/index.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,11 @@ const runCLI = async (
6969
);
7070

7171
if (argv.clearCache) {
72-
let clearCacheError;
73-
7472
configs.map(config => {
75-
rimraf(config.cacheDirectory, [], () => {
76-
clearCacheError = true;
77-
process.stderr.write(`Unable to clear ${config.cacheDirectory}\n`);
78-
});
73+
rimraf.sync(config.cacheDirectory);
7974
process.stdout.write(`Cleared ${config.cacheDirectory}\n`);
8075
});
8176

82-
if (clearCacheError) {
83-
process.exit(1);
84-
}
85-
8677
process.exit(0);
8778
}
8879

0 commit comments

Comments
 (0)