Skip to content

Commit ad9e7e2

Browse files
authored
Add policy for test scripts to split property for the client pipeline (#17161)
Also fix driver-web-cache test to run in the CI.
1 parent 147b19b commit ad9e7e2

File tree

8 files changed

+62
-9
lines changed

8 files changed

+62
-9
lines changed

azure/packages/azure-client/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"prettier": "prettier --check . --ignore-path ../../../.prettierignore",
3333
"prettier:fix": "prettier --write . --ignore-path ../../../.prettierignore",
3434
"start:tinylicious:test": "npx @fluidframework/azure-local-service > tinylicious.log 2>&1",
35+
"test": "npm run test:realsvc",
3536
"test:realsvc": "npm run test:realsvc:tinylicious",
3637
"test:realsvc:local:run": "mocha --recursive 'dist/test/**/*.spec.js' --exit --timeout 10000",
3738
"test:realsvc:tinylicious": "start-server-and-test start:tinylicious:test 7070 test:realsvc:local:run",

azure/packages/test/scenario-runner/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"start": "node ./dist/orchestratorRunner.js --config v1",
3030
"start:scenario": "node ./dist/orchestratorRunner.js --config",
3131
"start:server": "node ./dist/server.js",
32-
"test": "echo \"Error: no test specified\" && exit 1",
32+
"test": "npm run test:realsvc",
3333
"test:realsvc": "npm run test:realsvc:tinylicious",
3434
"test:realsvc:azure": "cross-env FLUID_CLIENT=azure npm run test:realsvc:azure:run",
3535
"test:realsvc:azure:run": "mocha --recursive 'dist/test/**/*.spec.js' --exit --timeout 10000",

build-tools/packages/build-tools/src/repoPolicyCheck/handlers/npmPackages.ts

+45
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,51 @@ export const handlers: Handler[] = [
789789
}
790790
},
791791
},
792+
{
793+
name: "npm-package-json-test-scripts-split",
794+
match,
795+
handler: (file, root) => {
796+
let json;
797+
798+
try {
799+
json = JSON.parse(readFile(file));
800+
} catch (err) {
801+
return "Error parsing JSON file: " + file;
802+
}
803+
804+
const scripts = json.scripts;
805+
if (scripts === undefined) {
806+
return undefined;
807+
}
808+
const testScript = scripts["test"];
809+
810+
const splitTestScriptNames = ["test:mocha", "test:jest", "test:realsvc"];
811+
812+
if (testScript === undefined) {
813+
if (splitTestScriptNames.some((name) => scripts[name] !== undefined)) {
814+
return "Missing 'test' scripts";
815+
}
816+
return undefined;
817+
}
818+
819+
const actualSplitTestScriptNames = splitTestScriptNames.filter(
820+
(name) => scripts[name] !== undefined,
821+
);
822+
823+
if (actualSplitTestScriptNames.length === 0) {
824+
if (!testScript.startsWith("echo ")) {
825+
return "Missing split test scripts. The 'test' script must call one or more \"split\" scripts like 'test:mocha', 'test:jest', or 'test:realsvc'.";
826+
}
827+
return undefined;
828+
}
829+
const expectedTestScript = actualSplitTestScriptNames
830+
.map((name) => `npm run ${name}`)
831+
.join(" && ");
832+
if (testScript !== expectedTestScript) {
833+
return `Unexpected test script:\n\tactual: ${testScript}\n\texpected: ${expectedTestScript}`;
834+
}
835+
},
836+
},
792837
{
793838
name: "npm-package-json-script-mocha-config",
794839
match,

experimental/dds/tree/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131
"perf:measure": "npm run perf -- --fgrep @Measurement",
3232
"prettier": "prettier --check . --ignore-path ../../../.prettierignore",
3333
"prettier:fix": "prettier --write . --ignore-path ../../../.prettierignore",
34-
"test": "nyc npm run test:mocha",
34+
"test": "npm run test:mocha",
3535
"test:benchmark:report": "mocha \"dist/**/*.tests.js\" --node-option unhandled-rejections=strict,expose-gc --exit --perfMode --fgrep @Benchmark -r node_modules/@fluidframework/mocha-test-setup --reporter @fluid-tools/benchmark/dist/MochaReporter.js --timeout 60000",
36+
"test:coverage": "nyc npm run test",
3637
"test:mocha": "mocha \"dist/**/*.tests.js\" --exit -r node_modules/@fluidframework/mocha-test-setup",
3738
"test:mocha:verbose": "cross-env FLUID_TEST_VERBOSE=1 npm run test:mocha",
3839
"test:stress": "cross-env FUZZ_TEST_COUNT=10 FUZZ_STRESS_RUN=true mocha \"dist/**/*.fuzz.tests.js\" --exit -r @fluidframework/mocha-test-setup",

fluidBuild.config.cjs

+6
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ module.exports = {
143143
"packages/test/mocha-test-setup/package.json",
144144
"examples/apps/attributable-map/package.json",
145145
],
146+
"npm-package-json-test-scripts-split": [
147+
"server/",
148+
"tools/",
149+
"package.json",
150+
"packages/test/test-service-load/package.json",
151+
],
146152
},
147153
packageNames: {
148154
// The allowed package scopes for the repo.

packages/common/client-utils/package.json

-6
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@
2828
"build:test:jest": "tsc --project ./src/test/jest/tsconfig.json",
2929
"build:test:mocha": "tsc --project ./src/test/mocha/tsconfig.json",
3030
"build:test:types": "tsc --project ./src/test/types/tsconfig.json",
31-
"ci:build": "npm run build:compile",
3231
"ci:build:docs": "api-extractor run --typescript-compiler-folder ./node_modules/typescript && copyfiles -u 1 ./_api-extractor-temp/doc-models/* ../../../_api-extractor-temp/",
33-
"ci:test": "npm run test:report",
34-
"ci:test:coverage": "npm run test:coverage",
3532
"clean": "rimraf --glob _api-extractor-temp dist lib *.tsbuildinfo *.build.log",
3633
"eslint": "eslint --format stylish src",
3734
"eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
@@ -41,11 +38,8 @@
4138
"prettier": "prettier --check . --ignore-path ../../../.prettierignore",
4239
"prettier:fix": "prettier --write . --ignore-path ../../../.prettierignore",
4340
"test": "npm run test:mocha && npm run test:jest",
44-
"test:coverage": "npm run test:report",
4541
"test:jest": "jest",
46-
"test:jest:report": "npm run test:jest -- --ci --coverage --reporters=default --reporters=jest-junit",
4742
"test:mocha": "mocha --recursive dist/test/mocha/**/*.spec.js --exit --project test/tsconfig.json",
48-
"test:report": "nyc npm run test:mocha && npm run test:jest:report",
4943
"tsc": "tsc",
5044
"typetests:gen": "fluid-type-test-generator",
5145
"typetests:prepare": "flub typetests --dir . --reset --previous --normalize"

packages/drivers/driver-web-cache/package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"lint:fix": "npm run prettier:fix && npm run eslint:fix",
3232
"prettier": "prettier --check . --ignore-path ../../../.prettierignore",
3333
"prettier:fix": "prettier --write . --ignore-path ../../../.prettierignore",
34-
"test": "jest",
34+
"test": "npm run test:jest",
35+
"test:jest": "jest",
3536
"tsc": "tsc",
3637
"typetests:gen": "fluid-type-test-generator",
3738
"typetests:prepare": "flub typetests --dir . --reset --previous --normalize"
@@ -60,6 +61,10 @@
6061
"rimraf": "^4.4.0",
6162
"typescript": "~4.5.5"
6263
},
64+
"jest-junit": {
65+
"outputDirectory": "nyc",
66+
"outputName": "jest-junit-report.xml"
67+
},
6368
"typeValidation": {
6469
"broken": {}
6570
}

packages/framework/tinylicious-client/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"prettier": "prettier --check . --ignore-path ../../../.prettierignore",
3232
"prettier:fix": "prettier --write . --ignore-path ../../../.prettierignore",
3333
"start:tinylicious:test": "tinylicious > tinylicious.log 2>&1",
34+
"test": "npm run test:realsvc",
3435
"test:realsvc": "npm run test:realsvc:tinylicious",
3536
"test:realsvc:tinylicious": "start-server-and-test start:tinylicious:test 7070 test:realsvc:tinylicious:run",
3637
"test:realsvc:tinylicious:run": "mocha --recursive 'dist/test/**/*.spec.js' --exit",

0 commit comments

Comments
 (0)