@@ -40,19 +40,73 @@ describe('CLI', () => {
4040
4141 const FIXTURES_DIR = join ( __dirname , 'fixtures' ) ;
4242
43- it ( 'runs inline tests' , async ( ) => {
44- const cli = new CLIMock ( )
45- . stdin (
46- `step('check h2', async () => {
47- await page.goto(params.url, { timeout: 1500 });
48- const sel = await page.waitForSelector('h2.synthetics', { timeout: 1500 });
49- expect(await sel.textContent()).toBe("Synthetics test page");
50- })`
51- )
52- . args ( [ '--inline' , '--params' , JSON . stringify ( serverParams ) ] )
53- . run ( ) ;
54- await cli . waitFor ( 'Journey: inline' ) ;
55- expect ( await cli . exitCode ) . toBe ( 0 ) ;
43+ describe ( 'for inline tests' , ( ) => {
44+ it ( 'runs inline tests' , async ( ) => {
45+ const cli = new CLIMock ( )
46+ . stdin (
47+ `step('check h2', async () => {
48+ await page.goto(params.url, { timeout: 1500 });
49+ const sel = await page.waitForSelector('h2.synthetics', { timeout: 1500 });
50+ expect(await sel.textContent()).toBe("Synthetics test page");
51+ })`
52+ )
53+ . args ( [ '--inline' , '--params' , JSON . stringify ( serverParams ) ] )
54+ . run ( ) ;
55+ await cli . waitFor ( 'Journey: inline' ) ;
56+ expect ( await cli . exitCode ) . toBe ( 0 ) ;
57+ } ) ;
58+
59+ it ( 'does not load a configuration file without a config param' , async ( ) => {
60+ // jest by default sets NODE_ENV to `test`
61+ const original = process . env [ 'NODE_ENV' ] ;
62+ const output = async ( ) => {
63+ const cli = new CLIMock ( )
64+ . stdin ( `step('fake step', async () => {})` )
65+ . args ( [ '--reporter' , 'json' , '--inline' ] )
66+ . run ( { cwd : FIXTURES_DIR } ) ;
67+ await cli . waitFor ( 'journey/start' ) ;
68+ expect ( await cli . exitCode ) . toBe ( 0 ) ;
69+ return cli . output ( ) ;
70+ } ;
71+
72+ expect ( JSON . parse ( await output ( ) ) . payload ) . not . toMatchObject ( {
73+ params : { url : 'non-dev' } ,
74+ } ) ;
75+ process . env [ 'NODE_ENV' ] = 'development' ;
76+ expect ( JSON . parse ( await output ( ) ) . payload ) . not . toMatchObject ( {
77+ params : { url : 'dev' } ,
78+ } ) ;
79+ process . env [ 'NODE_ENV' ] = original ;
80+ } ) ;
81+
82+ it ( 'loads a configuration file when passing a config param' , async ( ) => {
83+ // jest by default sets NODE_ENV to `test`
84+ const original = process . env [ 'NODE_ENV' ] ;
85+ const output = async ( ) => {
86+ const cli = new CLIMock ( )
87+ . stdin ( `step('fake step', async () => {})` )
88+ . args ( [
89+ '--reporter' ,
90+ 'json' ,
91+ '--inline' ,
92+ '--config' ,
93+ join ( FIXTURES_DIR , 'synthetics.config.ts' ) ,
94+ ] )
95+ . run ( { cwd : FIXTURES_DIR } ) ;
96+ await cli . waitFor ( 'journey/start' ) ;
97+ expect ( await cli . exitCode ) . toBe ( 0 ) ;
98+ return cli . output ( ) ;
99+ } ;
100+
101+ expect ( JSON . parse ( await output ( ) ) . payload ) . toMatchObject ( {
102+ params : { url : 'non-dev' } ,
103+ } ) ;
104+ process . env [ 'NODE_ENV' ] = 'development' ;
105+ expect ( JSON . parse ( await output ( ) ) . payload ) . toMatchObject ( {
106+ params : { url : 'dev' } ,
107+ } ) ;
108+ process . env [ 'NODE_ENV' ] = original ;
109+ } ) ;
56110 } ) ;
57111
58112 it ( 'run suites and exit with 0' , async ( ) => {
@@ -428,9 +482,9 @@ describe('CLI', () => {
428482 '--config' ,
429483 join ( FIXTURES_DIR , 'synthetics.config.ts' ) ,
430484 '--playwright-options' ,
431- JSON . stringify ( {
485+ JSON . stringify ( {
432486 ...devices [ 'iPad Pro 11' ] ,
433- } )
487+ } ) ,
434488 ] )
435489 . run ( ) ;
436490 await cli . waitFor ( 'step/end' ) ;
@@ -465,13 +519,14 @@ class CLIMock {
465519 return this ;
466520 }
467521
468- run ( ) : CLIMock {
522+ run ( spawnOverrides ?: { cwd ?: string } ) : CLIMock {
469523 this . process = spawn (
470524 'node' ,
471525 [ join ( __dirname , '..' , 'dist' , 'cli.js' ) , ...this . cliArgs ] ,
472526 {
473527 env : process . env ,
474528 stdio : 'pipe' ,
529+ ...spawnOverrides ,
475530 }
476531 ) ;
477532
0 commit comments