Skip to content

Commit 1e83901

Browse files
authored
ci(coverage): add assert tests (#436)
* chore: add assert tests * refactor: remove CLI async scope * chore: temp disable findFile test for Windows * ci(c8): fix paths * chore: adjust "*" imports
1 parent b28cc96 commit 1e83901

23 files changed

+255
-198
lines changed

.nycrc

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
11
{
22
"all": true,
33
"include": ["src/**"],
4-
"exclude": ["benchmark", "ci", "fixtures", "lib", "test", "tools", "website"],
5-
"extension": ["ts"],
4+
"exclude": [
5+
"src/@types",
6+
"src/bin",
7+
"src/configs",
8+
"src/polyfills",
9+
"benchmark",
10+
"ci",
11+
"fixtures",
12+
"lib",
13+
"test",
14+
"tools",
15+
"website"
16+
],
17+
"extension": [".ts"],
618
"reporter": ["text", "lcov", "cobertura"],
719
"clean": true,
820
"branches": 85,
921
"statements": 90,
1022
"lines": 90,
1123
"functions": 95,
12-
"checkCoverage": true
24+
"checkCoverage": true,
25+
"import": ["tsx"]
1326
}

src/@types/assert.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* c8 ignore start */
2-
31
export type ParseAssertionOptions = {
42
message?: string | Error;
53
defaultMessage?: string;
@@ -8,5 +6,3 @@ export type ParseAssertionOptions = {
86
throw?: boolean;
97
hideDiff?: boolean;
108
};
11-
12-
/* c8 ignore stop */

src/@types/background-process.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* c8 ignore start */
2-
31
import { Runner } from './runner.js';
42
import { Configs } from './poku.js';
53

@@ -50,5 +48,3 @@ export type StartServiceOptions = {
5048
} & BackgroundProcessOptions;
5149

5250
export type End = (port?: number | number[]) => Promise<void>;
53-
54-
/* c8 ignore stop */

src/@types/code.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
/* c8 ignore start */
2-
31
export type Code = 0 | 1;
4-
5-
/* c8 ignore stop */

src/@types/describe.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* c8 ignore start */
2-
31
import { type backgroundColor } from '../helpers/format.js';
42

53
export type DescribeOptions = {
@@ -14,5 +12,3 @@ export type DescribeOptions = {
1412
* @default "grey"
1513
*/
1614
};
17-
18-
/* c8 ignore stop */

src/@types/list-files.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* c8 ignore start */
2-
31
export type Configs = {
42
/**
53
* Filter by path to match only the files that should be performed.
@@ -19,5 +17,3 @@ export type FileResults = {
1917
success: Map<string, string>;
2018
fail: Map<string, string>;
2119
};
22-
23-
/* c8 ignore stop */

src/@types/poku.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* c8 ignore start */
2-
31
import type { Configs as ListFilesConfigs } from './list-files.js';
42

53
export type DenoOptions = {
@@ -106,5 +104,3 @@ export type FinalResults = {
106104
time: string;
107105
started: Date;
108106
};
109-
110-
/* c8 ignore stop */

src/@types/runner.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
/* c8 ignore start */
2-
31
export type Runner = 'npm' | 'bun' | 'deno' | 'yarn' | 'pnpm';
4-
5-
/* c8 ignore stop */

src/bin/index.ts

Lines changed: 129 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#! /usr/bin/env node
22

3-
/* c8 ignore start */
4-
53
import process from 'node:process';
64
import { escapeRegExp } from '../modules/list-files.js';
75
import {
@@ -21,150 +19,148 @@ import { onSigint, poku } from '../modules/poku.js';
2119
import { kill } from '../modules/processes.js';
2220
import type { Configs } from '../@types/poku.js';
2321

24-
(async () => {
25-
const dirs = (() => {
26-
const includeArg = getArg('include');
27-
if (includeArg !== undefined) return includeArg.split(',');
28-
29-
const lastParam = getLastParam();
30-
if (lastParam !== undefined) return lastParam.split(',');
31-
32-
return ['.'];
33-
})();
34-
35-
const platform = getArg('platform');
36-
const filter = getArg('filter');
37-
const exclude = getArg('exclude');
38-
const killPort = getArg('kill-port');
39-
const killRange = getArg('kill-range');
40-
const killPID = getArg('kill-pid');
41-
const denoAllow = argToArray('deno-allow');
42-
const denoDeny = argToArray('deno-deny');
43-
const denoCJS =
44-
getArg('deno-cjs')
45-
?.split(',')
46-
.map((a) => a.trim())
47-
.filter((a) => a) || hasArg('deno-cjs');
48-
49-
const parallel = hasArg('parallel');
50-
const quiet = hasArg('quiet');
51-
const debug = hasArg('debug');
52-
const failFast = hasArg('fail-fast');
53-
const watchMode = hasArg('watch');
54-
55-
const concurrency = parallel
56-
? Number(getArg('concurrency')) || undefined
57-
: undefined;
58-
59-
if (killPort) {
60-
const ports = killPort.split(',').map(Number);
61-
62-
await kill.port(ports);
63-
}
64-
65-
if (killRange) {
66-
const ranges = killRange.split(',');
67-
68-
for (const range of ranges) {
69-
const ports = range.split('-').map(Number);
70-
71-
const startsAt = ports[0];
72-
const endsAt = ports[1];
73-
74-
await kill.range(startsAt, endsAt);
75-
}
76-
}
22+
const dirs = (() => {
23+
const includeArg = getArg('include');
24+
if (includeArg !== undefined) return includeArg.split(',');
7725

78-
if (killPID) {
79-
const PIDs = killPID.split(',').map(Number);
26+
const lastParam = getLastParam();
27+
if (lastParam !== undefined) return lastParam.split(',');
8028

81-
await kill.pid(PIDs);
82-
}
29+
return ['.'];
30+
})();
8331

84-
const options: Configs = {
85-
platform: platformIsValid(platform) ? platform : undefined,
86-
filter: filter ? new RegExp(escapeRegExp(filter)) : undefined,
87-
exclude: exclude ? new RegExp(escapeRegExp(exclude)) : undefined,
88-
parallel,
89-
quiet,
90-
debug,
91-
failFast,
92-
concurrency,
93-
noExit: watchMode,
94-
deno: {
95-
allow: denoAllow,
96-
deny: denoDeny,
97-
cjs: denoCJS,
98-
},
99-
};
100-
101-
if (debug) {
102-
hr();
103-
write(`${format.bg(104, 'Debug Enabled')}\n`);
104-
write(`${format.italic(format.info('…'))} ${format.bold('Paths')}`);
105-
console.table(dirs);
106-
write('\n');
107-
write(`${format.italic(format.info('…'))} ${format.bold('Options')}`);
108-
console.dir(options, { depth: null, colors: true });
32+
const platform = getArg('platform');
33+
const filter = getArg('filter');
34+
const exclude = getArg('exclude');
35+
const killPort = getArg('kill-port');
36+
const killRange = getArg('kill-range');
37+
const killPID = getArg('kill-pid');
38+
const denoAllow = argToArray('deno-allow');
39+
const denoDeny = argToArray('deno-deny');
40+
const denoCJS =
41+
getArg('deno-cjs')
42+
?.split(',')
43+
.map((a) => a.trim())
44+
.filter((a) => a) || hasArg('deno-cjs');
45+
46+
const parallel = hasArg('parallel');
47+
const quiet = hasArg('quiet');
48+
const debug = hasArg('debug');
49+
const failFast = hasArg('fail-fast');
50+
const watchMode = hasArg('watch');
51+
52+
const concurrency = parallel
53+
? Number(getArg('concurrency')) || undefined
54+
: undefined;
55+
56+
const tasks: Promise<unknown>[] = [];
57+
58+
if (killPort) {
59+
const ports = killPort.split(',').map(Number);
60+
tasks.push(kill.port(ports));
61+
}
62+
63+
if (killRange) {
64+
const ranges = killRange.split(',');
65+
66+
for (const range of ranges) {
67+
const ports = range.split('-').map(Number);
68+
const startsAt = ports[0];
69+
const endsAt = ports[1];
70+
tasks.push(kill.range(startsAt, endsAt));
10971
}
72+
}
73+
74+
if (killPID) {
75+
const PIDs = killPID.split(',').map(Number);
76+
tasks.push(kill.pid(PIDs));
77+
}
78+
79+
const options: Configs = {
80+
platform: platformIsValid(platform) ? platform : undefined,
81+
filter: filter ? new RegExp(escapeRegExp(filter)) : undefined,
82+
exclude: exclude ? new RegExp(escapeRegExp(exclude)) : undefined,
83+
parallel,
84+
quiet,
85+
debug,
86+
failFast,
87+
concurrency,
88+
noExit: watchMode,
89+
deno: {
90+
allow: denoAllow,
91+
deny: denoDeny,
92+
cjs: denoCJS,
93+
},
94+
};
95+
96+
if (debug) {
97+
hr();
98+
write(`${format.bg(104, 'Debug Enabled')}\n`);
99+
write(`${format.italic(format.info('…'))} ${format.bold('Paths')}`);
100+
console.table(dirs);
101+
write('\n');
102+
write(`${format.italic(format.info('…'))} ${format.bold('Options')}`);
103+
console.dir(options, { depth: null, colors: true });
104+
}
105+
106+
Promise.all(tasks).then(() => {
107+
poku(dirs, options).then(() => {
108+
if (watchMode) {
109+
const executing = new Set<string>();
110+
const interval = Number(getArg('watch-interval')) || 1500;
111+
112+
const resultsClear = () => {
113+
fileResults.success.clear();
114+
fileResults.fail.clear();
115+
};
116+
117+
process.removeListener('SIGINT', onSigint);
118+
resultsClear();
119+
120+
mapTests('.', dirs, options.filter, options.exclude).then(
121+
(mappedTests) => {
122+
Array.from(mappedTests.keys()).forEach((mappedTest) => {
123+
watch(mappedTest, (file, event) => {
124+
if (event === 'change') {
125+
const filePath = normalizePath(file);
126+
if (executing.has(filePath)) return;
127+
128+
executing.add(filePath);
129+
resultsClear();
130+
131+
const tests = mappedTests.get(filePath);
132+
if (!tests) return;
133+
134+
poku(Array.from(tests), options).then(() => {
135+
setTimeout(() => {
136+
executing.delete(filePath);
137+
}, interval);
138+
});
139+
}
140+
});
141+
});
142+
}
143+
);
110144

111-
await poku(dirs, options);
112-
113-
if (watchMode) {
114-
const executing = new Set<string>();
115-
const interval = Number(getArg('watch-interval')) || 1500;
116-
117-
const resultsClear = () => {
118-
fileResults.success.clear();
119-
fileResults.fail.clear();
120-
};
121-
122-
process.removeListener('SIGINT', onSigint);
123-
resultsClear();
124-
125-
mapTests('.', dirs, options.filter, options.exclude).then((mappedTests) => {
126-
Array.from(mappedTests.keys()).forEach((mappedTest) => {
127-
watch(mappedTest, (file, event) => {
145+
dirs.forEach((dir) => {
146+
watch(dir, (file, event) => {
128147
if (event === 'change') {
129-
const filePath = normalizePath(file);
130-
if (executing.has(filePath)) return;
148+
if (executing.has(file)) return;
131149

132-
executing.add(filePath);
150+
executing.add(file);
133151
resultsClear();
134152

135-
const tests = mappedTests.get(filePath);
136-
if (!tests) return;
137-
138-
poku(Array.from(tests), options).then(() => {
153+
poku(file, options).then(() => {
139154
setTimeout(() => {
140-
executing.delete(filePath);
155+
executing.delete(file);
141156
}, interval);
142157
});
143158
}
144159
});
145160
});
146-
});
147-
148-
dirs.forEach((dir) => {
149-
watch(dir, (file, event) => {
150-
if (event === 'change') {
151-
if (executing.has(file)) return;
152-
153-
executing.add(file);
154-
resultsClear();
155-
156-
poku(file, options).then(() => {
157-
setTimeout(() => {
158-
executing.delete(file);
159-
}, interval);
160-
});
161-
}
162-
});
163-
});
164161

165-
hr();
166-
write(`${format.bold('Watching:')} ${format.underline(dirs.join(', '))}`);
167-
}
168-
})();
169-
170-
/* c8 ignore stop */
162+
hr();
163+
write(`${format.bold('Watching:')} ${format.underline(dirs.join(', '))}`);
164+
}
165+
});
166+
});

0 commit comments

Comments
 (0)