3
3
// SPDX-License-Identifier: MIT
4
4
5
5
import { resolve } from 'node:path'
6
+ import { spawnSync } from 'node:child_process'
6
7
import {
7
8
existsSync ,
8
9
readFileSync ,
9
10
writeFileSync ,
10
11
rmSync ,
11
12
renameSync
12
13
} from 'node:fs'
13
- import cli from '../main.js'
14
- import { describe , it } from 'vitest'
14
+ import { beforeAll , describe , it } from 'vitest'
15
+
16
+ // Build CLI before tests, for local usage only.
17
+ // CI builds the CLI on different platforms and architectures
18
+ if ( ! process . env . CI ) {
19
+ beforeAll ( ( ) => {
20
+ const cliDir = resolve ( __dirname , '..' )
21
+ exec ( 'pnpm' , [ 'build:debug' ] , { cwd : cliDir } )
22
+ } )
23
+ }
15
24
16
25
describe ( '[CLI] @tauri-apps/cli template' , ( ) => {
17
26
it ( 'init a project and builds it' , { timeout : 15 * 60 * 1000 } , async ( ) => {
@@ -31,6 +40,8 @@ describe('[CLI] @tauri-apps/cli template', () => {
31
40
renameSync ( outPath , cacheOutPath )
32
41
}
33
42
43
+ const cli = await import ( '../main.js' )
44
+
34
45
await cli . run ( [
35
46
'init' ,
36
47
'--directory' ,
@@ -63,3 +74,15 @@ describe('[CLI] @tauri-apps/cli template', () => {
63
74
process . chdir ( cwd )
64
75
} )
65
76
} )
77
+
78
+ function exec (
79
+ bin : string ,
80
+ args ?: string [ ] ,
81
+ opts ?: {
82
+ cwd ?: string
83
+ }
84
+ ) {
85
+ process . platform === 'win32'
86
+ ? spawnSync ( 'cmd' , [ '/c' , bin , ...( args ?? [ ] ) ] , { cwd : opts ?. cwd } )
87
+ : spawnSync ( bin , args , { cwd : opts ?. cwd } )
88
+ }
0 commit comments