Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use graceful-fs all over instead of monkey patching fs #9443

Merged
merged 13 commits into from Apr 28, 2020
7 changes: 7 additions & 0 deletions .eslintrc.js
Expand Up @@ -142,6 +142,13 @@ module.exports = {
// https://github.com/benmosher/eslint-plugin-import/issues/645
'import/order': 0,
'no-console': 0,
'no-restricted-imports': [
2,
{
message: 'Please use graceful-fs instead.',
name: 'fs',
},
],
'no-unused-vars': 2,
'prettier/prettier': 2,
'sort-imports': [2, {ignoreDeclarationSort: true}],
Expand Down
5 changes: 1 addition & 4 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,7 @@

### Fixes

- `[*]` Use `graceful-fs` directly in every package instead of relying on `fs` being monkey patched ([#9443](https://github.com/facebook/jest/pull/9443))
- `[expect]` Prints the Symbol name into the error message with a custom asymmetric matcher ([#9888](https://github.com/facebook/jest/pull/9888))
- `[jest-circus, jest-jasmine2]` Support older version of `jest-runtime` ([#9903](https://github.com/facebook/jest/pull/9903) & [#9842](https://github.com/facebook/jest/pull/9842))
- `[@jest/environment]` Make sure not to reference Jest types ([#9875](https://github.com/facebook/jest/pull/9875))
Expand Down Expand Up @@ -45,8 +46,6 @@
- `[*]` Do not generate TypeScript declaration source maps ([#9822](https://github.com/facebook/jest/pull/9822))
- `[*]` Transpile code for Node 8.3, not 8.0 ([#9827](https://github.com/facebook/jest/pull/9827))

### Performance

## 25.3.0

### Features
Expand Down Expand Up @@ -276,8 +275,6 @@
- `[jest-types]` Mark `InitialOptions` as `Partial` ([#8848](https://github.com/facebook/jest/pull/8848))
- `[jest-config]` Refactor `normalize` to be more type safe ([#8848](https://github.com/facebook/jest/pull/8848))

### Performance

## 24.9.0

### Features
Expand Down
2 changes: 1 addition & 1 deletion e2e/Utils.ts
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'graceful-fs';
import type {Config} from '@jest/types';

// eslint-disable-next-line import/named
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/clearCache.test.ts
Expand Up @@ -5,9 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/

import * as fs from 'fs';
import {tmpdir} from 'os';
import * as path from 'path';
import * as fs from 'graceful-fs';
import runJest from '../runJest';

const CACHE = path.resolve(tmpdir(), 'clear-cache-directory');
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/coverageHandlebars.test.ts
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import {readFileSync} from 'fs';
import * as path from 'path';
import {readFileSync} from 'graceful-fs';
import wrap from 'jest-snapshot-serializer-raw';
import {cleanup, run} from '../Utils';
import runJest from '../runJest';
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/coverageRemapping.test.ts
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import {readFileSync} from 'fs';
import * as path from 'path';
import {readFileSync} from 'graceful-fs';
import {cleanup, run} from '../Utils';
import runJest from '../runJest';

Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/coverageReport.test.ts
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'graceful-fs';
import {wrap} from 'jest-snapshot-serializer-raw';
import {extractSummary, run} from '../Utils';
import runJest from '../runJest';
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/coverageTransformInstrumented.test.ts
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import {readFileSync} from 'fs';
import * as path from 'path';
import {readFileSync} from 'graceful-fs';
import {cleanup, run} from '../Utils';
import runJest from '../runJest';

Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/globalSetup.test.ts
Expand Up @@ -5,9 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/

import * as fs from 'fs';
import {tmpdir} from 'os';
import * as path from 'path';
import * as fs from 'graceful-fs';
import runJest, {json as runWithJson} from '../runJest';
import {cleanup, run} from '../Utils';

Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/globalTeardown.test.ts
Expand Up @@ -5,9 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/

import * as fs from 'fs';
import {tmpdir} from 'os';
import * as path from 'path';
import * as fs from 'graceful-fs';
import {createDirectory} from 'jest-util';
import runJest, {json as runWithJson} from '../runJest';
import {cleanup, run} from '../Utils';
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/jsonReporter.test.ts
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'graceful-fs';
import type {FormattedTestResults} from '@jest/test-result';
import runJest from '../runJest';

Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/setupFilesAfterEnvConfig.test.ts
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'graceful-fs';
import {json as runWithJson} from '../runJest';
import {writeFiles} from '../Utils';

Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/snapshot.test.ts
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'graceful-fs';
import {wrap} from 'jest-snapshot-serializer-raw';
import {extractSummary} from '../Utils';
import runJest, {json as runWithJson} from '../runJest';
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/snapshotResolver.test.ts
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'graceful-fs';
import runJest from '../runJest';

const snapshotDir = path.resolve(
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/testEnvironmentAsync.test.ts
Expand Up @@ -5,9 +5,9 @@
* LICENSE file in the root directory of this source tree.
*/

import * as fs from 'fs';
import * as path from 'path';
import {tmpdir} from 'os';
import * as fs from 'graceful-fs';
import runJest from '../runJest';
import {cleanup} from '../Utils';

Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/testRetries.test.ts
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'graceful-fs';
import {skipSuiteOnJasmine} from '@jest/test-utils';
import runJest from '../runJest';

Expand Down
3 changes: 2 additions & 1 deletion e2e/__tests__/toMatchInlineSnapshot.test.ts
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'graceful-fs';
import {wrap} from 'jest-snapshot-serializer-raw';
import {cleanup, makeTemplate, writeFiles} from '../Utils';
import runJest from '../runJest';
Expand Down Expand Up @@ -256,6 +256,7 @@ test('handles mocking native modules prettier relies on', () => {
const test = `
jest.mock('path', () => ({}));
jest.mock('fs', () => ({}));
jest.mock('graceful-fs', () => ({}));
test('inline snapshots', () => {
expect({}).toMatchInlineSnapshot();
});
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/toMatchSnapshotWithStringSerializer.test.ts
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'graceful-fs';
import {cleanup, makeTemplate, writeFiles} from '../Utils';
import runJest from '../runJest';

Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/toThrowErrorMatchingInlineSnapshot.test.ts
Expand Up @@ -6,7 +6,7 @@
*/

import * as path from 'path';
import * as fs from 'fs';
import * as fs from 'graceful-fs';
import {wrap} from 'jest-snapshot-serializer-raw';
import {cleanup, makeTemplate, writeFiles} from '../Utils';
import runJest from '../runJest';
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/toThrowErrorMatchingSnapshot.test.ts
Expand Up @@ -6,7 +6,7 @@
*/

import * as path from 'path';
import * as fs from 'fs';
import * as fs from 'graceful-fs';
import {wrap} from 'jest-snapshot-serializer-raw';
import {cleanup, makeTemplate, writeFiles} from '../Utils';
import runJest from '../runJest';
Expand Down
2 changes: 2 additions & 0 deletions e2e/native-esm/__tests__/native-esm.test.js
Expand Up @@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

// the point here is that it's the node core module
// eslint-disable-next-line no-restricted-imports
import {readFileSync} from 'fs';
import {createRequire} from 'module';
import {dirname, resolve} from 'path';
Expand Down
2 changes: 1 addition & 1 deletion e2e/runJest.ts
Expand Up @@ -7,8 +7,8 @@
*/

import * as path from 'path';
import * as fs from 'fs';
import {Writable} from 'stream';
import * as fs from 'graceful-fs';
import execa = require('execa');
import type {Config} from '@jest/types';
import type {FormattedTestResults} from '@jest/test-result';
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -49,7 +49,7 @@
"find-process": "^1.4.1",
"glob": "^7.1.1",
"globby": "^10.0.2",
"graceful-fs": "^4.2.3",
"graceful-fs": "^4.2.4",
"isbinaryfile": "^4.0.0",
"istanbul-lib-coverage": "^3.0.0",
"istanbul-lib-report": "^3.0.0",
Expand Down
4 changes: 3 additions & 1 deletion packages/babel-jest/package.json
Expand Up @@ -24,10 +24,12 @@
"babel-plugin-istanbul": "^6.0.0",
"babel-preset-jest": "^25.4.0",
"chalk": "^3.0.0",
"graceful-fs": "^4.2.4",
"slash": "^3.0.0"
},
"devDependencies": {
"@babel/core": "^7.1.0"
"@babel/core": "^7.1.0",
"@types/graceful-fs": "^4.1.3"
},
"peerDependencies": {
"@babel/core": "^7.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-jest/src/index.ts
Expand Up @@ -6,8 +6,8 @@
*/

import {createHash} from 'crypto';
import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'graceful-fs';
import type {
TransformOptions as JestTransformOptions,
Transformer,
Expand Down
4 changes: 3 additions & 1 deletion packages/jest-circus/package.json
Expand Up @@ -41,8 +41,10 @@
"@jest/test-utils": "^25.3.0",
"@types/babel__traverse": "^7.0.4",
"@types/co": "^4.6.0",
"@types/graceful-fs": "^4.1.3",
"@types/stack-utils": "^1.0.1",
"execa": "^3.2.0"
"execa": "^3.2.0",
"graceful-fs": "^4.2.4"
},
"engines": {
"node": ">= 8.3"
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-circus/src/__mocks__/testUtils.ts
Expand Up @@ -5,10 +5,10 @@
* LICENSE file in the root directory of this source tree.
*/

import * as fs from 'fs';
import {tmpdir} from 'os';
import * as path from 'path';
import {createHash} from 'crypto';
import * as fs from 'graceful-fs';
// eslint-disable-next-line import/named
import {ExecaSyncReturnValue, sync as spawnSync} from 'execa';
import {skipSuiteOnWindows} from '@jest/test-utils';
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-cli/package.json
Expand Up @@ -17,6 +17,7 @@
"@jest/types": "^25.4.0",
"chalk": "^3.0.0",
"exit": "^0.1.2",
"graceful-fs": "^4.2.4",
"import-local": "^3.0.2",
"is-ci": "^2.0.0",
"jest-config": "^25.4.0",
Expand All @@ -30,6 +31,7 @@
"@jest/test-utils": "^25.3.0",
"@types/exit": "^0.1.30",
"@types/is-ci": "^2.0.0",
"@types/graceful-fs": "^4.1.3",
"@types/prompts": "^2.0.1",
"@types/yargs": "^15.0.0"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-cli/src/init/__tests__/init.test.js
Expand Up @@ -6,8 +6,8 @@
*/

/* eslint-disable no-eval */
import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'graceful-fs';
import prompts from 'prompts';
import {constants} from 'jest-config';
import init from '../';
Expand All @@ -19,7 +19,7 @@ jest.mock('../../../../jest-config/build/getCacheDirectory', () => () =>
'/tmp/jest',
);
jest.mock('path', () => ({...jest.requireActual('path'), sep: '/'}));
jest.mock('fs', () => ({
jest.mock('graceful-fs', () => ({
...jest.requireActual('fs'),
writeFileSync: jest.fn(),
}));
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-cli/src/init/index.ts
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'graceful-fs';
import chalk = require('chalk');
import prompts = require('prompts');
import {sync as realpath} from 'realpath-native';
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-config/package.json
Expand Up @@ -24,6 +24,7 @@
"chalk": "^3.0.0",
"deepmerge": "^4.2.2",
"glob": "^7.1.1",
"graceful-fs": "^4.2.4",
"jest-environment-jsdom": "^25.4.0",
"jest-environment-node": "^25.4.0",
"jest-get-type": "^25.2.6",
Expand All @@ -39,6 +40,7 @@
"devDependencies": {
"@types/babel__core": "^7.0.4",
"@types/glob": "^7.1.1",
"@types/graceful-fs": "^4.1.3",
"@types/micromatch": "^4.0.0"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/__tests__/normalize.test.js
Expand Up @@ -19,7 +19,7 @@ const DEFAULT_CSS_PATTERN = '^.+\\.(css)$';
jest
.mock('jest-resolve')
.mock('path', () => jest.requireActual('path').posix)
.mock('fs', () => {
.mock('graceful-fs', () => {
const realFs = jest.requireActual('fs');

return {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/index.ts
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

import * as fs from 'fs';
import * as path from 'path';
import * as fs from 'graceful-fs';
import type {Config} from '@jest/types';
import chalk = require('chalk');
import {sync as realpath} from 'realpath-native';
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/normalize.ts
Expand Up @@ -6,8 +6,8 @@
*/

import {createHash} from 'crypto';
import {statSync} from 'fs';
import * as path from 'path';
import {statSync} from 'graceful-fs';
import {sync as glob} from 'glob';
import type {Config} from '@jest/types';
import {ValidationError, validate} from 'jest-validate';
Expand Down