diff --git a/eslint.config.mjs b/eslint.config.mjs index 534be9ef70f0..f9de1d86254d 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -840,6 +840,7 @@ const config = defineConfig( 'packages/create-jest/src/__tests__/__fixtures__/**/*', 'packages/jest-core/src/__tests__/**/*', 'packages/jest-haste-map/src/__tests__/test_dotfiles_root/**/*', + 'packages/jest-reporters/src/__tests__/__fixtures__/**/*', 'packages/jest-resolve/src/__mocks__/**/*', ], rules: { diff --git a/package.json b/package.json index cfdf994ca690..99737de0dae2 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,6 @@ "jest-util": "workspace:*", "jest-watch-typeahead": "^3.0.1", "js-yaml": "^5.0.0", - "mock-fs": "^5.5.0", "netlify-plugin-cache": "^1.0.3", "node-notifier": "^10.0.1", "p-limit": "^3.1.0", diff --git a/packages/jest-reporters/package.json b/packages/jest-reporters/package.json index 476c22d624e0..e033ca7923c2 100644 --- a/packages/jest-reporters/package.json +++ b/packages/jest-reporters/package.json @@ -49,7 +49,6 @@ "@types/istanbul-reports": "^3.0.4", "@types/node-notifier": "^8.0.5", "jest-resolve": "workspace:*", - "mock-fs": "^5.5.0", "node-notifier": "^10.0.1" }, "peerDependencies": { diff --git a/packages/jest-reporters/src/__tests__/CoverageReporter.test.js b/packages/jest-reporters/src/__tests__/CoverageReporter.test.js index 2957c4879304..f83695418764 100644 --- a/packages/jest-reporters/src/__tests__/CoverageReporter.test.js +++ b/packages/jest-reporters/src/__tests__/CoverageReporter.test.js @@ -23,36 +23,21 @@ let CoverageReporter; let istanbulReports; import * as path from 'path'; -import mock from 'mock-fs'; + +const relativeFixtureDir = path + .relative(process.cwd(), path.join(__dirname, '__fixtures__')) + .split(path.sep) + .join('/'); + +function fixturePath(relativePath) { + return `./${relativeFixtureDir}/${relativePath}`; +} beforeEach(() => { CoverageReporter = require('../CoverageReporter').default; libCoverage = require('istanbul-lib-coverage'); libSourceMaps = require('istanbul-lib-source-maps'); istanbulReports = require('istanbul-reports'); - - const fileTree = { - [`${process.cwd()}/path-test-files`]: { - '000pc_coverage_file.js': '', - '050pc_coverage_file.js': '', - '100pc_coverage_file.js': '', - 'full_path_file.js': '', - 'glob-path': { - 'file1.js': '', - 'file2.js': '', - }, - 'non_covered_file.js': '', - 'relative_path_file.js': '', - }, - [`${process.cwd()}/path-test`]: { - '100pc_coverage_file.js': '', - }, - }; - mock(fileTree); -}); - -afterEach(() => { - mock.restore(); }); describe('onRunComplete', () => { @@ -83,24 +68,24 @@ describe('onRunComplete', () => { }; const fileCoverage = [ [ - './path-test/100pc_coverage_file.js', + fixturePath('path-test/100pc_coverage_file.js'), {statements: {covered: 10, pct: 100, total: 10}}, ], - ['./path-test-files/covered_file_without_threshold.js'], - ['./path-test-files/full_path_file.js'], - ['./path-test-files/relative_path_file.js'], - ['./path-test-files/glob-path/file1.js'], - ['./path-test-files/glob-path/file2.js'], + [fixturePath('path-test-files/covered_file_without_threshold.js')], + [fixturePath('path-test-files/full_path_file.js')], + [fixturePath('path-test-files/relative_path_file.js')], + [fixturePath('path-test-files/glob-path/file1.js')], + [fixturePath('path-test-files/glob-path/file2.js')], [ - './path-test-files/000pc_coverage_file.js', + fixturePath('path-test-files/000pc_coverage_file.js'), {statements: {covered: 0, pct: 0, total: 10}}, ], [ - './path-test-files/050pc_coverage_file.js', + fixturePath('path-test-files/050pc_coverage_file.js'), {statements: {covered: 5, pct: 50, total: 10}}, ], [ - './path-test-files/100pc_coverage_file.js', + fixturePath('path-test-files/100pc_coverage_file.js'), {statements: {covered: 10, pct: 100, total: 10}}, ], ].reduce((c, f) => { @@ -161,9 +146,9 @@ describe('onRunComplete', () => { const covThreshold = {}; const paths = [ 'global', - path.resolve(`${process.cwd()}/path-test-files/full_path_file.js`), - './path-test-files/relative_path_file.js', - 'path-test-files/glob-*/*.js', + path.resolve(__dirname, '__fixtures__/path-test-files/full_path_file.js'), + fixturePath('path-test-files/relative_path_file.js'), + `${relativeFixtureDir}/path-test-files/glob-*/*.js`, ]; for (const path of paths) { covThreshold[path] = {statements: 100}; @@ -189,9 +174,9 @@ describe('onRunComplete', () => { const covThreshold = {}; const paths = [ 'global', - path.resolve(`${process.cwd()}/path-test-files/full_path_file.js`), - './path-test-files/relative_path_file.js', - 'path-test-files/glob-*/*.js', + path.resolve(__dirname, '__fixtures__/path-test-files/full_path_file.js'), + fixturePath('path-test-files/relative_path_file.js'), + `${relativeFixtureDir}/path-test-files/glob-*/*.js`, ]; for (const path of paths) { covThreshold[path] = {statements: 50}; @@ -218,7 +203,7 @@ describe('onRunComplete', () => { { collectCoverage: true, coverageThreshold: { - 'path-test-files/non_covered_file.js': { + [`${relativeFixtureDir}/path-test-files/non_covered_file.js`]: { statements: 100, }, }, @@ -239,7 +224,7 @@ describe('onRunComplete', () => { { collectCoverage: true, coverageThreshold: { - './path-test-files/glob-path/': { + [fixturePath('path-test-files/glob-path/')]: { statements: 100, }, }, @@ -260,7 +245,7 @@ describe('onRunComplete', () => { { collectCoverage: true, coverageThreshold: { - './path-test-files/glob-path/': { + [fixturePath('path-test-files/glob-path/')]: { statements: 40, }, }, @@ -302,10 +287,10 @@ describe('onRunComplete', () => { { collectCoverage: true, coverageThreshold: { - './path-test-files/': { + [fixturePath('path-test-files/')]: { statements: 50, }, - './path-test/': { + [fixturePath('path-test/')]: { statements: 100, }, global: { @@ -331,10 +316,10 @@ describe('onRunComplete', () => { { collectCoverage: true, coverageThreshold: { - './path-test-files/': { + [fixturePath('path-test-files/')]: { statements: 50, }, - './path-test/': { + [fixturePath('path-test/')]: { statements: 100, }, global: { @@ -358,13 +343,13 @@ describe('onRunComplete', () => { test('getLastError() returns undefined when file and directory path threshold groups overlap', async () => { const covThreshold = {}; for (const path of [ - './path-test-files/', - './path-test-files/covered_file_without_threshold.js', - './path-test-files/full_path_file.js', - './path-test-files/relative_path_file.js', - './path-test-files/glob-path/file1.js', - './path-test-files/glob-path/file2.js', - './path-test-files/*.js', + fixturePath('path-test-files/'), + fixturePath('path-test-files/covered_file_without_threshold.js'), + fixturePath('path-test-files/full_path_file.js'), + fixturePath('path-test-files/relative_path_file.js'), + fixturePath('path-test-files/glob-path/file1.js'), + fixturePath('path-test-files/glob-path/file2.js'), + fixturePath('path-test-files/*.js'), ]) { covThreshold[path] = { statements: 0, @@ -392,10 +377,10 @@ describe('onRunComplete', () => { { collectCoverage: true, coverageThreshold: { - './path-test-files/100pc_coverage_file.js': { + [fixturePath('path-test-files/100pc_coverage_file.js')]: { statements: 100, }, - './path-test/100pc_coverage_file.js': { + [fixturePath('path-test/100pc_coverage_file.js')]: { statements: 100, }, global: { @@ -420,16 +405,16 @@ describe('onRunComplete', () => { { collectCoverage: true, coverageThreshold: { - './path-test-files/': { + [fixturePath('path-test-files/')]: { statements: 50, }, - './path-test-files/050pc_coverage_file.js': { + [fixturePath('path-test-files/050pc_coverage_file.js')]: { statements: 50, }, - './path-test-files/100pc_coverage_*.js': { + [fixturePath('path-test-files/100pc_coverage_*.js')]: { statements: 100, }, - './path-test-files/100pc_coverage_file.js': { + [fixturePath('path-test-files/100pc_coverage_file.js')]: { statements: 100, }, }, diff --git a/packages/jest-reporters/src/__tests__/__fixtures__/path-test-files/000pc_coverage_file.js b/packages/jest-reporters/src/__tests__/__fixtures__/path-test-files/000pc_coverage_file.js new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/jest-reporters/src/__tests__/__fixtures__/path-test-files/050pc_coverage_file.js b/packages/jest-reporters/src/__tests__/__fixtures__/path-test-files/050pc_coverage_file.js new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/jest-reporters/src/__tests__/__fixtures__/path-test-files/100pc_coverage_file.js b/packages/jest-reporters/src/__tests__/__fixtures__/path-test-files/100pc_coverage_file.js new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/jest-reporters/src/__tests__/__fixtures__/path-test-files/full_path_file.js b/packages/jest-reporters/src/__tests__/__fixtures__/path-test-files/full_path_file.js new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/jest-reporters/src/__tests__/__fixtures__/path-test-files/glob-path/file1.js b/packages/jest-reporters/src/__tests__/__fixtures__/path-test-files/glob-path/file1.js new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/jest-reporters/src/__tests__/__fixtures__/path-test-files/glob-path/file2.js b/packages/jest-reporters/src/__tests__/__fixtures__/path-test-files/glob-path/file2.js new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/jest-reporters/src/__tests__/__fixtures__/path-test-files/non_covered_file.js b/packages/jest-reporters/src/__tests__/__fixtures__/path-test-files/non_covered_file.js new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/jest-reporters/src/__tests__/__fixtures__/path-test-files/relative_path_file.js b/packages/jest-reporters/src/__tests__/__fixtures__/path-test-files/relative_path_file.js new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/jest-reporters/src/__tests__/__fixtures__/path-test/100pc_coverage_file.js b/packages/jest-reporters/src/__tests__/__fixtures__/path-test/100pc_coverage_file.js new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/yarn.lock b/yarn.lock index 2f959e2f0fdb..801bcf1def28 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4448,7 +4448,6 @@ __metadata: jest-util: "workspace:*" jest-watch-typeahead: "npm:^3.0.1" js-yaml: "npm:^5.0.0" - mock-fs: "npm:^5.5.0" netlify-plugin-cache: "npm:^1.0.3" node-notifier: "npm:^10.0.1" p-limit: "npm:^3.1.0" @@ -4536,7 +4535,6 @@ __metadata: jest-resolve: "workspace:*" jest-util: "workspace:*" jest-worker: "workspace:*" - mock-fs: "npm:^5.5.0" node-notifier: "npm:^10.0.1" slash: "npm:^3.0.0" string-length: "npm:^4.0.2" @@ -17319,13 +17317,6 @@ __metadata: languageName: node linkType: hard -"mock-fs@npm:^5.5.0": - version: 5.5.0 - resolution: "mock-fs@npm:5.5.0" - checksum: 10/f40f0ea4b0b0f79f2218a2ea64b55b756989a262ebe4aac7b4fb6d8757866c35f59a2740adb114a91854ab7a091378702facd5ba750f051cbc795622c685e415 - languageName: node - linkType: hard - "mrmime@npm:^2.0.0": version: 2.0.1 resolution: "mrmime@npm:2.0.1"