@@ -31,29 +31,65 @@ type SourceTemplate = {
3131
3232const sourceTemplates : SourceTemplate [ ] = [
3333 { template : 'app-vanilla' , sourceExtension : 'js' , testFile : 'dom.test.js' } ,
34- { template : 'app-vanilla-ts' , sourceExtension : 'ts' , testFile : 'dom.test.ts' } ,
34+ {
35+ template : 'app-vanilla-ts' ,
36+ sourceExtension : 'ts' ,
37+ testFile : 'dom.test.ts' ,
38+ } ,
3539 { template : 'app-react' , sourceExtension : 'jsx' , testFile : 'index.test.jsx' } ,
36- { template : 'app-react-ts' , sourceExtension : 'tsx' , testFile : 'index.test.tsx' } ,
37- { template : 'app-preact' , sourceExtension : 'jsx' , testFile : 'index.test.jsx' } ,
38- { template : 'app-preact-ts' , sourceExtension : 'tsx' , testFile : 'index.test.tsx' } ,
40+ {
41+ template : 'app-react-ts' ,
42+ sourceExtension : 'tsx' ,
43+ testFile : 'index.test.tsx' ,
44+ } ,
45+ {
46+ template : 'app-preact' ,
47+ sourceExtension : 'jsx' ,
48+ testFile : 'index.test.jsx' ,
49+ } ,
50+ {
51+ template : 'app-preact-ts' ,
52+ sourceExtension : 'tsx' ,
53+ testFile : 'index.test.tsx' ,
54+ } ,
3955 { template : 'app-vue' , sourceExtension : 'js' , testFile : 'index.test.js' } ,
4056 { template : 'app-vue-ts' , sourceExtension : 'ts' , testFile : 'index.test.ts' } ,
4157 { template : 'app-lit' , sourceExtension : 'js' , testFile : 'index.test.js' } ,
4258 { template : 'app-lit-ts' , sourceExtension : 'ts' , testFile : 'index.test.ts' } ,
4359 { template : 'app-svelte' , sourceExtension : 'js' , testFile : 'index.test.js' } ,
44- { template : 'app-svelte-ts' , sourceExtension : 'ts' , testFile : 'index.test.ts' } ,
60+ {
61+ template : 'app-svelte-ts' ,
62+ sourceExtension : 'ts' ,
63+ testFile : 'index.test.ts' ,
64+ } ,
4565 { template : 'app-solid' , sourceExtension : 'jsx' , testFile : 'index.test.jsx' } ,
46- { template : 'app-solid-ts' , sourceExtension : 'tsx' , testFile : 'index.test.tsx' } ,
66+ {
67+ template : 'app-solid-ts' ,
68+ sourceExtension : 'tsx' ,
69+ testFile : 'index.test.tsx' ,
70+ } ,
4771 { template : 'lib-node' , sourceExtension : 'js' , testFile : 'index.test.js' } ,
4872 { template : 'lib-node-ts' , sourceExtension : 'ts' , testFile : 'index.test.ts' } ,
4973 { template : 'lib-react' , sourceExtension : 'jsx' , testFile : 'index.test.jsx' } ,
50- { template : 'lib-react-ts' , sourceExtension : 'tsx' , testFile : 'index.test.tsx' } ,
74+ {
75+ template : 'lib-react-ts' ,
76+ sourceExtension : 'tsx' ,
77+ testFile : 'index.test.tsx' ,
78+ } ,
5179 { template : 'lib-vue' , sourceExtension : 'js' , testFile : 'index.test.js' } ,
5280 { template : 'lib-vue-ts' , sourceExtension : 'ts' , testFile : 'index.test.ts' } ,
5381 { template : 'lib-svelte' , sourceExtension : 'js' , testFile : 'index.test.js' } ,
54- { template : 'lib-svelte-ts' , sourceExtension : 'ts' , testFile : 'index.test.ts' } ,
82+ {
83+ template : 'lib-svelte-ts' ,
84+ sourceExtension : 'ts' ,
85+ testFile : 'index.test.ts' ,
86+ } ,
5587 { template : 'lib-solid' , sourceExtension : 'jsx' , testFile : 'index.test.jsx' } ,
56- { template : 'lib-solid-ts' , sourceExtension : 'tsx' , testFile : 'index.test.tsx' } ,
88+ {
89+ template : 'lib-solid-ts' ,
90+ sourceExtension : 'tsx' ,
91+ testFile : 'index.test.tsx' ,
92+ } ,
5793] ;
5894
5995const docTemplates = [
@@ -74,14 +110,25 @@ const docTemplates = [
74110] ;
75111
76112const getCheckScript = ( template : string , hasTypeScript : boolean ) : string =>
77- hasTypeScript && ! templatesWithoutTypeCheck . has ( template ) ? typeCheckScript : checkScript ;
113+ hasTypeScript && ! templatesWithoutTypeCheck . has ( template )
114+ ? typeCheckScript
115+ : checkScript ;
78116
79- const readProjectPackage = async ( projectDirectory : string ) : Promise < ProjectPackage > =>
80- JSON . parse ( await readFile ( path . join ( projectDirectory , 'package.json' ) , 'utf8' ) ) as ProjectPackage ;
117+ const readProjectPackage = async (
118+ projectDirectory : string ,
119+ ) : Promise < ProjectPackage > =>
120+ JSON . parse (
121+ await readFile ( path . join ( projectDirectory , 'package.json' ) , 'utf8' ) ,
122+ ) as ProjectPackage ;
81123
82- const expectFiles = async ( projectDirectory : string , files : string [ ] ) : Promise < void > => {
124+ const expectFiles = async (
125+ projectDirectory : string ,
126+ files : string [ ] ,
127+ ) : Promise < void > => {
83128 for ( const file of files ) {
84- await expect ( access ( path . join ( projectDirectory , file ) ) ) . resolves . toBeUndefined ( ) ;
129+ await expect (
130+ access ( path . join ( projectDirectory , file ) ) ,
131+ ) . resolves . toBeUndefined ( ) ;
85132 }
86133} ;
87134
@@ -92,10 +139,16 @@ const expectStagedSetup = async (
92139) : Promise < void > => {
93140 expect ( scripts . prepare ) . toBe ( 'rs setup' ) ;
94141 expect (
95- await readFile ( path . join ( projectDirectory , '.rstack' , 'hooks' , 'pre-commit' ) , 'utf8' ) ,
142+ await readFile (
143+ path . join ( projectDirectory , '.rstack' , 'hooks' , 'pre-commit' ) ,
144+ 'utf8' ,
145+ ) ,
96146 ) . toBe ( 'rs staged\n' ) ;
97147 expect (
98- await readFile ( path . join ( projectDirectory , `rstack.config.${ configExtension } ` ) , 'utf8' ) ,
148+ await readFile (
149+ path . join ( projectDirectory , `rstack.config.${ configExtension } ` ) ,
150+ 'utf8' ,
151+ ) ,
99152 ) . toContain ( 'define.staged({' ) ;
100153} ;
101154
@@ -109,7 +162,10 @@ const expectNoStagedSetup = async (
109162 access ( path . join ( projectDirectory , '.rstack' , 'hooks' , 'pre-commit' ) ) ,
110163 ) . rejects . toThrow ( ) ;
111164 expect (
112- await readFile ( path . join ( projectDirectory , `rstack.config.${ configExtension } ` ) , 'utf8' ) ,
165+ await readFile (
166+ path . join ( projectDirectory , `rstack.config.${ configExtension } ` ) ,
167+ 'utf8' ,
168+ ) ,
113169 ) . not . toContain ( 'define.staged({' ) ;
114170} ;
115171
@@ -122,8 +178,14 @@ const expectProjectSetup = async (
122178 const packageJson = await readProjectPackage ( projectDirectory ) ;
123179
124180 expect ( packageJson . name ) . toBe ( 'my-app' ) ;
125- expect ( packageJson . scripts . check ) . toBe ( getCheckScript ( template , hasTypeScript ) ) ;
126- await expectStagedSetup ( projectDirectory , configExtension , packageJson . scripts ) ;
181+ expect ( packageJson . scripts . check ) . toBe (
182+ getCheckScript ( template , hasTypeScript ) ,
183+ ) ;
184+ await expectStagedSetup (
185+ projectDirectory ,
186+ configExtension ,
187+ packageJson . scripts ,
188+ ) ;
127189
128190 const tsconfig = access ( path . join ( projectDirectory , 'tsconfig.json' ) ) ;
129191 if ( hasTypeScript ) {
@@ -135,7 +197,9 @@ const expectProjectSetup = async (
135197
136198afterEach ( async ( ) => {
137199 await Promise . all (
138- tempDirectories . splice ( 0 ) . map ( ( directory ) => rm ( directory , { recursive : true , force : true } ) ) ,
200+ tempDirectories
201+ . splice ( 0 )
202+ . map ( ( directory ) => rm ( directory , { recursive : true , force : true } ) ) ,
139203 ) ;
140204} ) ;
141205
@@ -154,7 +218,8 @@ const createProject = async (
154218 tempDirectories . push ( tempDirectory ) ;
155219
156220 if ( initializeGitIn ) {
157- const gitDirectory = initializeGitIn === 'project' ? projectDirectory : tempDirectory ;
221+ const gitDirectory =
222+ initializeGitIn === 'project' ? projectDirectory : tempDirectory ;
158223 await mkdir ( gitDirectory , { recursive : true } ) ;
159224 await execFileAsync ( 'git' , [ 'init' , '--quiet' ] , { cwd : gitDirectory } ) ;
160225 }
@@ -209,14 +274,22 @@ test.each(sourceTemplates)(
209274 files . push ( 'src/env.d.ts' ) ;
210275 }
211276
212- await expectProjectSetup ( projectDirectory , template , configExtension , hasTypeScript ) ;
277+ await expectProjectSetup (
278+ projectDirectory ,
279+ template ,
280+ configExtension ,
281+ hasTypeScript ,
282+ ) ;
213283 await expectFiles ( projectDirectory , files ) ;
214284 } ,
215285) ;
216286
217- test . each ( docTemplates ) ( 'creates the $template template' , async ( { template, files } ) => {
218- const projectDirectory = await createProject ( template ) ;
287+ test . each ( docTemplates ) (
288+ 'creates the $template template' ,
289+ async ( { template, files } ) => {
290+ const projectDirectory = await createProject ( template ) ;
219291
220- await expectProjectSetup ( projectDirectory , template , 'ts' , true ) ;
221- await expectFiles ( projectDirectory , files ) ;
222- } ) ;
292+ await expectProjectSetup ( projectDirectory , template , 'ts' , true ) ;
293+ await expectFiles ( projectDirectory , files ) ;
294+ } ,
295+ ) ;
0 commit comments