Skip to content

Commit

Permalink
fix integration test
Browse files Browse the repository at this point in the history
- 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
1 parent a4b9ea6 commit 613feca
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
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();

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 => {
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);
}

Expand Down

0 comments on commit 613feca

Please sign in to comment.