Skip to content

Commit

Permalink
ci: improve coverage (#264)
Browse files Browse the repository at this point in the history
* ci: improve coverage

* ci: fix c8 false positives

* refactor: move tests to their proper categories

* chore: remove tea

* ci: revert c8 cobertura

* chore: improve test scripts
  • Loading branch information
wellwelwel authored May 19, 2024
1 parent 65a740c commit ea5ed38
Show file tree
Hide file tree
Showing 37 changed files with 139 additions and 72 deletions.
19 changes: 8 additions & 11 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
{
"all": true,
"include": ["src/**"],
"exclude": [
"src/@types/**",
"fixtures",
"test",
"tools",
"website",
"ci",
"lib"
],
"exclude": ["ci", "fixtures", "lib", "test", "tools", "website"],
"extension": ["ts"],
"reporter": ["text", "lcov"],
"clean": true
"reporter": ["text", "lcov", "cobertura"],
"clean": true,
"branches": 85,
"statements": 90,
"lines": 90,
"functions": 95,
"checkCoverage": true
}
37 changes: 34 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,43 @@ We can discuss design of API and implementation ideas.

### General (recommended)

#### Sequential and Parallel

```sh
npm run test # Test with the locally installed Node.js version
npm run test:bun # Test with the locally installed Bun version
```

#### Sequential

```sh
npm run test # Test with the installed Node.js version
npm run test:options # Test with the installed Node.js version using CLI options
npm run test:bun # Test with the installed Bun version
npm run test:sequential # Test with the locally installed Node.js version
npm run test:bun:sequential # Test with the locally installed Bun version
```

> Pass custom flags using `--`, for example:
>
> ```sh
> npm run test:sequential -- --debug --fail-fast
> ```
>
> - Same for **Bun**
#### Parallel
```sh
npm run test:parallel # Test with the locally installed Node.js version
npm run test:bun:parallel # Test with the locally installed Bun version
```
> Pass custom flags using `--`, for example:
>
> ```sh
> npm run test:parallel -- --concurrency=5 --fail-fast
> ```
>
> - Same for **Bun**
### Coverage
Methods that vary according to **Node.js** version, platform or OS aren't tested against the coverage rate.
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
"description": "🐷 Poku makes testing easy for Node.js, Bun & Deno at the same time.",
"main": "./lib/index.js",
"scripts": {
"test": "tsx src/bin/index.ts --parallel --include=\"test/unit,test/integration,test/e2e\"",
"test:options": " tsx src/bin/index.ts --parallel --concurrency=\"4\" --fast-fail --debug --exclude=\".bak\" --kill-port=\"4000\" --kill-range=\"4000-4001\" --include=\"test/unit,test/integration,test/e2e\"",
"test:bun": "bun src/bin/index.ts --platform=bun --include=\"test/unit,test/integration,test/e2e\"",
"test": "npm run test:parallel && npm run test:sequential",
"test:bun": "npm run test:bun:parallel && npm run test:bun:sequential",
"test:sequential": "tsx src/bin/index.ts --include=\"test/unit,test/integration,test/e2e\"",
"test:parallel": "npm run test:sequential -- --parallel",
"test:bun:sequential": "bun src/bin/index.ts --platform=\"bun\" --include=\"test/unit,test/integration,test/e2e\"",
"test:bun:parallel": "npm run test:bun:sequential -- --parallel",
"test:c8:sequential": "c8 tsx src/bin/index.ts --include=\"test/unit,test/integration,test/e2e\"",
"test:c8:parallel": "c8 tsx src/bin/index.ts --parallel --include=\"test/unit,test/integration,test/e2e\"",
"test:c8:sequential:options": "c8 tsx src/bin/index.ts --fast-fail --debug --exclude=\".bak\" --kill-port=\"4000\" --kill-range=\"4000-4001\" --include=\"test/unit,test/integration,test/e2e\"",
Expand Down
4 changes: 4 additions & 0 deletions src/@types/background-process.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* c8 ignore start */

import { Runner } from './runner.js';
import { Configs } from './poku.js';

Expand Down Expand Up @@ -48,3 +50,5 @@ export type StartServiceOptions = {
} & BackgroundProcessOptions;

export type End = (port?: number | number[]) => Promise<void>;

/* c8 ignore stop */
4 changes: 4 additions & 0 deletions src/@types/code.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
/* c8 ignore start */

export type Code = 0 | 1;

/* c8 ignore stop */
9 changes: 9 additions & 0 deletions src/@types/list-files.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* c8 ignore start */

export type Configs = {
/**
* Filter by path to match only the files that should be performed.
Expand All @@ -12,3 +14,10 @@ export type Configs = {
*/
exclude?: RegExp | RegExp[];
};

export type FileResults = {
success: string[];
fail: string[];
};

/* c8 ignore stop */
4 changes: 4 additions & 0 deletions src/@types/poku.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* c8 ignore start */

import type { Configs as ListFilesConfigs } from './list-files.js';

export type Configs = {
Expand Down Expand Up @@ -92,3 +94,5 @@ export type Configs = {
*/
afterEach?: () => unknown | Promise<unknown>;
} & ListFilesConfigs;

/* c8 ignore stop */
4 changes: 4 additions & 0 deletions src/@types/runner.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
/* c8 ignore start */

export type Runner = 'npm' | 'bun' | 'deno' | 'yarn' | 'pnpm';

/* c8 ignore stop */
1 change: 1 addition & 0 deletions src/bin/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#! /usr/bin/env node

/* c8 ignore start */

import { escapeRegExp } from '../modules/list-files.js';
import { getArg, getLastParam, hasArg } from '../helpers/get-arg.js';
import { kill, poku } from '../index.js';
Expand Down
2 changes: 2 additions & 0 deletions src/configs/each.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* c8 ignore start */

export type Control = {
pause: () => void;
continue: () => void;
Expand Down Expand Up @@ -29,4 +30,5 @@ export const each: {
test: true,
},
};

/* c8 ignore stop */
10 changes: 10 additions & 0 deletions src/configs/files.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* c8 ignore start */

import { FileResults } from '../@types/list-files.js';

export const fileResults: FileResults = {
success: [],
fail: [],
};

/* c8 ignore stop */
4 changes: 4 additions & 0 deletions src/helpers/indentation.ts → src/configs/indentation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
/* c8 ignore start */

export const indentation = {
test: ' ',
stdio: ' ',
};

/* c8 ignore stop */
2 changes: 1 addition & 1 deletion src/helpers/find-file.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* c8 ignore start */
import { EOL } from 'node:os';

/* c8 ignore start */
export const findFile = (error: Error) => {
const stackLines = error.stack?.split(EOL) || [];

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/format.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* c8 ignore start */
import { padStart } from './pad.js';
import { padStart } from '../polyfills/pad.js';

export const backgroundColor = {
white: 7,
Expand Down
2 changes: 2 additions & 0 deletions src/helpers/get-arg.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* c8 ignore start */
import process from 'node:process';

const [, , ...args] = process.argv;
Expand All @@ -15,3 +16,4 @@ export const hasArg = (arg: string): boolean =>
export const getLastParam = (): string => {
return args[args.length - 1];
};
/* c8 ignore stop */
2 changes: 2 additions & 0 deletions src/helpers/logs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* c8 ignore start */
import { Configs } from '../@types/poku.js';

export const isQuiet = (configs?: Configs): boolean =>
typeof configs?.quiet === 'boolean' && Boolean(configs?.quiet);

export const isDebug = (configs?: Configs): boolean => Boolean(configs?.debug);
/* c8 ignore stop */
2 changes: 2 additions & 0 deletions src/helpers/parseAsssetion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { hr } from './hr.js';
import { findFile } from './find-file.js';
import { each } from '../configs/each.js';

/* c8 ignore start */
export type ParseAssertionOptions = {
message?: string | Error;
defaultMessage?: string;
Expand All @@ -15,6 +16,7 @@ export type ParseAssertionOptions = {
throw?: boolean;
hideDiff?: boolean;
};
/* c8 ignore stop */

export const parseAssertion = async (
cb: () => void | Promise<void>,
Expand Down
3 changes: 2 additions & 1 deletion src/modules/create-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ const backgroundProcess = (
shell: isWindows,
cwd: options?.cwd
? sanitizePath(path.normalize(options.cwd))
: undefined,
: /* c8 ignore next */
undefined,
env: process.env,
/* c8 ignore next */
detached: !isWindows,
Expand Down
2 changes: 1 addition & 1 deletion src/modules/describe.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* c8 ignore start */
import { EOL } from 'node:os';
import { format, backgroundColor } from '../helpers/format.js';

/* c8 ignore start */
export type DescribeOptions = {
/**
* Skips a line before to console it.
Expand Down
3 changes: 3 additions & 0 deletions src/modules/each.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/* c8 ignore next */
import { Control, each } from '../configs/each.js';

/* c8 ignore start */
type EachOptions = {
immediate?: boolean;
test?: boolean;
assert?: boolean;
};
/* c8 ignore stop */

/**
* - ✅ Handling **global** and **external** services (_preparing a database, for example_)
Expand Down
7 changes: 4 additions & 3 deletions src/modules/poku.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* c8 ignore start */

/**
* Both CLI, API, noExit, sequential and parallel runs are strictly tested, but these tests use deep child process for it
*/

/* c8 ignore start */
import { EOL } from 'node:os';
import { Code } from '../@types/code.js';
import { Configs } from '../@types/poku.js';
Expand All @@ -12,8 +13,8 @@ import { exit } from './exit.js';
import { format } from '../helpers/format.js';
import { isQuiet } from '../helpers/logs.js';
import { hr } from '../helpers/hr.js';
import { fileResults } from '../services/run-test-file.js';
import { indentation } from '../helpers/indentation.js';
import { fileResults } from '../configs/files.js';
import { indentation } from '../configs/indentation.js';

export async function poku(
targetPaths: string | string[],
Expand Down
3 changes: 3 additions & 0 deletions src/modules/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* c8 ignore next */
import { each } from '../configs/each.js';

export async function test(cb: () => Promise<unknown>): Promise<void>;
Expand All @@ -7,6 +8,7 @@ export async function test(
): Promise<void> {
if (typeof each.before.cb === 'function' && each.before.test) {
const beforeResult = each.before.cb();
/* c8 ignore next */
if (beforeResult instanceof Promise) await beforeResult;
}

Expand All @@ -16,6 +18,7 @@ export async function test(

if (typeof each.after.cb === 'function' && each.after.test) {
const afterResult = each.after.cb();
/* c8 ignore next */
if (afterResult instanceof Promise) await afterResult;
}
}
5 changes: 3 additions & 2 deletions src/helpers/pad.ts → src/polyfills/pad.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* c8 ignore start */

/**
* Custom implementations of `padStart` for compatibility with Node.js version 6.
*/

/* c8 ignore start */
export const padStart = (
str: string,
targetLength: number,
Expand All @@ -21,4 +21,5 @@ export const padStart = (

return fullPadString + str;
};

/* c8 ignore stop */
17 changes: 2 additions & 15 deletions src/services/run-test-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,13 @@ import path from 'node:path';
import { EOL } from 'node:os';
import { spawn } from 'node:child_process';
import { isWindows, runner } from '../helpers/runner.js';
import { indentation } from '../helpers/indentation.js';
import { indentation } from '../configs/indentation.js';
import { format } from '../helpers/format.js';
import { Configs } from '../@types/poku.js';
import { isDebug, isQuiet } from '../helpers/logs.js';
import { removeConsecutiveRepeats } from '../helpers/remove-repeats.js';
import { beforeEach, afterEach } from './each.js';

/* c8 ignore start */
export type FileResults = {
success: string[];
fail: string[];
};
/* c8 ignore stop */

/* c8 ignore start */
export const fileResults: FileResults = {
success: [],
fail: [],
};
/* c8 ignore stop */
import { fileResults } from '../configs/files.js';

export const runTestFile = (
filePath: string,
Expand Down
4 changes: 3 additions & 1 deletion src/services/run-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import process from 'node:process';
import { EOL } from 'node:os';
import path from 'node:path';
import { runner } from '../helpers/runner.js';
import { indentation } from '../helpers/indentation.js';
import { indentation } from '../configs/indentation.js';
import {
isFile as IS_FILE,
listFiles,
Expand All @@ -14,10 +14,12 @@ import { runTestFile } from './run-test-file.js';
import { Configs } from '../@types/poku.js';
import { isQuiet } from '../helpers/logs.js';

/* c8 ignore start */
export const results = {
success: 0,
fail: 0,
};
/* c8 ignore stop */

export const runTests = async (
dir: string,
Expand Down
6 changes: 0 additions & 6 deletions tea.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import {
test,
describe,
startScript,
} from '../../../src/index.js';
import { legacyFetch } from '../../helpers/legacy-fetch.test.js';
import { ext, isProduction } from '../../helpers/capture-cli.test.js';
import { getRuntime } from '../../../src/helpers/get-runtime.js';
} from '../../src/index.js';
import { legacyFetch } from '../helpers/legacy-fetch.test.js';
import { ext, isProduction } from '../helpers/capture-cli.test.js';
import { getRuntime } from '../../src/helpers/get-runtime.js';

(async () => {
const runtime = getRuntime();
Expand Down
Loading

0 comments on commit ea5ed38

Please sign in to comment.