Skip to content

Commit 18aee53

Browse files
author
chengyu.chengyulia
committed
feat: after test run
1 parent 2ffb977 commit 18aee53

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

src/built-in-plugins/command-test/plugin/run-test.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const runTest = async (options: IOpts) => {
4141
),
4242
};
4343

44-
await jest.runCLI(
44+
const result = await jest.runCLI(
4545
{
4646
_: options._,
4747
$0: options.$0,
@@ -50,9 +50,11 @@ export const runTest = async (options: IOpts) => {
5050
[pri.projectRootPath],
5151
);
5252

53-
logText(
54-
`Open this url to see code coverage: file://${path.join(pri.projectRootPath, 'coverage/lcov-report/index.html')}`,
55-
);
53+
plugin.afterTestRunCallbacks.forEach(callback => {
54+
return callback(result);
55+
});
56+
57+
logText(`Open this url to see code coverage: file://${path.join(pri.sourceRoot, 'coverage/lcov-report/index.html')}`);
5658

5759
process.exit(0);
5860
};

src/node/test.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { plugin } from '../utils/plugins';
2-
import { IJestConfigPipe } from '../utils/define';
2+
import { IJestConfigPipe, IAfterTestRun } from '../utils/define';
33

44
export const pipeJestConfig = (pipe: IJestConfigPipe) => {
55
plugin.jestConfigPipes.push(pipe);
66
};
7+
8+
export const afterTestRun = (callback: IAfterTestRun) => {
9+
plugin.afterTestRunCallbacks.push(callback);
10+
};

src/utils/define.ts

+2
Original file line numberDiff line numberDiff line change
@@ -394,3 +394,5 @@ export interface IPluginModule {
394394
export type IDevDllList = (list: string[]) => string[];
395395

396396
export type IJestConfigPipe = (options: any) => any;
397+
398+
export type IAfterTestRun = (result?: any) => any;

src/utils/plugins.ts

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
ProjectType,
2222
IDevDllList,
2323
IJestConfigPipe,
24+
IAfterTestRun,
2425
} from './define';
2526
import { getBabelOptions } from './babel-options';
2627
import { tempPath, srcPath } from '../node';
@@ -95,6 +96,8 @@ export class IPluginConfig {
9596

9697
public jestConfigPipes: IJestConfigPipe[] = [];
9798

99+
public afterTestRunCallbacks: IAfterTestRun[] = [];
100+
98101
// Lock init type
99102
public initType: ProjectType = null;
100103
}

0 commit comments

Comments
 (0)