@@ -21,12 +21,21 @@ export const execAsync = promisify(exec);
21
21
22
22
type Fixtures < Addons extends AddonMap > = {
23
23
page : Page ;
24
- run ( variant : ProjectVariant , options : OptionMap < Addons > ) : Promise < string > ;
24
+ run ( flavor : Flavor < Addons > ) : string ;
25
+ } ;
26
+
27
+ type Flavor < Addons extends AddonMap > = {
28
+ variant : ProjectVariant ;
29
+ kind : { type : string ; options : OptionMap < Addons > } ;
25
30
} ;
26
31
27
32
export function setupTest < Addons extends AddonMap > (
28
33
addons : Addons ,
29
- options ?: { browser ?: boolean }
34
+ options ?: {
35
+ kinds : Array < Flavor < Addons > [ 'kind' ] > ;
36
+ filter ?: ( flavor : Flavor < Addons > ) => boolean ;
37
+ browser ?: boolean ;
38
+ }
30
39
) {
31
40
const test = vitest . test . extend < Fixtures < Addons > > ( { } as any ) ;
32
41
@@ -44,8 +53,18 @@ export function setupTest<Addons extends AddonMap>(
44
53
} ) ;
45
54
}
46
55
47
- vitest . beforeAll ( ( { name } ) => {
48
- const testName = path . dirname ( name ) . split ( '/' ) . at ( - 1 ) ! ;
56
+ const flavors : Array < Flavor < Addons > > = [ ] ;
57
+ for ( const kind of options ?. kinds ?? [ ] ) {
58
+ for ( const variant of variants ) {
59
+ const flavor = { variant, kind } ;
60
+ if ( ! options ?. filter || options ?. filter ?.( flavor ) ) {
61
+ flavors . push ( flavor ) ;
62
+ }
63
+ }
64
+ }
65
+ let testName : string ;
66
+ vitest . beforeAll ( async ( { name } ) => {
67
+ testName = path . dirname ( name ) . split ( '/' ) . at ( - 1 ) ! ;
49
68
50
69
// constructs a builder for create test projects
51
70
create = createProject ( { cwd, templatesDir, testName } ) ;
@@ -65,32 +84,36 @@ export function setupTest<Addons extends AddonMap>(
65
84
private : true
66
85
} )
67
86
) ;
68
- } ) ;
69
87
70
- // runs before each test case
71
- vitest . beforeEach < Fixtures < Addons > > ( async ( ctx ) => {
72
- let browserCtx : BrowserContext ;
73
- if ( withBrowser ) {
74
- browserCtx = await browser . newContext ( ) ;
75
- ctx . page = await browserCtx . newPage ( ) ;
76
- }
77
- ctx . run = async ( variant , options ) => {
78
- const cwd = create ( { testId : ctx . task . id , variant } ) ;
88
+ for ( const { variant, kind } of flavors ) {
89
+ const cwd = create ( { testId : `${ kind . type } -${ variant } ` , variant } ) ;
79
90
80
91
// test metadata
81
92
const metaPath = path . resolve ( cwd , 'meta.json' ) ;
82
- fs . writeFileSync ( metaPath , JSON . stringify ( { variant, options } , null , '\t' ) , 'utf8' ) ;
93
+ fs . writeFileSync ( metaPath , JSON . stringify ( { variant, kind } , null , '\t' ) , 'utf8' ) ;
83
94
84
- // run addon
85
95
const { pnpmBuildDependencies } = await installAddon ( {
86
96
cwd,
87
97
addons,
88
- options,
98
+ options : kind . options ,
89
99
packageManager : 'pnpm'
90
100
} ) ;
91
101
addPnpmBuildDependencies ( cwd , 'pnpm' , [ 'esbuild' , ...pnpmBuildDependencies ] ) ;
102
+ }
103
+
104
+ execSync ( 'pnpm install' , { cwd : path . resolve ( cwd , testName ) , stdio : 'pipe' } ) ;
105
+ } ) ;
106
+
107
+ // runs before each test case
108
+ vitest . beforeEach < Fixtures < Addons > > ( async ( ctx ) => {
109
+ let browserCtx : BrowserContext ;
110
+ if ( withBrowser ) {
111
+ browserCtx = await browser . newContext ( ) ;
112
+ ctx . page = await browserCtx . newPage ( ) ;
113
+ }
92
114
93
- return cwd ;
115
+ ctx . run = ( flavor ) => {
116
+ return path . join ( cwd , testName , `${ flavor . kind . type } -${ flavor . variant } ` ) ;
94
117
} ;
95
118
96
119
return async ( ) => {
@@ -101,7 +124,7 @@ export function setupTest<Addons extends AddonMap>(
101
124
} ;
102
125
} ) ;
103
126
104
- return { test, variants, prepareServer } ;
127
+ return { test, variants, prepareServer, flavors } ;
105
128
}
106
129
107
130
type PrepareServerOptions = {
@@ -118,7 +141,7 @@ async function prepareServer(
118
141
page,
119
142
previewCommand = 'npm run preview' ,
120
143
buildCommand = 'npm run build' ,
121
- installCommand = 'pnpm install --no-frozen-lockfile'
144
+ installCommand
122
145
} : PrepareServerOptions ,
123
146
afterInstall ?: ( ) => Promise < any > | any
124
147
) {
0 commit comments