Skip to content

Commit eee5048

Browse files
authored
feat: add C8 test coverage support (#1567)
Add comprehensive test coverage reporting across all packages using C8. C8 uses Node.js built-in V8 coverage for excellent performance and simple configuration. - Add C8 dependency (^10.1.2) to root package.json - Create .c8rc.json configuration files for 5 packages - Add npm scripts for coverage testing and reporting - Add coverage directories to .gitignore to exclude generated reports - Support HTML, text, and LCOV coverage report formats Coverage results: - aws-lsp-codewhisperer: 62.02% - aws-lsp-identity: 87.35% - aws-lsp-json: 64.66% - aws-lsp-notification: 0% - hello-world-lsp: 45.66%
1 parent 5d2b3ec commit eee5048

File tree

13 files changed

+226
-3
lines changed

13 files changed

+226
-3
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ app/aws-lsp-partiql-*
2525

2626
# Mynah
2727
!mynah-ui/dist
28+
29+
# Coverage (C8)
30+
**/coverage/

package-lock.json

Lines changed: 126 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
"test": "npm run compile && npm run test --workspaces --if-present",
2929
"test-integ": "npm run compile && npm run test-integ --workspaces --if-present",
3030
"test-unit": "npm run compile && npm run test-unit --workspaces --if-present",
31+
"test:coverage": "npm run compile && npm run test:coverage --workspaces --if-present",
32+
"coverage:report": "c8 report --reporter=html --reporter=text",
33+
"coverage:check": "c8 check-coverage --lines 70 --functions 70 --branches 70 --statements 70",
3134
"package": "npm run compile && npm run package --workspaces --if-present"
3235
},
3336
"dependencies": {
@@ -41,6 +44,7 @@
4144
"@types/node": "^22.9.0",
4245
"@typescript-eslint/eslint-plugin": "^8.32.1",
4346
"@typescript-eslint/parser": "^8.32.1",
47+
"c8": "^10.1.2",
4448
"conventional-changelog-conventionalcommits": "^8.0.0",
4549
"eslint": "^8.42.0",
4650
"eslint-plugin-import": "^2.29.1",
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"all": true,
3+
"check-coverage": false,
4+
"reporter": ["text", "html", "lcov"],
5+
"reports-dir": "coverage",
6+
"include": ["src/**/*.ts"],
7+
"exclude": [
8+
"src/**/*.test.ts",
9+
"src/**/*.spec.ts",
10+
"src/**/test/**",
11+
"src/**/*TestConstants.ts",
12+
"src/**/*.d.ts",
13+
"src/client/**/*.json"
14+
],
15+
"branches": 80,
16+
"lines": 80,
17+
"functions": 80,
18+
"statements": 80
19+
}

server/aws-lsp-codewhisperer/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@
2222
"lint:bundle:webworker": "webpack --config webpack.lint.config.js && eslint bundle/aws-lsp-codewhisperer-webworker.js # Verify compatibility with web runtime target",
2323
"lint:src": "eslint src/ --ext .ts,.tsx",
2424
"test:unit": "ts-mocha --timeout 0 -b \"./src/**/*.test.ts\"",
25+
"test:unit:coverage": "c8 ts-mocha --timeout 0 -b \"./src/**/*.test.ts\"",
2526
"test": "npm run lint && npm run test:unit",
27+
"test:coverage": "npm run lint && npm run test:unit:coverage",
28+
"coverage:report": "c8 report --reporter=html --reporter=text",
29+
"coverage:check": "c8 check-coverage --lines 80 --functions 80 --branches 80 --statements 80",
2630
"prepack": "npm run compile && ts-node ../../script/link_bundled_dependencies.ts",
2731
"postinstall": "node ./script/install_transitive_dep.js"
2832
},
@@ -70,6 +74,7 @@
7074
"@types/uuid": "^9.0.8",
7175
"@types/xml2js": "^0.4.14",
7276
"assert": "^2.1.0",
77+
"c8": "^10.1.2",
7378
"copyfiles": "^2.4.1",
7479
"mock-fs": "^5.2.0",
7580
"sinon": "^19.0.2",

server/aws-lsp-identity/.c8rc.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"all": true,
3+
"check-coverage": false,
4+
"reporter": ["text", "html", "lcov"],
5+
"reports-dir": "coverage",
6+
"include": ["out/**/*.js"],
7+
"exclude": ["out/**/*.test.js", "out/**/*.spec.js", "out/**/test/**", "out/**/*TestConstants.js", "out/**/*.d.ts"],
8+
"branches": 70,
9+
"lines": 70,
10+
"functions": 70,
11+
"statements": 70,
12+
"source-map": true
13+
}

server/aws-lsp-identity/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
"copy": "copyfiles --error --flat ./src/sso/authorizationCodePkce/resources/* ./out/sso/authorizationCodePkce/resources/",
1919
"package": "npm run compile && npm run copy",
2020
"test": "npm run package && npm run test-unit",
21-
"test-unit": "mocha \"./out/**/*.test.js\""
21+
"test-unit": "mocha \"./out/**/*.test.js\"",
22+
"test-unit:coverage": "npm run compile && c8 mocha \"./out/**/*.test.js\"",
23+
"test:coverage": "npm run package && npm run test-unit:coverage",
24+
"coverage:report": "c8 report --reporter=html --reporter=text"
2225
},
2326
"dependencies": {
2427
"@aws-sdk/client-sso-oidc": "^3.616.0",
@@ -38,6 +41,7 @@
3841
"@types/mocha": "^10.0.9",
3942
"@types/mock-fs": "^4.13.4",
4043
"@types/sinon": "^17.0.3",
44+
"c8": "^10.1.2",
4145
"chai": "^4.3.7",
4246
"chai-as-promised": "^7.1.1",
4347
"copyfiles": "^2.4.1",

server/aws-lsp-json/.c8rc.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"all": true,
3+
"check-coverage": false,
4+
"reporter": ["text", "html", "lcov"],
5+
"reports-dir": "coverage",
6+
"include": ["src/**/*.ts"],
7+
"exclude": ["src/**/*.test.ts", "src/**/*.spec.ts", "src/**/test/**", "src/**/*TestConstants.ts", "src/**/*.d.ts"],
8+
"branches": 70,
9+
"lines": 70,
10+
"functions": 70,
11+
"statements": 70
12+
}

server/aws-lsp-json/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
"scripts": {
2222
"compile": "tsc --build",
2323
"test": "ts-mocha -b \"./src/**/*.test.ts\"",
24+
"test:coverage": "c8 ts-mocha -b \"./src/**/*.test.ts\"",
25+
"coverage:report": "c8 report --reporter=html --reporter=text",
2426
"prepack": "shx cp ../../LICENSE ../../NOTICE ../../SECURITY.md ."
2527
},
2628
"dependencies": {
@@ -38,5 +40,8 @@
3840
"bracketSpacing": true,
3941
"arrowParens": "avoid",
4042
"endOfLine": "lf"
43+
},
44+
"devDependencies": {
45+
"c8": "^10.1.2"
4146
}
4247
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"all": true,
3+
"check-coverage": false,
4+
"reporter": ["text", "html", "lcov"],
5+
"reports-dir": "coverage",
6+
"include": ["out/**/*.js"],
7+
"exclude": ["out/**/*.test.js", "out/**/*.spec.js", "out/**/test/**", "out/**/*TestConstants.js", "out/**/*.d.ts"],
8+
"branches": 70,
9+
"lines": 70,
10+
"functions": 70,
11+
"statements": 70,
12+
"source-map": true
13+
}

server/aws-lsp-notification/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
"clean": "rm -fr ./out tsconfig.tsbuildinfo",
1717
"compile": "tsc --build --verbose",
1818
"test": "npm run test-unit",
19-
"test-unit": "mocha \"./out/**/*.test.js\""
19+
"test-unit": "mocha \"./out/**/*.test.js\"",
20+
"test-unit:coverage": "npm run compile && c8 mocha \"./out/**/*.test.js\"",
21+
"test:coverage": "npm run test-unit:coverage",
22+
"coverage:report": "c8 report --reporter=html --reporter=text"
2023
},
2124
"dependencies": {
2225
"@aws/language-server-runtimes": "^0.2.90",
@@ -31,6 +34,7 @@
3134
"@types/mocha": "^10.0.9",
3235
"@types/mock-fs": "^4.13.4",
3336
"@types/sinon": "^17.0.3",
37+
"c8": "^10.1.2",
3438
"chai": "^4.3.7",
3539
"chai-as-promised": "^7.1.1",
3640
"mock-fs": "^5.2.0",

server/hello-world-lsp/.c8rc.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"all": true,
3+
"check-coverage": false,
4+
"reporter": ["text", "html", "lcov"],
5+
"reports-dir": "coverage",
6+
"include": ["src/**/*.ts"],
7+
"exclude": ["src/**/*.test.ts", "src/**/*.spec.ts", "src/**/test/**", "src/**/*TestConstants.ts", "src/**/*.d.ts"],
8+
"branches": 70,
9+
"lines": 70,
10+
"functions": 70,
11+
"statements": 70
12+
}

server/hello-world-lsp/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
"lint": "npm run lint:src && npm run lint:bundle:webworker",
99
"lint:bundle:webworker": "webpack --config webpack.lint.config.js && eslint bundle/hello-world-lsp-webworker.js # Verify compatibility with web runtime target",
1010
"lint:src": "eslint src/ --ext .ts,.tsx",
11-
"test": "ts-mocha -b \"./src/**/*.test.ts\""
11+
"test": "ts-mocha -b \"./src/**/*.test.ts\"",
12+
"test:coverage": "c8 ts-mocha -b \"./src/**/*.test.ts\"",
13+
"coverage:report": "c8 report --reporter=html --reporter=text"
1214
},
1315
"dependencies": {
1416
"@aws/language-server-runtimes": "^0.2.90",
1517
"vscode-languageserver": "^9.0.1"
1618
},
1719
"devDependencies": {
20+
"c8": "^10.1.2",
1821
"ts-loader": "^9.4.4",
1922
"webpack": "^5.94.0",
2023
"webpack-cli": "^6.0.1"

0 commit comments

Comments
 (0)