@@ -47,7 +47,10 @@ export class Generator {
47
47
await createFiles ( this . rootDir , files ) ;
48
48
this . _patchGitIgnore ( ) ;
49
49
await this . _patchPackageJSON ( answers ) ;
50
- this . _printEpilogue ( answers ) ;
50
+ if ( answers . framework )
51
+ this . _printEpilogueCT ( answers ) ;
52
+ else
53
+ this . _printEpilogue ( answers ) ;
51
54
}
52
55
53
56
private _printPrologue ( ) {
@@ -126,21 +129,21 @@ export class Generator {
126
129
for ( const browserName of [ 'chromium' , 'firefox' , 'webkit' ] )
127
130
sections . set ( browserName , ! this . options . browser || this . options . browser . includes ( browserName ) ? 'show' : 'comment' ) ;
128
131
132
+ let ctPackageName ;
129
133
let installExamples = true ;
130
- let ctPackageName = '' ;
131
134
if ( answers . framework ) {
132
135
ctPackageName = `@playwright/experimental-ct-${ answers . framework } ` ;
133
136
installExamples = false ;
134
- sections . set ( 'ct' , 'show' ) ;
137
+ files . set ( `playwright-ct.config.${ fileExtension } ` , executeTemplate ( this . _readAsset ( `playwright-ct.config.${ fileExtension } ` ) , {
138
+ testDir : answers . testDir || '' ,
139
+ ctPackageName,
140
+ } , sections ) ) ;
135
141
} else {
136
- sections . set ( 'ct' , 'hide' ) ;
142
+ files . set ( `playwright.config.${ fileExtension } ` , executeTemplate ( this . _readAsset ( `playwright.config.${ fileExtension } ` ) , {
143
+ testDir : answers . testDir || '' ,
144
+ } , sections ) ) ;
137
145
}
138
146
139
- files . set ( `playwright.config.${ fileExtension } ` , executeTemplate ( this . _readAsset ( `playwright.config.${ fileExtension } ` ) , {
140
- testDir : answers . testDir || '' ,
141
- testRunnerImport : ctPackageName || '@playwright/test' ,
142
- } , sections ) ) ;
143
-
144
147
if ( answers . installGitHubActions ) {
145
148
const githubActionsScript = executeTemplate ( this . _readAsset ( 'github-actions.yml' ) , {
146
149
installDepsCommand : this . packageManager === 'npm' ? 'npm ci' : 'yarn' ,
@@ -159,20 +162,24 @@ export class Generator {
159
162
} ) ;
160
163
}
161
164
162
- let packageName = '@playwright/test' ;
165
+ let packageLine = '' ;
166
+ const packageName = '@playwright/test' ;
163
167
if ( this . options . beta )
164
- packageName = '@playwright/test @beta' ;
168
+ packageLine = '@beta' ;
165
169
if ( this . options . next )
166
- packageName = '@playwright/test@next' ;
167
- commands . push ( {
168
- name : 'Installing Playwright Test' ,
169
- command : this . packageManager === 'yarn' ? `yarn add --dev ${ packageName } ` : `npm install --save-dev ${ packageName } ` ,
170
- } ) ;
170
+ packageLine = '@next' ;
171
+
172
+ if ( ! this . options . ct ) {
173
+ commands . push ( {
174
+ name : 'Installing Playwright Test' ,
175
+ command : this . packageManager === 'yarn' ? `yarn add --dev ${ packageName } ${ packageLine } ` : `npm install --save-dev ${ packageName } ${ packageLine } ` ,
176
+ } ) ;
177
+ }
171
178
172
- if ( ctPackageName ) {
179
+ if ( this . options . ct ) {
173
180
commands . push ( {
174
181
name : 'Installing Playwright Component Testing' ,
175
- command : this . packageManager === 'yarn' ? `yarn add --dev ${ ctPackageName } @latest ` : `npm install --save-dev ${ ctPackageName } @latest ` ,
182
+ command : this . packageManager === 'yarn' ? `yarn add --dev ${ ctPackageName } ${ packageLine } ` : `npm install --save-dev ${ ctPackageName } ${ packageLine } ` ,
176
183
} ) ;
177
184
178
185
const extension = languageToFileExtension ( answers . language ) ;
@@ -201,7 +208,7 @@ export class Generator {
201
208
gitIgnore += 'node_modules/\n' ;
202
209
gitIgnore += '/test-results/\n' ;
203
210
gitIgnore += '/playwright-report/\n' ;
204
- gitIgnore += '/dist-pw /\n' ;
211
+ gitIgnore += '/playwright/.cache /\n' ;
205
212
fs . writeFileSync ( gitIgnorePath , gitIgnore ) ;
206
213
}
207
214
@@ -216,6 +223,10 @@ export class Generator {
216
223
if ( packageJSON . scripts [ 'test' ] ?. includes ( 'no test specified' ) )
217
224
delete packageJSON . scripts [ 'test' ] ;
218
225
226
+ const extension = languageToFileExtension ( answers . language ) ;
227
+ if ( answers . framework )
228
+ packageJSON . scripts [ 'test-ct' ] = `playwright test -c playwright-ct.config.${ extension } ` ;
229
+
219
230
const files = new Map < string , string > ( ) ;
220
231
files . set ( 'package.json' , JSON . stringify ( packageJSON , null , 2 ) + '\n' ) ; // NPM keeps a trailing new-line
221
232
await createFiles ( this . rootDir , files , true ) ;
@@ -227,7 +238,8 @@ export class Generator {
227
238
const prefix = pathToNavigate !== '' ? ` cd ${ pathToNavigate } \n` : '' ;
228
239
const exampleSpecPath = `example.spec.${ languageToFileExtension ( answers . language ) } ` ;
229
240
const playwrightConfigPath = `playwright.config.${ languageToFileExtension ( answers . language ) } ` ;
230
- console . log ( `Inside that directory, you can run several commands:
241
+ console . log ( `
242
+ Inside that directory, you can run several commands:
231
243
232
244
${ colors . cyan ( commandToRunTests ( this . packageManager ) ) }
233
245
Runs the end-to-end tests.
@@ -236,21 +248,47 @@ export class Generator {
236
248
Runs the tests only on Desktop Chrome.
237
249
238
250
${ colors . cyan ( commandToRunTests ( this . packageManager , exampleSpecPath ) ) }
239
- Runs the tests of a specific file.
251
+ Runs the tests in the specific file.
240
252
241
253
${ colors . cyan ( `${ commandToRunTests ( this . packageManager , '--debug' ) } ` ) }
242
254
Runs the tests in debug mode.
243
255
244
256
We suggest that you begin by typing:
245
257
246
- ${ colors . cyan ( prefix + ' ' + commandToRunTests ( this . packageManager ) ) }
258
+ ${ colors . cyan ( prefix + ' ' + commandToRunTests ( this . packageManager ) ) }
247
259
248
260
And check out the following files:
249
261
- .${ path . sep } ${ pathToNavigate ? path . join ( pathToNavigate , exampleSpecPath ) : exampleSpecPath } - Example end-to-end test
250
262
- .${ path . sep } ${ pathToNavigate ? path . join ( pathToNavigate , playwrightConfigPath ) : playwrightConfigPath } - Playwright Test configuration
251
263
252
264
Visit https://playwright.dev/docs/intro for more information. ✨
253
265
266
+ Happy hacking! 🎭` ) ;
267
+ }
268
+
269
+ private _printEpilogueCT ( answers : PromptOptions ) {
270
+ console . log ( colors . green ( '✔ Success!' ) + ' ' + colors . bold ( `Created a Playwright Test project at ${ this . rootDir } ` ) ) ;
271
+ console . log ( `
272
+ Inside that directory, you can run several commands:
273
+
274
+ ${ colors . cyan ( `${ this . packageManager } run test-ct` ) }
275
+ Runs the component tests.
276
+
277
+ ${ colors . cyan ( `${ this . packageManager } run test-ct -- --project=chromium` ) }
278
+ Runs the tests only on Desktop Chrome.
279
+
280
+ ${ colors . cyan ( `${ this . packageManager } run test-ct App.test.ts` ) }
281
+ Runs the tests in the specific file.
282
+
283
+ ${ colors . cyan ( `${ this . packageManager } run test-ct -- --debug` ) }
284
+ Runs the tests in debug mode.
285
+
286
+ We suggest that you begin by typing:
287
+
288
+ ${ colors . cyan ( `${ this . packageManager } run test-ct` ) }
289
+
290
+ Visit https://playwright.dev/docs/intro for more information. ✨
291
+
254
292
Happy hacking! 🎭` ) ;
255
293
}
256
294
}
0 commit comments