Skip to content

Commit 23d0b92

Browse files
authored
ci(coverage): add tests (#440)
* ci(coverage): add tests * ci: debug * ci: debug * chore: remove comments * ci: remove debug
1 parent 1ab72ed commit 23d0b92

21 files changed

+277
-96
lines changed

src/helpers/parse-assertion.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1+
/* c8 ignore next */
2+
import type { ParseAssertionOptions } from '../@types/assert.js';
13
import { cwd as processCWD, env, exit } from 'node:process';
24
import path from 'node:path';
35
import assert from 'node:assert';
46
import { format } from './format.js';
57
import { hr } from './hr.js';
68
import { findFile } from './find-file.js';
7-
/* c8 ignore next */
89
import { each } from '../configs/each.js';
9-
/* c8 ignore next */
1010
import { indentation } from '../configs/indentation.js';
1111
import { fromEntries, entries } from '../polyfills/object.js';
1212
import { nodeVersion } from './get-runtime.js';
1313
import { write } from './logs.js';
14-
/* c8 ignore next */
15-
import type { ParseAssertionOptions } from '../@types/assert.js';
1614

1715
const cwd = processCWD();
1816

@@ -93,6 +91,7 @@ export const parseAssertion = async (
9391
isPoku &&
9492
!indentation.hasDescribe &&
9593
!indentation.hasIt &&
94+
/* c8 ignore next */ // c8 bug?
9695
!indentation.hasTest
9796
? /* c8 ignore next */
9897
`${preIdentation}${format(`${format(`✔ ${options.message}`).bold()} ${format(`› ${FILE}`).success().dim()}`).success()}`

src/modules/assert-promise.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
/* c8 ignore next */
2+
import type { ParseAssertionOptions } from '../@types/assert.js';
13
import nodeAssert from 'node:assert';
24
import { parseAssertion } from '../helpers/parse-assertion.js';
35
import { nodeVersion } from '../helpers/get-runtime.js';
4-
/* c8 ignore next */
5-
import type { ParseAssertionOptions } from '../@types/assert.js';
66

77
const ok = async (
88
value: unknown,
@@ -144,7 +144,9 @@ function doesNotThrow(
144144
): Promise<void>;
145145
async function doesNotThrow(
146146
block: () => unknown,
147-
errorOrMessage?: nodeAssert.AssertPredicate | string | Error,
147+
errorOrMessage?:
148+
| nodeAssert.AssertPredicate
149+
| ParseAssertionOptions['message'],
148150
message?: ParseAssertionOptions['message']
149151
): Promise<void> {
150152
await parseAssertion(
@@ -210,17 +212,19 @@ async function throws(
210212

211213
function rejects(
212214
block: (() => Promise<unknown>) | Promise<unknown>,
213-
message?: string | Error
215+
message?: ParseAssertionOptions['message']
214216
): Promise<void>;
215217
function rejects(
216218
block: (() => Promise<unknown>) | Promise<unknown>,
217219
error: nodeAssert.AssertPredicate,
218-
message?: string | Error
220+
message?: ParseAssertionOptions['message']
219221
): Promise<void>;
220222
async function rejects(
221223
block: (() => Promise<unknown>) | Promise<unknown>,
222-
errorOrMessage?: nodeAssert.AssertPredicate | string | Error,
223-
message?: string | Error
224+
errorOrMessage?:
225+
| nodeAssert.AssertPredicate
226+
| ParseAssertionOptions['message'],
227+
message?: ParseAssertionOptions['message']
224228
): Promise<void> {
225229
await parseAssertion(
226230
async () => {
@@ -247,17 +251,19 @@ async function rejects(
247251

248252
function doesNotReject(
249253
block: (() => Promise<unknown>) | Promise<unknown>,
250-
message?: string | Error
254+
message?: ParseAssertionOptions['message']
251255
): Promise<void>;
252256
function doesNotReject(
253257
block: (() => Promise<unknown>) | Promise<unknown>,
254258
error: nodeAssert.AssertPredicate,
255-
message?: string | Error
259+
message?: ParseAssertionOptions['message']
256260
): Promise<void>;
257261
async function doesNotReject(
258262
block: (() => Promise<unknown>) | Promise<unknown>,
259-
errorOrMessage?: nodeAssert.AssertPredicate | string | Error,
260-
message?: string | Error
263+
errorOrMessage?:
264+
| nodeAssert.AssertPredicate
265+
| ParseAssertionOptions['message'],
266+
message?: ParseAssertionOptions['message']
261267
): Promise<void> {
262268
await parseAssertion(
263269
async () => {
@@ -338,5 +344,5 @@ export const assertPromise = Object.assign(
338344
fail,
339345
rejects,
340346
}
341-
/* c8 ignore next */
347+
/* c8 ignore next */ // c8 bug
342348
);

src/modules/assert.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
/* c8 ignore next */
2+
import type { ParseAssertionOptions } from '../@types/assert.js';
13
import nodeAssert from 'node:assert';
24
import { parseAssertion } from '../helpers/parse-assertion.js';
35
import { nodeVersion } from '../helpers/get-runtime.js';
4-
/* c8 ignore next */
5-
import type { ParseAssertionOptions } from '../@types/assert.js';
66

77
const ok = (
88
value: unknown,
@@ -136,7 +136,9 @@ function doesNotThrow(
136136
): void;
137137
function doesNotThrow(
138138
block: () => unknown,
139-
errorOrMessage?: nodeAssert.AssertPredicate | string | Error,
139+
errorOrMessage?:
140+
| nodeAssert.AssertPredicate
141+
| ParseAssertionOptions['message'],
140142
message?: ParseAssertionOptions['message']
141143
): void {
142144
parseAssertion(
@@ -202,17 +204,19 @@ function throws(
202204

203205
function rejects(
204206
block: (() => Promise<unknown>) | Promise<unknown>,
205-
message?: string | Error
207+
message?: ParseAssertionOptions['message']
206208
): Promise<void>;
207209
function rejects(
208210
block: (() => Promise<unknown>) | Promise<unknown>,
209211
error: nodeAssert.AssertPredicate,
210-
message?: string | Error
212+
message?: ParseAssertionOptions['message']
211213
): Promise<void>;
212214
async function rejects(
213215
block: (() => Promise<unknown>) | Promise<unknown>,
214-
errorOrMessage?: nodeAssert.AssertPredicate | string | Error,
215-
message?: string | Error
216+
errorOrMessage?:
217+
| nodeAssert.AssertPredicate
218+
| ParseAssertionOptions['message'],
219+
message?: ParseAssertionOptions['message']
216220
): Promise<void> {
217221
await parseAssertion(
218222
async () => {
@@ -239,17 +243,19 @@ async function rejects(
239243

240244
function doesNotReject(
241245
block: (() => Promise<unknown>) | Promise<unknown>,
242-
message?: string | Error
246+
message?: ParseAssertionOptions['message']
243247
): Promise<void>;
244248
function doesNotReject(
245249
block: (() => Promise<unknown>) | Promise<unknown>,
246250
error: nodeAssert.AssertPredicate,
247-
message?: string | Error
251+
message?: ParseAssertionOptions['message']
248252
): Promise<void>;
249253
async function doesNotReject(
250254
block: (() => Promise<unknown>) | Promise<unknown>,
251-
errorOrMessage?: nodeAssert.AssertPredicate | string | Error,
252-
message?: string | Error
255+
errorOrMessage?:
256+
| nodeAssert.AssertPredicate
257+
| ParseAssertionOptions['message'],
258+
message?: ParseAssertionOptions['message']
253259
): Promise<void> {
254260
await parseAssertion(
255261
async () => {
@@ -330,5 +336,5 @@ export const assert = Object.assign(
330336
fail,
331337
rejects,
332338
}
333-
/* c8 ignore next */
339+
/* c8 ignore next */ // c8 bug
334340
);

src/modules/create-service.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import process from 'node:process';
2-
import { spawn } from 'node:child_process';
3-
import { isWindows, runner, scriptRunner } from '../helpers/runner.js';
4-
import { normalize } from 'node:path';
5-
import { sanitizePath } from './list-files.js';
6-
import { kill } from './processes.js';
71
/* c8 ignore next */
82
import type {
93
End,
104
StartScriptOptions,
115
StartServiceOptions,
126
} from '../@types/background-process.js';
7+
import process from 'node:process';
8+
import { spawn } from 'node:child_process';
9+
import { isWindows, runner, scriptRunner } from '../helpers/runner.js';
10+
import { normalize } from 'node:path';
11+
import { sanitizePath } from './list-files.js';
12+
import { kill } from './processes.js';
1313
import { write } from '../helpers/logs.js';
1414

1515
const runningProcesses: Map<number, { end: End; port?: number | number[] }> =
@@ -37,10 +37,8 @@ const backgroundProcess = (
3737
stdio: ['inherit', 'pipe', 'pipe'],
3838
/* c8 ignore next */
3939
shell: isWindows,
40-
cwd: options?.cwd
41-
? sanitizePath(normalize(options.cwd))
42-
: /* c8 ignore next */
43-
undefined,
40+
/* c8 ignore next */
41+
cwd: options?.cwd ? sanitizePath(normalize(options.cwd)) : undefined,
4442
env: process.env,
4543
/* c8 ignore next */
4644
detached: !isWindows,
@@ -166,6 +164,7 @@ const backgroundProcess = (
166164
}
167165
}, options.startAfter);
168166
}
167+
/* c8 ignore next */ // c8 bug
169168
} catch {}
170169
});
171170

@@ -191,6 +190,7 @@ export const startService = async (
191190
);
192191
};
193192

193+
/* c8 ignore start */ // c8 bug
194194
/**
195195
*
196196
* Starts a script (package.json) or task (deno.json) in a background process
@@ -203,6 +203,8 @@ export const startScript = async (
203203
script: string,
204204
options?: StartScriptOptions
205205
): Promise<{ end: End }> => {
206+
/* c8 ignore stop */
207+
/* c8 ignore next */
206208
const runner = options?.runner || 'npm';
207209
const runtimeOptions = scriptRunner(runner);
208210
const runtime = runtimeOptions.shift()!;

src/modules/describe.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
/* c8 ignore next */
2+
import type { DescribeOptions } from '../@types/describe.js';
23
import { hrtime, env } from 'node:process';
34
import { format } from '../helpers/format.js';
45
import { write } from '../helpers/logs.js';
5-
/* c8 ignore next */
66
import { indentation } from '../configs/indentation.js';
7-
/* c8 ignore next */
8-
import type { DescribeOptions } from '../@types/describe.js';
97

10-
/* c8 ignore start */
8+
/* c8 ignore start */ // c8 bug
119
/**
1210
* On **Poku**, `describe` also can be used just as a pretty `console.log` to title your test suites in the terminal.
1311
*/
@@ -41,12 +39,11 @@ export async function describe(
4139
options = arg2 as DescribeOptions;
4240
}
4341

44-
/* c8 ignore start */
4542
if (title) {
4643
indentation.hasDescribe = true;
4744

4845
const { background, icon } = options || {};
49-
const message = `${cb ? format('◌').dim() : icon || '☰'} ${cb ? format(isPoku ? `${title}${format(`${FILE}`).italic().gray()}` : title).dim() : format(title).bold() || ''}`;
46+
const message = `${cb ? format('◌').dim() : icon || '☰'} ${cb ? format(isPoku ? `${title}${format(`${FILE}`).italic().gray()}` : /* c8 ignore next */ title).dim() : format(title).bold() || ''}`;
5047
const noBackground = !background;
5148

5249
if (noBackground) write(format(message).bold());
@@ -58,7 +55,6 @@ export async function describe(
5855
);
5956
}
6057
}
61-
/* c8 ignore stop */
6258

6359
if (typeof cb !== 'function') return;
6460

@@ -69,7 +65,6 @@ export async function describe(
6965
if (resultCb instanceof Promise) await resultCb;
7066
const end = hrtime(start);
7167

72-
/* c8 ignore start */
7368
if (title) {
7469
const total = (end[0] * 1e3 + end[1] / 1e6).toFixed(6);
7570

@@ -78,5 +73,4 @@ export async function describe(
7873
`${format(`● ${title}`).success().bold()} ${format(`› ${total}ms`).success().dim()}`
7974
);
8075
}
81-
/* c8 ignore stop */
8276
}

src/modules/each.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export const beforeEach = (
5252
return { pause, continue: continueFunc, reset };
5353
};
5454

55+
/* c8 ignore start */ // c8 bug
5556
/**
5657
* - ✅ Handling **global** and **external** services (_preparing a database, for example_)
5758
* - ✅ It's made for **exclusive use** in combination with **Poku**'s **`assert`** methods
@@ -77,6 +78,7 @@ export const afterEach = (
7778
callback: () => unknown,
7879
options?: Omit<EachOptions, 'immediate'>
7980
): Control => {
81+
/* c8 ignore stop */
8082
each.after.test = typeof options?.test === 'boolean' ? options.test : true;
8183
each.after.assert =
8284
typeof options?.assert === 'boolean' ? options.assert : false;

src/modules/it.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
/* c8 ignore next */
1+
/* c8 ignore next */ // c8 bug
22
import { hrtime, env } from 'node:process';
3-
/* c8 ignore next */
43
import { each } from '../configs/each.js';
5-
/* c8 ignore next */
64
import { indentation } from '../configs/indentation.js';
75
import { format } from '../helpers/format.js';
86
import { write } from '../helpers/logs.js';
97

10-
/* c8 ignore start */
8+
/* c8 ignore start */ // c8 bug
119
export async function it(
1210
message: string,
1311
cb: () => Promise<unknown>
@@ -40,16 +38,15 @@ export async function it(
4038
cb = args[1] as () => unknown | Promise<unknown>;
4139
} else cb = args[0] as () => unknown | Promise<unknown>;
4240

43-
/* c8 ignore start */
4441
if (message) {
4542
indentation.hasIt = true;
4643
write(
4744
isPoku && !indentation.hasDescribe
48-
? `${indentation.hasDescribe ? ' ' : ''}${format(`◌ ${message}${format(`${FILE}`).italic().gray()}`).dim()}`
49-
: `${indentation.hasDescribe ? ' ' : ''}${format(`◌ ${message}`).dim()}`
45+
? `${indentation.hasDescribe ? ' ' : ''}${format(`◌ ${message}${format(`${FILE}`).italic().gray()}`).dim()}` /* c8 ignore next */ // c8 bug
46+
: /* c8 ignore next */
47+
`${indentation.hasDescribe ? ' ' : ''}${format(`◌ ${message}`).dim()}`
5048
);
5149
}
52-
/* c8 ignore end */
5350

5451
const start = hrtime();
5552
const resultCb = cb();
@@ -64,7 +61,6 @@ export async function it(
6461
if (afterResult instanceof Promise) await afterResult;
6562
}
6663

67-
/* c8 ignore start */
6864
if (message) {
6965
const total = (end[0] * 1e3 + end[1] / 1e6).toFixed(6);
7066

@@ -73,5 +69,4 @@ export async function it(
7369
`${indentation.hasDescribe ? ' ' : ''}${format(`● ${message}`).success().bold()} ${format(`› ${total}ms`).success().dim()}`
7470
);
7571
}
76-
/* c8 ignore stop */
7772
}

src/modules/list-files.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
/* c8 ignore next */
2+
import type { Configs } from '../@types/list-files.js';
23
import { env } from 'node:process';
34
import { sep, join } from 'node:path';
45
import { readdir, stat as fsStat } from '../polyfills/fs.js';
5-
/* c8 ignore next */
6-
import type { Configs } from '../@types/list-files.js';
76

87
export const sanitizePath = (input: string, ensureTarget?: boolean): string => {
98
const sanitizedPath = input
@@ -83,7 +82,7 @@ export const getAllFiles = async (
8382
return files;
8483
};
8584

86-
/* c8 ignore start */
85+
/* c8 ignore start */ // c8 bug
8786
export const listFiles = async (
8887
targetDir: string,
8988
configs?: Configs

src/modules/poku.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* c8 ignore start */
1+
/* c8 ignore start */ // c8 bug (incompatibility) =>
22
/**
33
* Both CLI, API, noExit, sequential and parallel runs are strictly tested, but these tests use deep child process for it
44
*/

0 commit comments

Comments
 (0)