Skip to content

Commit

Permalink
Remove all usage of jest-file-exists. (#3101)
Browse files Browse the repository at this point in the history
  • Loading branch information
wtgtybhertgeghgtwtg authored and cpojer committed Mar 8, 2017
1 parent 7e2ca96 commit 5c82046
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 17 deletions.
1 change: 0 additions & 1 deletion packages/jest-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"convert-source-map": "^1.3.0",
"graceful-fs": "^4.1.6",
"jest-config": "^19.0.2",
"jest-file-exists": "^19.0.0",
"jest-haste-map": "^19.0.0",
"jest-regex-util": "^19.0.0",
"jest-resolve": "^19.0.2",
Expand Down
3 changes: 1 addition & 2 deletions packages/jest-runtime/src/__tests__/transform-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const slash = require('slash');

jest
.mock('graceful-fs')
.mock('jest-file-exists')
.mock('jest-haste-map', () => ({
getCacheFilePath: (cacheDir, baseDir, version) => cacheDir + baseDir,
}))
Expand Down Expand Up @@ -131,7 +130,7 @@ describe('transform', () => {
mtime: {getTime: () => 42},
}));

require('jest-file-exists').mockImplementation(path => !!mockFs[path]);
fs.existsSync = jest.fn(path => !!mockFs[path]);

config = {
cache: true,
Expand Down
3 changes: 1 addition & 2 deletions packages/jest-runtime/src/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import type {
} from 'types/Transform';
const createDirectory = require('jest-util').createDirectory;
const crypto = require('crypto');
const fileExists = require('jest-file-exists');
const fs = require('graceful-fs');
const getCacheFilePath = require('jest-haste-map').getCacheFilePath;
const path = require('path');
Expand Down Expand Up @@ -111,7 +110,7 @@ const wrap = content =>
'\n}});';

const readCacheFile = (filename: Path, cachePath: Path): ?string => {
if (!fileExists(cachePath)) {
if (!fs.existsSync(cachePath)) {
return null;
}

Expand Down
1 change: 0 additions & 1 deletion packages/jest-snapshot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"dependencies": {
"chalk": "^1.1.3",
"jest-diff": "^19.0.0",
"jest-file-exists": "^19.0.0",
"jest-matcher-utils": "^19.0.0",
"jest-util": "^19.0.2",
"natural-compare": "^1.4.0",
Expand Down
5 changes: 2 additions & 3 deletions packages/jest-snapshot/src/State.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const {
testNameToKey,
unescape,
} = require('./utils');
const fileExists = require('jest-file-exists');
const fs = require('fs');

class SnapshotState {
Expand Down Expand Up @@ -87,7 +86,7 @@ class SnapshotState {
if ((this._dirty || this._uncheckedKeys.size) && !isEmpty) {
saveSnapshotFile(this._snapshotData, this._snapshotPath);
status.saved = true;
} else if (isEmpty && fileExists(this._snapshotPath)) {
} else if (isEmpty && fs.existsSync(this._snapshotPath)) {
if (update) {
fs.unlinkSync(this._snapshotPath);
}
Expand Down Expand Up @@ -135,7 +134,7 @@ class SnapshotState {
}

if (
!fileExists(this._snapshotPath) || // there's no snapshot file
!fs.existsSync(this._snapshotPath) || // there's no snapshot file
(hasSnapshot && this.update) || // there is a file, but we're updating
!hasSnapshot // there is a file, but it doesn't have this snaphsot
) {
Expand Down
5 changes: 3 additions & 2 deletions packages/jest-snapshot/src/__tests__/utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@ const path = require('path');

const writeFileSync = fs.writeFileSync;
const readFileSync = fs.readFileSync;
const existsSync = fs.existsSync;
beforeEach(() => {
fs.writeFileSync = jest.fn();
fs.readFileSync = jest.fn();
fs.existsSync = jest.fn(() => true);
});
afterEach(() => {
fs.writeFileSync = writeFileSync;
fs.readFileSync = readFileSync;
fs.existsSync = existsSync;
});

jest.mock('jest-file-exists', () => () => true);

test('keyToTestName()', () => {
expect(keyToTestName('abc cde 12')).toBe('abc cde');
expect(keyToTestName('abc cde 12')).toBe('abc cde ');
Expand Down
4 changes: 3 additions & 1 deletion packages/jest-snapshot/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import type {HasteFS} from 'types/HasteMap';
import type {Path} from 'types/Config';

const diff = require('jest-diff');
const fileExists = require('jest-file-exists');
const fs = require('fs');
const path = require('path');
const SnapshotState = require('./State');
Expand All @@ -27,6 +26,9 @@ const {
} = require('jest-matcher-utils');
const {SNAPSHOT_EXTENSION} = require('./utils');

const fileExists = (filePath: Path, hasteFS: HasteFS): boolean =>
hasteFS.exists(filePath) || fs.existsSync(filePath);

const cleanup = (hasteFS: HasteFS, update: boolean) => {
const pattern = '\\.' + SNAPSHOT_EXTENSION + '$';
const files = hasteFS.matchFiles(pattern);
Expand Down
3 changes: 1 addition & 2 deletions packages/jest-snapshot/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import type {Path} from 'types/Config';

const chalk = require('chalk');
const createDirectory = require('jest-util').createDirectory;
const fileExists = require('jest-file-exists');
const path = require('path');
const prettyFormat = require('pretty-format');
const fs = require('fs');
Expand Down Expand Up @@ -103,7 +102,7 @@ const getSnapshotData = (snapshotPath: Path, update: boolean) => {
let snapshotContents = '';
let dirty = false;

if (fileExists(snapshotPath)) {
if (fs.existsSync(snapshotPath)) {
try {
snapshotContents = fs.readFileSync(snapshotPath, 'utf8');
// eslint-disable-next-line no-new-func
Expand Down
1 change: 0 additions & 1 deletion packages/jest-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"dependencies": {
"chalk": "^1.1.1",
"graceful-fs": "^4.1.6",
"jest-file-exists": "^19.0.0",
"jest-mock": "^19.0.0",
"jest-validate": "^19.0.2",
"jest-message-util": "^19.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-util/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ const FakeTimers = require('./FakeTimers');
const NullConsole = require('./NullConsole');

const clearLine = require('./clearLine');
const fileExists = require('jest-file-exists');
const formatTestResults = require('./formatTestResults');
const installCommonGlobals = require('./installCommonGlobals');
const mkdirp = require('mkdirp');
const path = require('path');
const fs = require('fs');
const setGlobal = require('./setGlobal');
const validateCLIOptions = require('./validateCLIOptions');

Expand All @@ -38,7 +38,7 @@ const getPackageRoot = () => {

// Is the cwd somewhere within an npm package?
let root = cwd;
while (!fileExists(path.join(root, 'package.json'))) {
while (!fs.existsSync(path.join(root, 'package.json'))) {
if (root === '/' || root.match(/^[A-Z]:\\/)) {
root = cwd;
break;
Expand Down

0 comments on commit 5c82046

Please sign in to comment.