Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion packages/jest-reporters/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
103 changes: 44 additions & 59 deletions packages/jest-reporters/src/__tests__/CoverageReporter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('/');

Comment thread
SimenB marked this conversation as resolved.
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', () => {
Expand Down Expand Up @@ -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')],
Comment thread
SimenB marked this conversation as resolved.
[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) => {
Expand Down Expand Up @@ -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};
Expand All @@ -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};
Expand All @@ -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,
},
},
Expand All @@ -239,7 +224,7 @@ describe('onRunComplete', () => {
{
collectCoverage: true,
coverageThreshold: {
'./path-test-files/glob-path/': {
[fixturePath('path-test-files/glob-path/')]: {
statements: 100,
},
},
Expand All @@ -260,7 +245,7 @@ describe('onRunComplete', () => {
{
collectCoverage: true,
coverageThreshold: {
'./path-test-files/glob-path/': {
[fixturePath('path-test-files/glob-path/')]: {
statements: 40,
},
},
Expand Down Expand Up @@ -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: {
Expand All @@ -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: {
Expand All @@ -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,
Expand Down Expand Up @@ -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: {
Expand All @@ -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,
},
},
Expand Down
9 changes: 0 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
Loading