Skip to content

Commit 808c8b9

Browse files
committed
Ignore TS constructs for CC
1 parent 5fdb235 commit 808c8b9

File tree

4 files changed

+58
-10
lines changed

4 files changed

+58
-10
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"lint:f": "eslint src/ test/ --ext .ts --fix",
2020
"prepare": "husky install",
2121
"coverage": "npm run coverage:generate && npx http-server coverage",
22-
"coverage:generate": "npm run build && npm run coverage:unit && npm run coverage:bdd && npm run coverage:report",
22+
"coverage:generate": "npm run build && npm run coverage:ignore && npm run coverage:unit && npm run coverage:bdd && npm run coverage:report",
23+
"coverage:ignore": "node scripts/coverage-ignore.js",
2324
"coverage:check": "npm run build && npm run coverage:unit && npm run coverage:bdd && nyc report --check-coverage",
2425
"coverage:unit": "nyc --silent npm run test:run:unit && SCRAMJET_LOG=1 nyc --silent --no-clean npm run test:run:unit -- -m \"trace does not throw\"",
2526
"coverage:bdd": "nyc --silent --no-clean npm run test:run:bdd",

scripts/coverage-ignore.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env node
2+
// Ignore TypeScript constructs (like decorator local functions) in coverage reports.
3+
4+
const { join } = require("path");
5+
const { readFileSync, writeFileSync } = require("fs");
6+
7+
const files = [
8+
"build/src/streams/data-stream.js",
9+
"build/src/streams/string-stream.js",
10+
"build/src/streams/proxies/stream-node-writable-proxy.js"
11+
];
12+
13+
const replacements = [
14+
"var __decorate = (",
15+
"var __metadata = (",
16+
"var __asyncValues = (",
17+
"var __importDefault = (",
18+
[/__decorate\(\[/g, "__decorate(["]
19+
];
20+
21+
for (const file of files) {
22+
const filePath = join(__dirname, "..", file);
23+
const fileContents = readFileSync(filePath, "utf8");
24+
25+
console.log(`coverage-ignore: Processing ${filePath}`);
26+
27+
let newContents = fileContents;
28+
29+
for (const replacement of replacements) {
30+
if (Array.isArray(replacement)) {
31+
newContents = newContents.replace(replacement[0], `/* istanbul ignore next */\n${replacement[1]}`);
32+
} else {
33+
newContents = newContents.replace(replacement, `/* istanbul ignore next */\n${replacement}`);
34+
}
35+
}
36+
37+
writeFileSync(filePath, newContents);
38+
}

src/streams/data-stream.ts

+17-9
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,12 @@ export class DataStream<IN, OUT = IN> implements BaseStream<IN, OUT>, AsyncItera
225225
onChunkCallback: async (chunk: OUT) => {
226226
const items = await callback(chunk, ...args);
227227

228-
for await (const item of items) {
229-
await newStream.ifca.write(item);
228+
/* istanbul ignore next */
229+
// eslint-disable-next-line no-lone-blocks
230+
{
231+
for await (const item of items) {
232+
await newStream.ifca.write(item);
233+
}
230234
}
231235
},
232236
onEndCallback: async () => {
@@ -577,15 +581,19 @@ export class DataStream<IN, OUT = IN> implements BaseStream<IN, OUT>, AsyncItera
577581
await this.corked.promise;
578582
}
579583

580-
for await (const data of iterable) {
581-
if (this.corked) {
582-
await this.corked.promise;
583-
}
584+
/* istanbul ignore next */
585+
// eslint-disable-next-line no-lone-blocks
586+
{
587+
for await (const data of iterable) {
588+
if (this.corked) {
589+
await this.corked.promise;
590+
}
584591

585-
const drain = this.ifca.write(data);
592+
const drain = this.ifca.write(data);
586593

587-
if (drain instanceof Promise) {
588-
await drain;
594+
if (drain instanceof Promise) {
595+
await drain;
596+
}
589597
}
590598
}
591599

tsconfig.build.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"extends": "./tsconfig.json",
33
"compilerOptions": {
44
"sourceMap": false,
5+
"removeComments": false,
56
"outDir": "build"
67
},
78
"watchOptions": {

0 commit comments

Comments
 (0)