Skip to content

Commit 6d4e010

Browse files
authored
Change jest to always use jest-junit reporter whether in CI or not (#17173)
To mirror what mocha does so that local run can be more similar to CI runs
1 parent ad9e7e2 commit 6d4e010

File tree

95 files changed

+502
-196
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+502
-196
lines changed

Diff for: azure/packages/external-controller/jest.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,14 @@ module.exports = {
2020
transform: {
2121
"^.+\\.ts?$": "ts-jest",
2222
},
23+
reporters: [
24+
"default",
25+
[
26+
"jest-junit",
27+
{
28+
outputDirectory: "nyc",
29+
outputName: "jest-junit-report.xml",
30+
},
31+
],
32+
],
2333
};

Diff for: azure/packages/external-controller/package.json

-4
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,6 @@
101101
}
102102
}
103103
},
104-
"jest-junit": {
105-
"outputDirectory": "nyc",
106-
"outputName": "jest-junit-report.xml"
107-
},
108104
"typeValidation": {
109105
"disabled": true,
110106
"broken": {}

Diff for: build-tools/packages/build-tools/src/repoPolicyCheck/handlers/npmPackages.ts

+60-1
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ export const handlers: Handler[] = [
853853
const mochaScriptName = scripts["test:mocha"] !== undefined ? "test:mocha" : "test";
854854
const mochaScript = scripts[mochaScriptName];
855855

856-
if (!mochaScript || !mochaScript.startsWith("mocha")) {
856+
if (mochaScript === undefined || !mochaScript.startsWith("mocha")) {
857857
// skip irregular test script for now
858858
return undefined;
859859
}
@@ -871,4 +871,63 @@ export const handlers: Handler[] = [
871871
}
872872
},
873873
},
874+
875+
{
876+
name: "npm-package-json-script-jest-config",
877+
match,
878+
handler: (file, root) => {
879+
let json;
880+
881+
try {
882+
json = JSON.parse(readFile(file));
883+
} catch (err) {
884+
return "Error parsing JSON file: " + file;
885+
}
886+
887+
const scripts = json.scripts;
888+
if (scripts === undefined) {
889+
return undefined;
890+
}
891+
const jestScriptName = scripts["test:jest"] !== undefined ? "test:jest" : "test";
892+
const jestScript = scripts[jestScriptName];
893+
894+
if (jestScript === undefined || !jestScript.startsWith("jest")) {
895+
// skip irregular test script for now
896+
return undefined;
897+
}
898+
899+
const packageDir = path.dirname(file);
900+
const jestFileName = ["jest.config.js", "jest.config.cjs"].find((name) =>
901+
fs.existsSync(path.join(packageDir, name)),
902+
);
903+
if (jestFileName === undefined) {
904+
return `Missing jest config file.`;
905+
}
906+
907+
const jestConfigFile = path.join(packageDir, jestFileName);
908+
const config = require(path.resolve(jestConfigFile));
909+
if (config.reporters === undefined) {
910+
return `Missing reporters in '${jestConfigFile}'`;
911+
}
912+
913+
const expectedReporter = [
914+
"default",
915+
[
916+
"jest-junit",
917+
{
918+
outputDirectory: "nyc",
919+
outputName: "jest-junit-report.xml",
920+
},
921+
],
922+
];
923+
924+
if (JSON.stringify(config.reporters) !== JSON.stringify(expectedReporter)) {
925+
return `Unexpected reporters in '${jestConfigFile}'`;
926+
}
927+
928+
if (json["jest-junit"] !== undefined) {
929+
return `Extraneous jest-unit config in ${file}`;
930+
}
931+
},
932+
},
874933
];

Diff for: common/lib/common-utils/jest.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,14 @@ module.exports = {
77
preset: "jest-puppeteer",
88
testMatch: ["**/dist/test/jest/?(*.)+(spec|test).js"],
99
testPathIgnorePatterns: ["/node_modules/"],
10+
reporters: [
11+
"default",
12+
[
13+
"jest-junit",
14+
{
15+
outputDirectory: "nyc",
16+
outputName: "jest-junit-report.xml",
17+
},
18+
],
19+
],
1020
};

Diff for: common/lib/common-utils/package.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"test": "npm run test:mocha && npm run test:jest",
4646
"test:coverage": "npm run test:report",
4747
"test:jest": "jest",
48-
"test:jest:report": "npm run test:jest -- --ci --coverage --reporters=default --reporters=jest-junit",
48+
"test:jest:report": "npm run test:jest -- --ci --coverage",
4949
"test:mocha": "mocha --unhandled-rejections=strict --recursive dist/test/mocha/**/*.spec.js --exit --project test/tsconfig.json",
5050
"test:mocha:multireport": "cross-env FLUID_TEST_MULTIREPORT=1 npm run test:mocha",
5151
"test:mocha:report": "npm run test:mocha -- -- --reporter xunit --reporter-option output=nyc/mocha-junit-report.xml",
@@ -146,10 +146,6 @@
146146
]
147147
}
148148
},
149-
"jest-junit": {
150-
"outputDirectory": "nyc",
151-
"outputName": "jest-junit-report.xml"
152-
},
153149
"typeValidation": {
154150
"broken": {}
155151
}

Diff for: examples/apps/attributable-map/jest.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,14 @@ module.exports = {
2020
transform: {
2121
"^.+\\.ts?$": "ts-jest",
2222
},
23+
reporters: [
24+
"default",
25+
[
26+
"jest-junit",
27+
{
28+
outputDirectory: "nyc",
29+
outputName: "jest-junit-report.xml",
30+
},
31+
],
32+
],
2333
};

Diff for: examples/apps/attributable-map/package.json

-4
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,6 @@
8282
}
8383
}
8484
},
85-
"jest-junit": {
86-
"outputDirectory": "nyc",
87-
"outputName": "jest-junit-report.xml"
88-
},
8985
"typeValidation": {
9086
"disabled": true,
9187
"broken": {}

Diff for: examples/apps/collaborative-textarea/package.json

-4
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,6 @@
9292
}
9393
}
9494
},
95-
"jest-junit": {
96-
"outputDirectory": "nyc",
97-
"outputName": "jest-junit-report.xml"
98-
},
9995
"typeValidation": {
10096
"disabled": true,
10197
"broken": {}

Diff for: examples/apps/contact-collection/jest.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,14 @@ module.exports = {
2020
transform: {
2121
"^.+\\.ts?$": "ts-jest",
2222
},
23+
reporters: [
24+
"default",
25+
[
26+
"jest-junit",
27+
{
28+
outputDirectory: "nyc",
29+
outputName: "jest-junit-report.xml",
30+
},
31+
],
32+
],
2333
};

Diff for: examples/apps/contact-collection/package.json

-4
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,6 @@
8888
}
8989
}
9090
},
91-
"jest-junit": {
92-
"outputDirectory": "nyc",
93-
"outputName": "jest-junit-report.xml"
94-
},
9591
"typeValidation": {
9692
"disabled": true,
9793
"broken": {}

Diff for: examples/apps/data-object-grid/jest.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,14 @@ module.exports = {
2020
transform: {
2121
"^.+\\.ts?$": "ts-jest",
2222
},
23+
reporters: [
24+
"default",
25+
[
26+
"jest-junit",
27+
{
28+
outputDirectory: "nyc",
29+
outputName: "jest-junit-report.xml",
30+
},
31+
],
32+
],
2333
};

Diff for: examples/apps/data-object-grid/package.json

-4
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,6 @@
135135
]
136136
}
137137
},
138-
"jest-junit": {
139-
"outputDirectory": "nyc",
140-
"outputName": "jest-junit-report.xml"
141-
},
142138
"typeValidation": {
143139
"disabled": true,
144140
"broken": {}

Diff for: examples/apps/presence-tracker/jest.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,14 @@ module.exports = {
2020
transform: {
2121
"^.+\\.ts?$": "ts-jest",
2222
},
23+
reporters: [
24+
"default",
25+
[
26+
"jest-junit",
27+
{
28+
outputDirectory: "nyc",
29+
outputName: "jest-junit-report.xml",
30+
},
31+
],
32+
],
2333
};

Diff for: examples/apps/presence-tracker/package.json

-4
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,6 @@
8585
}
8686
}
8787
},
88-
"jest-junit": {
89-
"outputDirectory": "nyc",
90-
"outputName": "jest-junit-report.xml"
91-
},
9288
"typeValidation": {
9389
"disabled": true,
9490
"broken": {}

Diff for: examples/apps/task-selection/jest.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,14 @@ module.exports = {
2020
transform: {
2121
"^.+\\.ts?$": "ts-jest",
2222
},
23+
reporters: [
24+
"default",
25+
[
26+
"jest-junit",
27+
{
28+
outputDirectory: "nyc",
29+
outputName: "jest-junit-report.xml",
30+
},
31+
],
32+
],
2333
};

Diff for: examples/apps/task-selection/package.json

-4
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,6 @@
8989
}
9090
}
9191
},
92-
"jest-junit": {
93-
"outputDirectory": "nyc",
94-
"outputName": "jest-junit-report.xml"
95-
},
9692
"typeValidation": {
9793
"disabled": true,
9894
"broken": {}

Diff for: examples/benchmarks/bubblebench/baseline/jest.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,14 @@ module.exports = {
2020
transform: {
2121
"^.+\\.ts?$": "ts-jest",
2222
},
23+
reporters: [
24+
"default",
25+
[
26+
"jest-junit",
27+
{
28+
outputDirectory: "nyc",
29+
outputName: "jest-junit-report.xml",
30+
},
31+
],
32+
],
2333
};

Diff for: examples/benchmarks/bubblebench/baseline/package.json

-4
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,6 @@
8989
}
9090
}
9191
},
92-
"jest-junit": {
93-
"outputDirectory": "nyc",
94-
"outputName": "jest-junit-report.xml"
95-
},
9692
"typeValidation": {
9793
"disabled": true,
9894
"broken": {}

Diff for: examples/benchmarks/bubblebench/common/package.json

-4
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,6 @@
9797
}
9898
}
9999
},
100-
"jest-junit": {
101-
"outputDirectory": "nyc",
102-
"outputName": "jest-junit-report.xml"
103-
},
104100
"typeValidation": {
105101
"disabled": true,
106102
"broken": {}

Diff for: examples/benchmarks/bubblebench/editable-shared-tree/jest.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,14 @@ module.exports = {
2020
transform: {
2121
"^.+\\.ts?$": "ts-jest",
2222
},
23+
reporters: [
24+
"default",
25+
[
26+
"jest-junit",
27+
{
28+
outputDirectory: "nyc",
29+
outputName: "jest-junit-report.xml",
30+
},
31+
],
32+
],
2333
};

Diff for: examples/benchmarks/bubblebench/editable-shared-tree/package.json

-4
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,6 @@
9292
}
9393
}
9494
},
95-
"jest-junit": {
96-
"outputDirectory": "nyc",
97-
"outputName": "jest-junit-report.xml"
98-
},
9995
"typeValidation": {
10096
"disabled": true,
10197
"broken": {}

Diff for: examples/benchmarks/bubblebench/ot/jest.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,14 @@ module.exports = {
2020
transform: {
2121
"^.+\\.ts?$": "ts-jest",
2222
},
23+
reporters: [
24+
"default",
25+
[
26+
"jest-junit",
27+
{
28+
outputDirectory: "nyc",
29+
outputName: "jest-junit-report.xml",
30+
},
31+
],
32+
],
2333
};

Diff for: examples/benchmarks/bubblebench/ot/package.json

-4
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@
9191
}
9292
}
9393
},
94-
"jest-junit": {
95-
"outputDirectory": "nyc",
96-
"outputName": "jest-junit-report.xml"
97-
},
9894
"typeValidation": {
9995
"disabled": true,
10096
"broken": {}

Diff for: examples/benchmarks/bubblebench/sharedtree/jest.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,14 @@ module.exports = {
2020
transform: {
2121
"^.+\\.ts?$": "ts-jest",
2222
},
23+
reporters: [
24+
"default",
25+
[
26+
"jest-junit",
27+
{
28+
outputDirectory: "nyc",
29+
outputName: "jest-junit-report.xml",
30+
},
31+
],
32+
],
2333
};

Diff for: examples/benchmarks/bubblebench/sharedtree/package.json

-4
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@
9090
}
9191
}
9292
},
93-
"jest-junit": {
94-
"outputDirectory": "nyc",
95-
"outputName": "jest-junit-report.xml"
96-
},
9793
"typeValidation": {
9894
"disabled": true,
9995
"broken": {}

0 commit comments

Comments
 (0)