@@ -292,4 +292,74 @@ describe('TSGoLint E2E Snapshot Tests', () => {
292292
293293 expect ( v1Diagnostics ) . toStrictEqual ( v2Diagnostics ) ;
294294 } ) ;
295+
296+ it ( 'should use source overrides instead of reading from disk' , async ( ) => {
297+ const testFiles = await getTestFiles ( 'source-overrides' ) ;
298+ expect ( testFiles . length ) . toBeGreaterThan ( 0 ) ;
299+ const testFile = testFiles [ 0 ] ;
300+
301+ const overriddenContent = `const promise = new Promise((resolve, _reject) => resolve("value"));
302+ promise;
303+ ` ;
304+
305+ const config = {
306+ version : 2 ,
307+ configs : [
308+ {
309+ file_paths : [ testFile ] ,
310+ rules : [ { name : 'no-floating-promises' } ] ,
311+ } ,
312+ ] ,
313+ source_overrides : {
314+ [ testFile ] : overriddenContent ,
315+ } ,
316+ } ;
317+
318+ const env = { ...process . env , GOMAXPROCS : '1' } ;
319+ const output = execFileSync ( TSGOLINT_BIN , [ 'headless' ] , {
320+ input : JSON . stringify ( config ) ,
321+ env,
322+ } ) ;
323+
324+ let diagnostics = parseHeadlessOutput ( output ) ;
325+ diagnostics = sortDiagnostics ( diagnostics ) ;
326+
327+ expect ( diagnostics . length ) . toBe ( 1 ) ;
328+ expect ( diagnostics [ 0 ] . rule ) . toBe ( 'no-floating-promises' ) ;
329+ expect ( diagnostics [ 0 ] . file_path ) . toContain ( 'original.ts' ) ;
330+ } ) ;
331+
332+ it ( 'should not report errors when source override is valid' , async ( ) => {
333+ const testFiles = await getTestFiles ( 'source-overrides' ) ;
334+ expect ( testFiles . length ) . toBeGreaterThan ( 0 ) ;
335+ const testFile = testFiles [ 0 ] ;
336+
337+ const validOverride = `// Valid code with no errors
338+ const x: number = 42;
339+ console.log(x);
340+ ` ;
341+
342+ const config = {
343+ version : 2 ,
344+ configs : [
345+ {
346+ file_paths : [ testFile ] ,
347+ rules : [ { name : 'no-floating-promises' } , { name : 'no-unsafe-assignment' } ] ,
348+ } ,
349+ ] ,
350+ source_overrides : {
351+ [ testFile ] : validOverride ,
352+ } ,
353+ } ;
354+
355+ const env = { ...process . env , GOMAXPROCS : '1' } ;
356+ const output = execFileSync ( TSGOLINT_BIN , [ 'headless' ] , {
357+ input : JSON . stringify ( config ) ,
358+ env,
359+ } ) ;
360+
361+ const diagnostics = parseHeadlessOutput ( output ) ;
362+
363+ expect ( diagnostics . length ) . toBe ( 0 ) ;
364+ } ) ;
295365} ) ;
0 commit comments