11import { spawnSync } from 'node:child_process' ;
2- import { mkdirSync , mkdtempSync , readFileSync , rmSync , writeFileSync } from 'node:fs' ;
2+ import { mkdtempSync , readFileSync , rmSync , writeFileSync } from 'node:fs' ;
33import path from 'node:path' ;
44import { afterEach , beforeEach , expect , test } from 'rstack/test' ;
55import { RSTACK_BIN_PATH } from '#test-helpers' ;
66
77let projectPath : string ;
88let env : NodeJS . ProcessEnv ;
99
10- const writeProjectFile = ( filePath : string , content : string ) : void => {
11- const absolutePath = path . join ( projectPath , filePath ) ;
12- mkdirSync ( path . dirname ( absolutePath ) , { recursive : true } ) ;
13- writeFileSync ( absolutePath , content ) ;
14- } ;
10+ const writeProjectFile = ( filePath : string , content : string ) : void =>
11+ writeFileSync ( path . join ( projectPath , filePath ) , content ) ;
1512
1613const readProjectFile = ( filePath : string ) : string =>
1714 readFileSync ( path . join ( projectPath , filePath ) , 'utf8' ) ;
@@ -43,17 +40,9 @@ beforeEach(() => {
4340 ...process . env ,
4441 GIT_CONFIG_GLOBAL : path . join ( projectPath , 'global.gitconfig' ) ,
4542 GIT_CONFIG_NOSYSTEM : '1' ,
46- NO_COLOR : '1' ,
4743 } ;
4844
4945 git ( [ 'init' , '--quiet' ] ) ;
50- } ) ;
51-
52- afterEach ( ( ) => {
53- rmSync ( projectPath , { force : true , recursive : true } ) ;
54- } ) ;
55-
56- test ( 'formats staged files with rs fmt and applies ignore rules' , ( ) => {
5746 writeProjectFile (
5847 'rstack.config.ts' ,
5948 `import { define } from 'rstack';
@@ -67,6 +56,13 @@ define.staged({
6756});
6857` ,
6958 ) ;
59+ } ) ;
60+
61+ afterEach ( ( ) => {
62+ rmSync ( projectPath , { force : true , recursive : true } ) ;
63+ } ) ;
64+
65+ test ( 'formats staged files with rs fmt and applies ignore rules' , ( ) => {
7066 writeProjectFile ( '.gitignore' , 'ignored-by-git.ts\n' ) ;
7167 writeProjectFile ( 'file with spaces.ts' , 'const spaced="spaced"' ) ;
7268 writeProjectFile ( 'ignored-by-git.ts' , 'const gitIgnored="git ignored"' ) ;
@@ -83,19 +79,9 @@ define.staged({
8379 expect ( readProjectFile ( 'ignored-by-fmt.ts' ) ) . toBe ( 'const fmtIgnored="fmt ignored"' ) ;
8480 expect ( git ( [ 'show' , ':file with spaces.ts' ] ) ) . toBe ( 'const spaced = "spaced";\n' ) ;
8581 expect ( git ( [ 'show' , ':ignored-by-git.ts' ] ) ) . toBe ( 'const gitIgnored = "git ignored";\n' ) ;
86- expect ( git ( [ 'show' , ':ignored-by-fmt.ts' ] ) ) . toBe ( 'const fmtIgnored="fmt ignored"' ) ;
8782} ) ;
8883
8984test ( 'propagates rs fmt failures' , ( ) => {
90- writeProjectFile (
91- 'rstack.config.ts' ,
92- `import { define } from 'rstack';
93-
94- define.staged({
95- '*': 'rs fmt',
96- });
97- ` ,
98- ) ;
9985 writeProjectFile ( 'invalid.ts' , 'const value = ;' ) ;
10086 git ( [ 'add' , '--' , 'invalid.ts' ] ) ;
10187
0 commit comments