@@ -11,6 +11,8 @@ const {
1111 untrackedDiff
1212} = require ( "../tooling/check-comment-length" ) ;
1313
14+ const SCRIPT = path . join ( __dirname , ".." , "tooling" , "check-comment-length.js" ) ;
15+
1416/**
1517 * @param {string[] } lines added lines, without the `+`
1618 * @returns {string[] } what the checker reports for them
@@ -141,8 +143,6 @@ describe("check-comment-length", () => {
141143 describe ( "over a real repository" , ( ) => {
142144 /** @type {string } */
143145 let dir ;
144- /** @type {string } */
145- let cwd ;
146146
147147 const git = ( /** @type {string[] } */ args ) =>
148148 execFileSync ( "git" , args , { cwd : dir , encoding : "utf8" } ) ;
@@ -161,12 +161,9 @@ describe("check-comment-length", () => {
161161 "-qm" ,
162162 "base"
163163 ] ) ;
164- cwd = process . cwd ( ) ;
165- process . chdir ( dir ) ;
166164 } ) ;
167165
168166 afterEach ( ( ) => {
169- process . chdir ( cwd ) ;
170167 fs . rmSync ( dir , { recursive : true , force : true } ) ;
171168 } ) ;
172169
@@ -175,36 +172,36 @@ describe("check-comment-length", () => {
175172 path . join ( dir , "kept.js" ) ,
176173 "// one\n// two\n// three\n"
177174 ) ;
178- expect ( report ( "HEAD" ) ) . toEqual ( [ "kept.js:2" ] ) ;
175+ expect ( report ( "HEAD" , dir ) ) . toEqual ( [ "kept.js:2" ] ) ;
179176 } ) ;
180177
181178 it ( "reads a file git does not track yet" , ( ) => {
182179 fs . writeFileSync (
183180 path . join ( dir , "new.js" ) ,
184181 "/* one\n two\n three */\n"
185182 ) ;
186- expect ( report ( "HEAD" ) ) . toEqual ( [ "new.js:1" ] ) ;
183+ expect ( report ( "HEAD" , dir ) ) . toEqual ( [ "new.js:1" ] ) ;
187184 } ) ;
188185
189186 it ( "reports nothing when every comment is short enough" , ( ) => {
190187 fs . appendFileSync ( path . join ( dir , "kept.js" ) , "// one\n// two\n" ) ;
191188 fs . writeFileSync ( path . join ( dir , "new.js" ) , "/* just the one */\n" ) ;
192- expect ( report ( "HEAD" ) ) . toEqual ( [ ] ) ;
189+ expect ( report ( "HEAD" , dir ) ) . toEqual ( [ ] ) ;
193190 } ) ;
194191
195192 it ( "returns 1 and names each offender" , ( ) => {
196193 fs . writeFileSync ( path . join ( dir , "new.js" ) , "// one\n// two\n// three\n" ) ;
197194 /** @type {string[] } */
198195 const written = [ ] ;
199- expect ( main ( ( text ) => written . push ( text ) , "HEAD" ) ) . toBe ( 1 ) ;
196+ expect ( main ( ( text ) => written . push ( text ) , "HEAD" , dir ) ) . toBe ( 1 ) ;
200197 expect ( written ) . toEqual ( [ "new.js:1: comment over 2 lines\n" ] ) ;
201198 } ) ;
202199
203200 it ( "returns 0 and writes nothing when the diff is clean" , ( ) => {
204201 fs . appendFileSync ( path . join ( dir , "kept.js" ) , "// one\n" ) ;
205202 /** @type {string[] } */
206203 const written = [ ] ;
207- expect ( main ( ( text ) => written . push ( text ) , "HEAD" ) ) . toBe ( 0 ) ;
204+ expect ( main ( ( text ) => written . push ( text ) , "HEAD" , dir ) ) . toBe ( 0 ) ;
208205 expect ( written ) . toEqual ( [ ] ) ;
209206 } ) ;
210207
@@ -213,11 +210,11 @@ describe("check-comment-length", () => {
213210 let status = 0 ;
214211 let stderr = "" ;
215212 try {
216- execFileSync (
217- process . execPath ,
218- [ path . join ( cwd , "tooling/check-comment-length.js" ) , "HEAD" ] ,
219- { cwd : dir , encoding : "utf8" , stdio : "pipe" }
220- ) ;
213+ execFileSync ( process . execPath , [ SCRIPT , "HEAD" ] , {
214+ cwd : dir ,
215+ encoding : "utf8" ,
216+ stdio : "pipe"
217+ } ) ;
221218 } catch ( err ) {
222219 status = /** @type {EXPECTED_ANY } */ ( err ) . status ;
223220 stderr = /** @type {EXPECTED_ANY } */ ( err ) . stderr ;
@@ -228,11 +225,11 @@ describe("check-comment-length", () => {
228225
229226 it ( "exits 0 and says nothing when the diff is clean" , ( ) => {
230227 fs . appendFileSync ( path . join ( dir , "kept.js" ) , "// one\n" ) ;
231- const out = execFileSync (
232- process . execPath ,
233- [ path . join ( cwd , "tooling/check-comment-length.js" ) , "HEAD" ] ,
234- { cwd : dir , encoding : "utf8" , stdio : "pipe" }
235- ) ;
228+ const out = execFileSync ( process . execPath , [ SCRIPT , "HEAD" ] , {
229+ cwd : dir ,
230+ encoding : "utf8" ,
231+ stdio : "pipe"
232+ } ) ;
236233 expect ( out ) . toBe ( "" ) ;
237234 } ) ;
238235 } ) ;
0 commit comments