@atls/code-test 1.0.1 → 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 CHANGED
@@ -1,9 +1,11 @@
1
- import type { AggregatedResult } from '@jest/test-result';
2
- import type { Config } from '@jest/types';
3
- export declare class Tester {
4
- private readonly cwd;
5
- constructor(cwd: string);
6
- unit(options?: Partial<Config.Argv>, files?: Array<string>): Promise<AggregatedResult>;
7
- integration(options?: Partial<Config.Argv>, files?: Array<string>): Promise<AggregatedResult>;
8
- private isConfigExists;
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,87 +1,63 @@
1
- import { constants } from 'node:fs';
2
- import { access } from 'node:fs/promises';
3
- import { join } from 'node:path';
4
- import { runCLI } from '@atls/code-runtime/jest';
5
- import { integration } from '@atls/code-runtime/jest';
6
- import { unit } from '@atls/code-runtime/jest';
7
- export class Tester {
8
- cwd;
9
- constructor(cwd) {
10
- 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();
11
8
  }
12
- async unit(options, files) {
13
- process.env.TS_JEST_DISABLE_VER_CHECKER = 'true';
14
- const setup = {
15
- globalSetup: (await this.isConfigExists('.config/test/unit/global-setup.ts'))
16
- ? join(this.cwd, '.config/test/unit/global-setup.ts')
17
- : undefined,
18
- globalTeardown: (await this.isConfigExists('.config/test/unit/global-teardown.ts'))
19
- ? join(this.cwd, '.config/test/unit/global-teardown.ts')
20
- : undefined,
21
- setupFilesAfterEnv: (await this.isConfigExists('.config/test/unit/setup.ts'))
22
- ? [join(this.cwd, '.config/test/unit/setup.ts')]
23
- : [],
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);
24
38
  };
25
- const argv = {
26
- rootDir: this.cwd,
27
- ci: false,
28
- detectLeaks: false,
29
- detectOpenHandles: false,
30
- errorOnDeprecated: false,
31
- listTests: false,
32
- passWithNoTests: true,
33
- runTestsByPath: false,
34
- testLocationInResults: true,
35
- config: JSON.stringify({ ...unit, ...setup }),
36
- maxConcurrency: 5,
37
- notifyMode: 'failure-change',
38
- _: files || [],
39
- $0: '',
40
- ...options,
39
+ const onFail = (data) => {
40
+ this.emit('test:fail', data);
41
41
  };
42
- const { results } = await runCLI(argv, [this.cwd]);
43
- return results;
44
- }
45
- async integration(options, files) {
46
- process.env.TS_JEST_DISABLE_VER_CHECKER = 'true';
47
- const setup = {
48
- globalSetup: (await this.isConfigExists('.config/test/integration/global-setup.ts'))
49
- ? join(this.cwd, '.config/test/integration/global-setup.ts')
50
- : undefined,
51
- globalTeardown: (await this.isConfigExists('.config/test/integration/global-teardown.ts'))
52
- ? join(this.cwd, '.config/test/integration/global-teardown.ts')
53
- : undefined,
54
- setupFilesAfterEnv: (await this.isConfigExists('.config/test/integration/setup.ts'))
55
- ? [join(this.cwd, '.config/test/integration/setup.ts')]
56
- : [],
42
+ const onStdout = (data) => {
43
+ this.emit('test:stdout', data);
57
44
  };
58
- const argv = {
59
- rootDir: this.cwd,
60
- ci: false,
61
- detectLeaks: false,
62
- detectOpenHandles: false,
63
- errorOnDeprecated: false,
64
- listTests: false,
65
- passWithNoTests: true,
66
- runTestsByPath: false,
67
- testLocationInResults: true,
68
- config: JSON.stringify({ ...integration, ...setup }),
69
- maxConcurrency: 5,
70
- notifyMode: 'failure-change',
71
- _: files || [],
72
- $0: '',
73
- ...options,
45
+ const onStderr = (data) => {
46
+ this.emit('test:stderr', data);
74
47
  };
75
- const { results } = await runCLI(argv, [this.cwd]);
76
- return results;
77
- }
78
- async isConfigExists(file) {
48
+ testsStream.on('test:pass', onPass);
49
+ testsStream.on('test:fail', onFail);
50
+ testsStream.on('test:stdout', onStdout);
51
+ testsStream.on('test:stderr', onStderr);
79
52
  try {
80
- await access(join(this.cwd, file), constants.R_OK);
81
- return true;
53
+ return (await testsStream.toArray());
82
54
  }
83
- catch {
84
- return false;
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);
85
61
  }
86
62
  }
87
63
  }
@@ -0,0 +1,8 @@
1
+ export interface Test {
2
+ file: string;
3
+ source: string;
4
+ tests: number;
5
+ }
6
+ export declare class Tests {
7
+ static load(files: Array<string>): Promise<Array<Test>>;
8
+ }
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": "1.0.1",
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": "1.1.2",
27
- "@jest/test-result": "29.7.0",
28
- "@jest/types": "29.6.3"
26
+ "@atls/code-runtime": "2.0.1",
27
+ "globby": "13.2.2"
29
28
  },
30
29
  "devDependencies": {
31
- "@types/node": "22.5.1"
32
- },
33
- "peerDependenciesMeta": {
34
- "jest": {
35
- "optional": true
36
- }
30
+ "@types/node": "22.9.0"
37
31
  },
38
32
  "publishConfig": {
39
33
  "access": "public",