@@ -47,7 +47,10 @@ export class Generator {
4747 await createFiles ( this . rootDir , files ) ;
4848 this . _patchGitIgnore ( ) ;
4949 await this . _patchPackageJSON ( answers ) ;
50- this . _printEpilogue ( answers ) ;
50+ if ( answers . framework )
51+ this . _printEpilogueCT ( answers ) ;
52+ else
53+ this . _printEpilogue ( answers ) ;
5154 }
5255
5356 private _printPrologue ( ) {
@@ -126,21 +129,21 @@ export class Generator {
126129 for ( const browserName of [ 'chromium' , 'firefox' , 'webkit' ] )
127130 sections . set ( browserName , ! this . options . browser || this . options . browser . includes ( browserName ) ? 'show' : 'comment' ) ;
128131
132+ let ctPackageName ;
129133 let installExamples = true ;
130- let ctPackageName = '' ;
131134 if ( answers . framework ) {
132135 ctPackageName = `@playwright/experimental-ct-${ answers . framework } ` ;
133136 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 ) ) ;
135141 } else {
136- sections . set ( 'ct' , 'hide' ) ;
142+ files . set ( `playwright.config.${ fileExtension } ` , executeTemplate ( this . _readAsset ( `playwright.config.${ fileExtension } ` ) , {
143+ testDir : answers . testDir || '' ,
144+ } , sections ) ) ;
137145 }
138146
139- files . set ( `playwright.config.${ fileExtension } ` , executeTemplate ( this . _readAsset ( `playwright.config.${ fileExtension } ` ) , {
140- testDir : answers . testDir || '' ,
141- testRunnerImport : ctPackageName || '@playwright/test' ,
142- } , sections ) ) ;
143-
144147 if ( answers . installGitHubActions ) {
145148 const githubActionsScript = executeTemplate ( this . _readAsset ( 'github-actions.yml' ) , {
146149 installDepsCommand : this . packageManager === 'npm' ? 'npm ci' : 'yarn' ,
@@ -159,20 +162,24 @@ export class Generator {
159162 } ) ;
160163 }
161164
162- let packageName = '@playwright/test' ;
165+ let packageLine = '' ;
166+ const packageName = '@playwright/test' ;
163167 if ( this . options . beta )
164- packageName = '@playwright/test @beta' ;
168+ packageLine = '@beta' ;
165169 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+ }
171178
172- if ( ctPackageName ) {
179+ if ( this . options . ct ) {
173180 commands . push ( {
174181 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 } ` ,
176183 } ) ;
177184
178185 const extension = languageToFileExtension ( answers . language ) ;
@@ -201,7 +208,7 @@ export class Generator {
201208 gitIgnore += 'node_modules/\n' ;
202209 gitIgnore += '/test-results/\n' ;
203210 gitIgnore += '/playwright-report/\n' ;
204- gitIgnore += '/dist-pw /\n' ;
211+ gitIgnore += '/playwright/.cache /\n' ;
205212 fs . writeFileSync ( gitIgnorePath , gitIgnore ) ;
206213 }
207214
@@ -216,6 +223,10 @@ export class Generator {
216223 if ( packageJSON . scripts [ 'test' ] ?. includes ( 'no test specified' ) )
217224 delete packageJSON . scripts [ 'test' ] ;
218225
226+ const extension = languageToFileExtension ( answers . language ) ;
227+ if ( answers . framework )
228+ packageJSON . scripts [ 'test-ct' ] = `playwright test -c playwright-ct.config.${ extension } ` ;
229+
219230 const files = new Map < string , string > ( ) ;
220231 files . set ( 'package.json' , JSON . stringify ( packageJSON , null , 2 ) + '\n' ) ; // NPM keeps a trailing new-line
221232 await createFiles ( this . rootDir , files , true ) ;
@@ -227,7 +238,8 @@ export class Generator {
227238 const prefix = pathToNavigate !== '' ? ` cd ${ pathToNavigate } \n` : '' ;
228239 const exampleSpecPath = `example.spec.${ languageToFileExtension ( answers . language ) } ` ;
229240 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:
231243
232244 ${ colors . cyan ( commandToRunTests ( this . packageManager ) ) }
233245 Runs the end-to-end tests.
@@ -236,21 +248,47 @@ export class Generator {
236248 Runs the tests only on Desktop Chrome.
237249
238250 ${ colors . cyan ( commandToRunTests ( this . packageManager , exampleSpecPath ) ) }
239- Runs the tests of a specific file.
251+ Runs the tests in the specific file.
240252
241253 ${ colors . cyan ( `${ commandToRunTests ( this . packageManager , '--debug' ) } ` ) }
242254 Runs the tests in debug mode.
243255
244256We suggest that you begin by typing:
245257
246- ${ colors . cyan ( prefix + ' ' + commandToRunTests ( this . packageManager ) ) }
258+ ${ colors . cyan ( prefix + ' ' + commandToRunTests ( this . packageManager ) ) }
247259
248260And check out the following files:
249261 - .${ path . sep } ${ pathToNavigate ? path . join ( pathToNavigate , exampleSpecPath ) : exampleSpecPath } - Example end-to-end test
250262 - .${ path . sep } ${ pathToNavigate ? path . join ( pathToNavigate , playwrightConfigPath ) : playwrightConfigPath } - Playwright Test configuration
251263
252264Visit https://playwright.dev/docs/intro for more information. ✨
253265
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+
254292Happy hacking! 🎭` ) ;
255293 }
256294}
0 commit comments