Skip to content

Commit

Permalink
chore: improve coverage transparency (#612)
Browse files Browse the repository at this point in the history
* chore: remove default coverage file

* chore: remove c8 comments

* chore: add build for dynamic coverage

* chore: fix windows and mac

* docs: add coverage disclaimer

* chore: few adjustments

* ci: restaure defineConfigs test

* chore: ensure clean build

* docs: update link to coverage discussion
  • Loading branch information
wellwelwel authored Jul 27, 2024
1 parent cf22b0a commit 219f075
Show file tree
Hide file tree
Showing 23 changed files with 204 additions and 70 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ node_modules
/test-src
/test-tests
/test-before-and-after-each.json
.nycrc.json
30 changes: 0 additions & 30 deletions .nycrc

This file was deleted.

34 changes: 34 additions & 0 deletions .nycrc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# ☔️ Coverage

## Specific cases and approaches don't generate coverage reports properly

### Different behaviors due to platform versions

- Compatibility with `c8` starts with [**Node.js** `v18`](https://github.com/bcoe/c8/blob/ff146b4dde004c62651b57c33cedd8353c94c423/package.json#L67).
- Compatibility with `monocart-coverage-reports` starts with [**Node.js** `v18`](https://github.com/cenfun/monocart-coverage-reports/issues/60).

### Different behaviors due to **Deno** and **Bun** platforms

- At the moment, there is no way to generate the coverage report for them using `c8` or `monocart-coverage-reports`.

### process-based

> E.g., `process.on`, `process.once`, `pid`, etc.
- I intend to do more research.

---

### Conclusion

The choice not to consider these topics in the coverage comes from the fact that it isn't possible, not that they are ignored. For example, even if exhaustive tests are created for **Node.js** `v8`, there is no way to generate the coverage report for these tests.

> Similarly, there are specific tests for **Bun** and **Deno** that don't generate coverage reports.
- In order to keep the minimum possible number of coverage instructions within the code, I have concentrated the cases of impossible coverage in individual files.

> [!NOTE]
>
> If you don't agree with any of these not covered topics, please feel free to comment. I'm totally open to discussions and opinions.
>
> - In disagreements, please see and discuss through [discussion#613](https://github.com/wellwelwel/poku/discussions/613).
19 changes: 19 additions & 0 deletions .nycrc/_.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Global setttings
*
* The final compatibility file is generated by merging this file with the file based on the current operating system.
* You can see the compilation process at: ./tools/biuld/c8-file.ts and generate it by running `npm run pretest:c8`, then check the generated file at ./.nycrc.json.
*/
{
"clean": true,
"all": true,
"include": ["src/**"],
"reporter": ["v8", "codecov", "console-details"],
"branches": 95,
"statements": 95,
"lines": 95,
"functions": 95,
"checkCoverage": true,
"import": ["tsx"],
"extension": [".ts"]
}
21 changes: 21 additions & 0 deletions .nycrc/darwin.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Global setttings
*
* In addition to the ./README.md in this directory, each deleted file explains the reason for its deletion.
* Please note that excluded files aren't ignored, but that the coverage report can't be properly generated.
*/
{
"exclude": [
"src/@types", // Typings exports only
"src/polyfills", // They involve compatibility between older versions of platforms or assist in cross-platform compatibility
"src/modules/helpers/create-service.ts", // Varies of platform (Node.js, Bun, and Deno)
"src/modules/helpers/container.ts", // On macOS, the memory consumption and installation time plus the processing required cause constant failures due to timeouts or resource limit usage.
"src/modules/helpers/get-pids.ts", // 100% Process-based
"src/modules/helpers/kill.ts", // 100% Process-based
"src/services/container.ts", // On macOS, the memory consumption and installation time plus the processing required cause constant failures due to timeouts or resource limit usage.
"src/parsers/get-runner.ts", // Varies of platform (npm, yarn, bun, deno, pnpm, etc.)
"src/parsers/get-runtime.ts", // Varies of platform (Node.js, Bun, and Deno)
"src/services/pid.ts", // 100% Process-based
"src/bin" // TODO: Remove after expose `inpectCLI` and `watchCLI` methods.
]
}
19 changes: 19 additions & 0 deletions .nycrc/linux.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Global setttings
*
* In addition to the ./README.md in this directory, each deleted file explains the reason for its deletion.
* Please note that excluded files aren't ignored, but that the coverage report can't be properly generated.
*/
{
"exclude": [
"src/@types", // Typings exports only
"src/polyfills", // They involve compatibility between older versions of platforms or assist in cross-platform compatibility
"src/modules/helpers/create-service.ts", // Varies of platform (Node.js, Bun, and Deno)
"src/modules/helpers/get-pids.ts", // 100% Process-based
"src/modules/helpers/kill.ts", // 100% Process-based
"src/parsers/get-runner.ts", // Varies of platform (Node.js, Bun, and Deno)
"src/parsers/get-runtime.ts", // Varies of platform (Node.js, Bun, and Deno)
"src/services/pid.ts", // 100% Process-based
"src/bin" // TODO: Remove after expose `inpectCLI` and `watchCLI` methods.
]
}
21 changes: 21 additions & 0 deletions .nycrc/win32.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Global setttings
*
* In addition to the ./README.md in this directory, each deleted file explains the reason for its deletion.
* Please note that excluded files aren't ignored, but that the coverage report can't be properly generated.
*/
{
"exclude": [
"src/@types", // Typings exports only
"src/polyfills", // They involve compatibility between older versions of platforms or assist in cross-platform compatibility
"src/modules/helpers/create-service.ts", // Varies of platform (Node.js, Bun, and Deno)
"src/modules/helpers/container.ts", // On Windows-based GitHub Actions, it's not possible to pull images based on manifest windows/amd64
"src/modules/helpers/get-pids.ts", // 100% Process-based
"src/modules/helpers/kill.ts", // 100% Process-based
"src/services/container.ts", // On Windows-based GitHub Actions, it's not possible to pull images based on manifest windows/amd64
"src/parsers/get-runner.ts", // Varies of platform (Node.js, Bun, and Deno)
"src/parsers/get-runtime.ts", // Varies of platform (Node.js, Bun, and Deno)
"src/services/pid.ts", // 100% Process-based
"src/bin" // TODO: Remove after expose `inpectCLI` and `watchCLI` methods.
]
}
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/CHANGELOG.md
/website
/fixtures/sintax
/.nycrc.json
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Enjoying **Poku**? Give him a star to show your support 🌟

[![NPM Downloads](https://img.shields.io/npm/v/poku.svg?label=&color=70a1ff&logo=npm&logoColor=white)](https://www.npmjs.com/package/poku)
[![NPM Downloads](https://img.shields.io/npm/dt/poku.svg?label=&logo=npm&logoColor=white&color=45aaf2)](https://www.npmjs.com/package/poku)
[![Coverage](https://img.shields.io/codecov/c/github/wellwelwel/poku?label=&logo=codecov&logoColor=white&color=98cc00)](https://app.codecov.io/github/wellwelwel/poku)<br />
[![Coverage](https://img.shields.io/codecov/c/github/wellwelwel/poku?label=&logo=codecov&logoColor=white&color=98cc00)](https://github.com/wellwelwel/poku/tree/main/.nycrc)<br />
[![GitHub Workflow Status (Linux)](https://img.shields.io/github/actions/workflow/status/wellwelwel/poku/ci_coverage-linux.yml?event=push&label=&branch=main&logo=ubuntu&logoColor=8897a9&color=dfe4ea)](https://github.com/wellwelwel/poku/actions/workflows/ci_coverage-linux.yml?query=branch%3Amain)
[![GitHub Workflow Status (OSX)](https://img.shields.io/github/actions/workflow/status/wellwelwel/poku/ci_coverage-osx.yml?event=push&label=&branch=main&logo=apple&logoColor=8897a9&color=dfe4ea)](https://github.com/wellwelwel/poku/actions/workflows/ci_coverage-osx.yml?query=branch%3Amain)
[![GitHub Workflow Status (Windows)](https://img.shields.io/github/actions/workflow/status/wellwelwel/poku/ci_coverage-windows.yml?event=push&label=&branch=main&logo=data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHZpZXdCb3g9IjAgMCAxMjggMTI4IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjx0aXRsZT5XaW5kb3dzIDExPC90aXRsZT48cGF0aCBmaWxsPSIjODg5N2E5IiBkPSJNMTI2IDEuNjM3bC02NyA5LjgzNHY0OS44MzFsNjctLjUzNHpNMS42NDcgNjYuNzA5bC4wMDMgNDIuNDA0IDUwLjc5MSA2Ljk4My0uMDQtNDkuMDU3em01Ni44Mi42OGwuMDk0IDQ5LjQ2NSA2Ny4zNzYgOS41MDkuMDE2LTU4Ljg2M3pNMS42MSAxOS4yOTdsLjA0NyA0Mi4zODMgNTAuNzkxLS4yODktLjAyMy00OS4wMTZ6Ij48L3BhdGg+PC9zdmc+&color=dfe4ea)](https://github.com/wellwelwel/poku/actions/workflows/ci_coverage-windows.yml?query=branch%3Amain)
Expand Down
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
"test:bun:parallel": "bun src/bin/index.ts --bun -p test/unit test/integration test/e2e",
"test:deno:sequential": "tsx src/bin/index.ts --deno --deno-allow=all --deno-cjs ci/test/unit ci/test/integration ci/test/e2e",
"test:deno:parallel": "tsx src/bin/index.ts --deno --deno-allow=all --deno-cjs -p ci/test/unit ci/test/integration ci/test/e2e",
"pretest:c8": "tsx tools/build/c8-file.ts",
"test:c8": "c8 --experimental-monocart tsx test/c8.test.ts",
"posttest:c8": "rm -rf ./.nycrc.json",
"test:ci": "tsx test/ci.test.ts",
"test:ci:node": "FILTER='node-' npm run test:ci",
"test:ci:bun": "FILTER='bun-' npm run test:ci",
Expand All @@ -49,7 +51,7 @@
"clear": "rm -rf lib ci coverage .temp test-src test-tests",
"prebuild": "npm run clear",
"build": "tsc && tsc -p tsconfig.test.json",
"postbuild": "tsx tools/compatibility/node.ts && cp fixtures/server/package.json ci/fixtures/server/package.json && rm -f ./lib/@types/*.js ./lib/bin/*.ts && npm run build:deno && chmod +x lib/bin/index.js",
"postbuild": "tsx tools/compatibility/node.ts && tsx tools/compatibility/comments.ts && cp fixtures/server/package.json ci/fixtures/server/package.json && rm -f ./lib/@types/*.js ./lib/bin/*.ts && npm run build:deno && chmod +x lib/bin/index.js",
"build:deno": "tsc -p tsconfig.mjs.json",
"postbuild:deno": "tsx tools/build/check-deno-polyfill.ts",
"lint": "npx @biomejs/biome lint && prettier --check .",
Expand All @@ -62,6 +64,7 @@
"@biomejs/biome": "1.8.3",
"@types/node": "^20.14.12",
"c8": "^10.1.2",
"jsonc.min": "^1.0.0",
"monocart-coverage-reports": "^2.9.3",
"packages-update": "^2.0.0",
"prettier": "^3.3.3",
Expand Down
4 changes: 2 additions & 2 deletions src/modules/essentials/poku.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import { isQuiet } from '../../parsers/output.js';
import { fileResults, finalResults } from '../../configs/files.js';
import { indentation } from '../../configs/indentation.js';

/* c8 ignore next 3 */
/* c8 ignore next 3 */ // Process-based
export const onSigint = () => {
process.stdout.write('\u001B[?25h');
};

/* c8 ignore next */
/* c8 ignore next */ // Process-based
process.once('SIGINT', onSigint);

export async function poku(
Expand Down
2 changes: 2 additions & 0 deletions src/modules/helpers/exit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ export const exit = (code: Code, quiet?: boolean) => {
process.exit(code === 0 ? 0 : 1);
};

/* c8 ignore next 4 */ // Unknown external error
process.on('unhandledRejection', (reason) => {
console.error('unhandledRejection', reason);
process.exit(1);
});

/* c8 ignore next 4 */ // Unknown external error
process.on('uncaughtException', (err) => {
console.error('uncaughtException', err);
process.exit(1);
Expand Down
1 change: 0 additions & 1 deletion src/modules/helpers/list-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export const getAllFiles = async (
const fullPath = join(dirPath, file);
const stat = await fsStat(fullPath);

/* c8 ignore next 6 */
if (
fullPath.indexOf('node_modules') !== -1 ||
fullPath.indexOf('.git') === 0
Expand Down
3 changes: 0 additions & 3 deletions src/modules/helpers/wait-for.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const checkPort = (port: number, host: string): Promise<boolean> =>

/** Wait until the defined milliseconds. */
export const sleep = (milliseconds: number): Promise<void> => {
/* c8 ignore next 3 */
if (!Number.isInteger(milliseconds)) {
throw new Error('Milliseconds must be an integer.');
}
Expand All @@ -39,7 +38,6 @@ export const waitForExpectedResult = async (
const interval = options?.interval || 100;
const timeout = options?.timeout || 60000;

/* c8 ignore start */
if (typeof callback !== 'function') {
throw new Error('Callback must be a function.');
}
Expand All @@ -55,7 +53,6 @@ export const waitForExpectedResult = async (
if (!Number.isInteger(delay)) {
throw new Error('Delay must be an integer.');
}
/* c8 ignore stop */

await sleep(delay);

Expand Down
2 changes: 1 addition & 1 deletion src/parsers/assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const parseResultType = (type?: unknown): string => {
return Array.from(value).map(recurse);
}

/* c8 ignore start */
/* c8 ignore start */ // Platform version
if (value instanceof Map) {
return recurse(
!nodeVersion || nodeVersion >= 12
Expand Down
6 changes: 3 additions & 3 deletions src/services/assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const processAssert = async (
exit(1);
}

// Non-assertion errors
/* c8 ignore next */ // Unknown external error
throw error;
}
};
Expand Down Expand Up @@ -383,7 +383,7 @@ export const createAssert = (nodeAssert: typeof assert) => {
regExp: RegExp,
message?: ProcessAssertionOptions['message']
): void => {
/* c8 ignore next 3 */
/* c8 ignore next 3 */ // Platform version
if (typeof nodeVersion === 'number' && nodeVersion < 12) {
throw new Error('match is available from Node.js 12 or higher');
}
Expand All @@ -401,7 +401,7 @@ export const createAssert = (nodeAssert: typeof assert) => {
regExp: RegExp,
message?: ProcessAssertionOptions['message']
): void => {
/* c8 ignore next 3 */
/* c8 ignore next 3 */ // Platform version
if (typeof nodeVersion === 'number' && nodeVersion < 12) {
throw new Error('doesNotMatch is available from Node.js 12 or higher');
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export class DockerCompose {
this.envFile = envFile;
this.projectName = projectName;
this.detach = detach;
this.cwd = cwd ? sanitizePath(cwd) : undefined;
this.cwd = cwd ? sanitizePath(cwd) /* c8 ignore next */ : undefined;
this.verbose = verbose;
}

Expand Down
5 changes: 2 additions & 3 deletions src/services/run-test-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const runTestFile = async (
const runtime = runtimeOptions.shift()!;
const runtimeArguments = [
...runtimeOptions,
/* c8 ignore next 5 */
/* c8 ignore next 5 */ // Varies Platform
configs?.deno?.cjs === true ||
(Array.isArray(configs?.deno?.cjs) &&
configs.deno.cjs.some((ext) => filePath.includes(ext)))
Expand Down Expand Up @@ -95,7 +95,7 @@ export const runTestFile = async (
resolve(result);
});

/* c8 ignore start */
/* c8 ignore next 10 */ // Unknown external error
child.on('error', (err) => {
end = hrtime(start);

Expand All @@ -106,6 +106,5 @@ export const runTestFile = async (

resolve(false);
});
/* c8 ignore stop */
});
};
12 changes: 0 additions & 12 deletions src/services/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ export class Watcher {
this.callback(filePath, eventType);
});

/* c8 ignore next 3 */
watcher.on('error', () => {
return;
});

this.fileWatchers.set(filePath, watcher);
}

Expand Down Expand Up @@ -65,16 +60,10 @@ export class Watcher {
if (stats.isDirectory()) {
await this.watchDirectory(fullPath);
}
/* c8 ignore next */
} catch {}
}
});

/* c8 ignore next 3 */
watcher.on('error', () => {
return;
});

this.dirWatchers.set(dir, watcher);

const entries = await readdir(dir, { withFileTypes: true });
Expand All @@ -99,7 +88,6 @@ export class Watcher {
} else {
this.watchFile(this.rootDir);
}
/* c8 ignore next */
} catch {}
}

Expand Down
Loading

0 comments on commit 219f075

Please sign in to comment.