@@ -134,6 +134,10 @@ class TestInitCommand implements ICommand {
134134 this . $projectData
135135 ) ;
136136
137+ this . $logger . clearScreen ( ) ;
138+
139+ const bufferedLogs = [ ] ;
140+
137141 const testsDir = path . join ( this . $projectData . appDirectoryPath , "tests" ) ;
138142 const projectTestsDir = path . relative (
139143 this . $projectData . projectDir ,
@@ -145,8 +149,13 @@ class TestInitCommand implements ICommand {
145149 ) ;
146150 let shouldCreateSampleTests = true ;
147151 if ( this . $fs . exists ( testsDir ) ) {
148- this . $logger . info (
149- `${ projectTestsDir } directory already exists, will not create an example test project.`
152+ const specFilenamePattern = `<filename>.spec${ projectFilesExtension } ` ;
153+ bufferedLogs . push (
154+ [
155+ `Note: The "${ projectTestsDir } " directory already exists, will not create example tests in the project.` ,
156+ `You may create "${ specFilenamePattern } " files anywhere you'd like.` ,
157+ "" ,
158+ ] . join ( "\n" ) . yellow
150159 ) ;
151160 shouldCreateSampleTests = false ;
152161 }
@@ -172,23 +181,76 @@ class TestInitCommand implements ICommand {
172181 const exampleFilePath = this . $resources . resolvePath (
173182 `test/example.${ frameworkToInstall } ${ projectFilesExtension } `
174183 ) ;
184+ const targetExampleTestPath = path . join (
185+ testsDir ,
186+ `example.spec${ projectFilesExtension } `
187+ ) ;
175188
176189 if ( shouldCreateSampleTests && this . $fs . exists ( exampleFilePath ) ) {
177- this . $fs . copyFile (
178- exampleFilePath ,
179- path . join ( testsDir , `example${ projectFilesExtension } ` )
190+ this . $fs . copyFile ( exampleFilePath , targetExampleTestPath ) ;
191+ const targetExampleTestRelativePath = path . relative (
192+ projectDir ,
193+ targetExampleTestPath
180194 ) ;
181- this . $logger . info (
182- `\nExample test file created in ${ projectTestsDir } ` . yellow
195+ bufferedLogs . push (
196+ `Added example test: ${ targetExampleTestRelativePath . yellow } `
183197 ) ;
184- } else {
185- this . $logger . info (
186- `\nPlace your test files under ${ projectTestsDir } ` . yellow
198+ }
199+
200+ // test main entry
201+ const testMainResourcesPath = this . $resources . resolvePath (
202+ `test/test-main${ projectFilesExtension } `
203+ ) ;
204+ const testMainPath = path . join (
205+ this . $projectData . appDirectoryPath ,
206+ `test${ projectFilesExtension } `
207+ ) ;
208+
209+ if ( ! this . $fs . exists ( testMainPath ) ) {
210+ this . $fs . copyFile ( testMainResourcesPath , testMainPath ) ;
211+ const testMainRelativePath = path . relative ( projectDir , testMainPath ) ;
212+ bufferedLogs . push (
213+ `Main test entrypoint created: ${ testMainRelativePath . yellow } `
187214 ) ;
188215 }
189216
217+ const testTsConfigTemplate = this . $resources . readText (
218+ "test/tsconfig.spec.json"
219+ ) ;
220+ const testTsConfig = _ . template ( testTsConfigTemplate ) ( {
221+ basePath : this . $projectData . getAppDirectoryRelativePath ( ) ,
222+ } ) ;
223+
224+ this . $fs . writeFile (
225+ path . join ( projectDir , "tsconfig.spec.json" ) ,
226+ testTsConfig
227+ ) ;
228+ bufferedLogs . push ( `Added/replaced ${ "tsconfig.spec.json" . yellow } ` ) ;
229+
230+ const greyDollarSign = "$" . grey ;
190231 this . $logger . info (
191- 'Run your tests using the "$ ns test <platform>" command.' . yellow
232+ [
233+ [
234+ `Tests using` . green ,
235+ frameworkToInstall . cyan ,
236+ `were successfully initialized.` . green ,
237+ ] . join ( " " ) ,
238+ "" ,
239+ ...bufferedLogs ,
240+ "" ,
241+ `Note: @nativescript/unit-test-runner was included in "dependencies" as a convenience to automatically adjust your app's Info.plist on iOS and AndroidManifest.xml on Android to ensure the socket connects properly.`
242+ . yellow ,
243+ "" ,
244+ `For production you may want to move to "devDependencies" and manage the settings yourself.`
245+ . yellow ,
246+ "" ,
247+ "" ,
248+ `You can now run your tests:` ,
249+ "" ,
250+ ` ${ greyDollarSign } ${ "ns test ios" . green } ` ,
251+ ` ${ greyDollarSign } ${ "ns test android" . green } ` ,
252+ "" ,
253+ ] . join ( "\n" )
192254 ) ;
193255 }
194256}
0 commit comments