1- import type { TestCase , TestCaseExecution , TestCasePhases } from './domain'
1+ import type { Plugin , TestCase , TestCaseExecution , TestCasePhases } from './domain'
22import { debug , retry } from './utils.js'
33import { dirname } from 'node:path'
44import test from 'node:test'
5+ import * as disableNetConnectPlugin from './plugins/disable-net-connect-plugin.js'
6+ import * as functionCallPlugin from './plugins/function-call-plugin.js'
7+ import * as httpMockPlugin from './plugins/http-mock-plugin.js'
58
69export type * from './domain'
710export * from './utils.js'
811export * from './config.js'
912export * from './loader.js'
1013
11- export const defaultTestRunner = async ( testCaseExecutions : TestCaseExecution [ ] , plugins : string [ ] ) => {
14+ export const defaultTestRunner = async ( testCaseExecutions : TestCaseExecution [ ] , plugins : Plugin [ ] ) => {
1215 for ( const testCaseExecution of testCaseExecutions ) {
1316 test ( testCaseExecution . testCase . name ?? testCaseExecution . filePath , ( args ) => executeTestCase ( testCaseExecution , plugins , args ) )
1417 }
1518}
1619
1720export const defaultLoader = async ( filePath : string ) => ( await import ( filePath ) ) . default
1821
19- export const defaultPlugins = [
20- './plugins/disable-net-connect-plugin.js' ,
21- './plugins/function-call-plugin.js' ,
22- './plugins/http-mock-plugin.js' ,
23- ]
22+ export const defaultPlugins : Plugin [ ] = [ disableNetConnectPlugin , functionCallPlugin , httpMockPlugin ]
2423
25- const createPluginExecutor = ( plugins : any [ ] , basePath : string , testRunnerArgs ?: unknown ) => {
26- return async ( functionName : string , data : unknown ) => {
24+ const createPluginExecutor = ( plugins : Plugin [ ] , basePath : string , testRunnerArgs ?: unknown ) => {
25+ return async ( functionName : TestCasePhases , data : unknown ) => {
2726 if ( ! data ) {
2827 return
2928 }
@@ -44,7 +43,7 @@ const createPluginExecutor = (plugins: any[], basePath: string, testRunnerArgs?:
4443}
4544
4645const createPhaseExecutor = (
47- executePluginFunction : ( functionName : string , data : unknown ) => Promise < void > ,
46+ executePluginFunction : ( functionName : TestCasePhases , data : unknown ) => Promise < void > ,
4847 testCaseExecution : TestCaseExecution ,
4948) => {
5049 const allowedLayerPhases = [ 'arrange' , 'clean' ]
@@ -82,12 +81,11 @@ const createPhaseExecutor = (
8281
8382const createTestCaseExecutor = async (
8483 testCaseExecution : TestCaseExecution ,
85- plugins : string [ ] ,
84+ plugins : Plugin [ ] ,
8685 testRunnerArgs ?: unknown ,
8786) => {
8887 const basePath = dirname ( testCaseExecution . filePath )
89- const loadedPlugins = await Promise . all ( plugins . map ( ( plugin ) => import ( plugin ) ) )
90- const executePluginFunction = createPluginExecutor ( loadedPlugins , basePath , testRunnerArgs )
88+ const executePluginFunction = createPluginExecutor ( plugins , basePath , testRunnerArgs )
9189 const phaseExecutor = createPhaseExecutor ( executePluginFunction , testCaseExecution )
9290 let errors : Error [ ] = [ ]
9391
@@ -118,7 +116,7 @@ const createTestCaseExecutor = async (
118116
119117export const executeTestCase = async (
120118 testCaseExecution : TestCaseExecution ,
121- plugins : string [ ] ,
119+ plugins : Plugin [ ] ,
122120 testRunnerArgs ?: unknown ,
123121) => {
124122 debug ( `TestCase: ${ JSON . stringify ( testCaseExecution , null , 2 ) } ` )
0 commit comments