@atls/code-test 1.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/tester.d.ts +10 -8
- package/dist/tester.js +53 -76
- package/dist/tests.d.ts +8 -0
- package/dist/tests.js +13 -0
- package/package.json +4 -10
package/dist/tester.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import type { TestEvent } from 'node:test/reporters';
|
|
2
|
+
import EventEmitter from 'node:events';
|
|
3
|
+
import { run } from 'node:test';
|
|
4
|
+
export type TestsStream = ReturnType<typeof run>;
|
|
5
|
+
export declare class Tester extends EventEmitter {
|
|
6
|
+
constructor();
|
|
7
|
+
static initialize(): Promise<Tester>;
|
|
8
|
+
unit(cwd: string): Promise<Array<TestEvent>>;
|
|
9
|
+
integration(cwd: string): Promise<Array<TestEvent>>;
|
|
10
|
+
protected run(files: Array<string>, timeout: number, concurrency: boolean): Promise<Array<TestEvent>>;
|
|
9
11
|
}
|
package/dist/tester.js
CHANGED
|
@@ -1,86 +1,63 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
constructor(cwd) {
|
|
9
|
-
this.cwd = cwd;
|
|
1
|
+
import EventEmitter from 'node:events';
|
|
2
|
+
import { run } from 'node:test';
|
|
3
|
+
import { globby } from 'globby';
|
|
4
|
+
import { Tests } from './tests.js';
|
|
5
|
+
export class Tester extends EventEmitter {
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
10
8
|
}
|
|
11
|
-
async
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
9
|
+
static async initialize() {
|
|
10
|
+
return new Tester();
|
|
11
|
+
}
|
|
12
|
+
async unit(cwd) {
|
|
13
|
+
return this.run(await globby(['**/!(integration)/*.test.{ts,tsx,js,jsx}'], {
|
|
14
|
+
cwd,
|
|
15
|
+
dot: true,
|
|
16
|
+
absolute: true,
|
|
17
|
+
ignore: ['**/node_modules/**', '**/dist/**'],
|
|
18
|
+
}), 25_000, true);
|
|
19
|
+
}
|
|
20
|
+
async integration(cwd) {
|
|
21
|
+
return this.run(await globby(['**/integration/**/*.test.{ts,tsx,js,jsx}'], {
|
|
22
|
+
cwd,
|
|
23
|
+
dot: true,
|
|
24
|
+
absolute: true,
|
|
25
|
+
ignore: ['**/node_modules/**', '**/dist/**'],
|
|
26
|
+
}), 240_000, false);
|
|
27
|
+
}
|
|
28
|
+
async run(files, timeout, concurrency) {
|
|
29
|
+
const tests = await Tests.load(files);
|
|
30
|
+
this.emit('start', { tests });
|
|
31
|
+
const testsStream = run({
|
|
32
|
+
files,
|
|
33
|
+
timeout,
|
|
34
|
+
concurrency,
|
|
35
|
+
});
|
|
36
|
+
const onPass = (data) => {
|
|
37
|
+
this.emit('test:pass', data);
|
|
23
38
|
};
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
ci: false,
|
|
27
|
-
detectLeaks: false,
|
|
28
|
-
detectOpenHandles: false,
|
|
29
|
-
errorOnDeprecated: false,
|
|
30
|
-
listTests: false,
|
|
31
|
-
passWithNoTests: true,
|
|
32
|
-
runTestsByPath: false,
|
|
33
|
-
testLocationInResults: true,
|
|
34
|
-
config: JSON.stringify({ ...unit, ...setup }),
|
|
35
|
-
maxConcurrency: 5,
|
|
36
|
-
notifyMode: 'failure-change',
|
|
37
|
-
_: files || [],
|
|
38
|
-
$0: '',
|
|
39
|
-
...options,
|
|
39
|
+
const onFail = (data) => {
|
|
40
|
+
this.emit('test:fail', data);
|
|
40
41
|
};
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
async integration(options, files) {
|
|
45
|
-
process.env.TS_JEST_DISABLE_VER_CHECKER = 'true';
|
|
46
|
-
const setup = {
|
|
47
|
-
globalSetup: (await this.isConfigExists('.config/test/integration/global-setup.ts'))
|
|
48
|
-
? join(this.cwd, '.config/test/integration/global-setup.ts')
|
|
49
|
-
: undefined,
|
|
50
|
-
globalTeardown: (await this.isConfigExists('.config/test/integration/global-teardown.ts'))
|
|
51
|
-
? join(this.cwd, '.config/test/integration/global-teardown.ts')
|
|
52
|
-
: undefined,
|
|
53
|
-
setupFilesAfterEnv: (await this.isConfigExists('.config/test/integration/setup.ts'))
|
|
54
|
-
? [join(this.cwd, '.config/test/integration/setup.ts')]
|
|
55
|
-
: [],
|
|
42
|
+
const onStdout = (data) => {
|
|
43
|
+
this.emit('test:stdout', data);
|
|
56
44
|
};
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
ci: false,
|
|
60
|
-
detectLeaks: false,
|
|
61
|
-
detectOpenHandles: false,
|
|
62
|
-
errorOnDeprecated: false,
|
|
63
|
-
listTests: false,
|
|
64
|
-
passWithNoTests: true,
|
|
65
|
-
runTestsByPath: false,
|
|
66
|
-
testLocationInResults: true,
|
|
67
|
-
config: JSON.stringify({ ...integration, ...setup }),
|
|
68
|
-
maxConcurrency: 5,
|
|
69
|
-
notifyMode: 'failure-change',
|
|
70
|
-
_: files || [],
|
|
71
|
-
$0: '',
|
|
72
|
-
...options,
|
|
45
|
+
const onStderr = (data) => {
|
|
46
|
+
this.emit('test:stderr', data);
|
|
73
47
|
};
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
48
|
+
testsStream.on('test:pass', onPass);
|
|
49
|
+
testsStream.on('test:fail', onFail);
|
|
50
|
+
testsStream.on('test:stdout', onStdout);
|
|
51
|
+
testsStream.on('test:stderr', onStderr);
|
|
78
52
|
try {
|
|
79
|
-
|
|
80
|
-
return true;
|
|
53
|
+
return (await testsStream.toArray());
|
|
81
54
|
}
|
|
82
|
-
|
|
83
|
-
|
|
55
|
+
finally {
|
|
56
|
+
this.emit('end');
|
|
57
|
+
testsStream.off('test:pass', onPass);
|
|
58
|
+
testsStream.off('test:fail', onFail);
|
|
59
|
+
testsStream.off('test:stdout', onStdout);
|
|
60
|
+
testsStream.off('test:stderr', onStderr);
|
|
84
61
|
}
|
|
85
62
|
}
|
|
86
63
|
}
|
package/dist/tests.d.ts
ADDED
package/dist/tests.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
export class Tests {
|
|
3
|
+
static async load(files) {
|
|
4
|
+
return Promise.all(files.map(async (file) => {
|
|
5
|
+
const source = await readFile(file, 'utf8');
|
|
6
|
+
return {
|
|
7
|
+
file,
|
|
8
|
+
source,
|
|
9
|
+
tests: source.match(/test\(/gm)?.length || 0,
|
|
10
|
+
};
|
|
11
|
+
}));
|
|
12
|
+
}
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atls/code-test",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"license": "BSD-3-Clause",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -23,17 +23,11 @@
|
|
|
23
23
|
"postpack": "rm -rf dist"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@atls/code-runtime": "
|
|
27
|
-
"
|
|
28
|
-
"@jest/types": "^29.6.1"
|
|
26
|
+
"@atls/code-runtime": "2.0.1",
|
|
27
|
+
"globby": "13.2.2"
|
|
29
28
|
},
|
|
30
29
|
"devDependencies": {
|
|
31
|
-
"@types/node": "
|
|
32
|
-
},
|
|
33
|
-
"peerDependenciesMeta": {
|
|
34
|
-
"jest": {
|
|
35
|
-
"optional": true
|
|
36
|
-
}
|
|
30
|
+
"@types/node": "22.9.0"
|
|
37
31
|
},
|
|
38
32
|
"publishConfig": {
|
|
39
33
|
"access": "public",
|