@@ -3,7 +3,7 @@ const os = require('os');
33const path = require ( 'path' ) ;
44const { spawnSync } = require ( 'child_process' ) ;
55
6- const { generateTestsFromSource, runTests } = require ( '../index' ) ;
6+ const { generateTestsFromSource, runTests, discoverTests , loadConfig } = require ( '../index' ) ;
77
88const CLI_PATH = path . resolve ( __dirname , '..' , 'bin' , 'themis.js' ) ;
99const FIXTURES_DIR = path . join ( __dirname , 'fixtures' ) ;
@@ -116,6 +116,19 @@ describe('code scan generation', () => {
116116 return { run : lastRun , payload : null } ;
117117 }
118118
119+ async function runDiscoveredSuite ( tempDir , overrides = { } ) {
120+ const config = loadConfig ( tempDir ) ;
121+ const files = discoverTests ( tempDir , config ) ;
122+ return runTests ( files , {
123+ cwd : tempDir ,
124+ maxWorkers : 1 ,
125+ environment : config . environment ,
126+ setupFiles : config . setupFiles ,
127+ tsconfigPath : config . tsconfigPath ,
128+ ...overrides
129+ } ) ;
130+ }
131+
119132 function parseJsonOutput ( result ) {
120133 return JSON . parse ( result . stdout || result . output ) ;
121134 }
@@ -547,11 +560,9 @@ describe('code scan generation', () => {
547560 expect ( buttonTestSource ) . toContain ( '../../../src/components/Button.tsx' ) ;
548561 expect ( buttonTestSource ) . toContain ( 'react component adapter' ) ;
549562
550- const { run, payload } = runCliJsonWithRetry ( tempDir , [ 'test' , '--json' , '--workers' , '1' ] ) ;
551- expect ( run . status ) . toBe ( 0 ) ;
552- expect ( Boolean ( payload ) ) . toBe ( true ) ;
553- expect ( payload . summary . failed ) . toBe ( 0 ) ;
554- expect ( payload . summary . passed ) . toBe ( 16 ) ;
563+ const result = await runDiscoveredSuite ( tempDir ) ;
564+ expect ( result . summary . failed ) . toBe ( 0 ) ;
565+ expect ( result . summary . passed ) . toBe ( 16 ) ;
555566 }
556567 ) ;
557568 } ) ;
@@ -811,10 +822,8 @@ describe('code scan generation', () => {
811822 'src/hooks/useToggle.themis.json'
812823 ] ) ;
813824
814- const { run, payload : runPayload } = runCliJsonWithRetry ( tempDir , [ 'test' , '--json' , '--workers' , '1' ] ) ;
815- expect ( run . status ) . toBe ( 0 ) ;
816- expect ( Boolean ( runPayload ) ) . toBe ( true ) ;
817- expect ( runPayload . summary . failed ) . toBe ( 0 ) ;
825+ const result = await runDiscoveredSuite ( tempDir ) ;
826+ expect ( result . summary . failed ) . toBe ( 0 ) ;
818827 }
819828 ) ;
820829 } ) ;
0 commit comments