@@ -33,15 +33,15 @@ const FIXTURES_DIR = join(__dirname, 'fixtures');
3333describe ( 'Config' , ( ) => {
3434 it ( 'read config based on environment' , async ( ) => {
3535 const configPath = join ( FIXTURES_DIR , 'synthetics.config.ts' ) ;
36- expect ( readConfig ( 'development' , configPath ) ) . toMatchObject ( {
36+ expect ( await readConfig ( 'development' , configPath ) ) . toMatchObject ( {
3737 params : {
3838 url : 'dev' ,
3939 } ,
4040 playwrightOptions : {
4141 ...devices [ 'Galaxy S9+' ] ,
4242 } ,
4343 } ) ;
44- expect ( readConfig ( 'testing' , configPath ) ) . toMatchObject ( {
44+ expect ( await readConfig ( 'testing' , configPath ) ) . toMatchObject ( {
4545 params : {
4646 url : 'non-dev' ,
4747 } ,
@@ -50,15 +50,35 @@ describe('Config', () => {
5050
5151 it ( 'throw error when config does not exist' , async ( ) => {
5252 const tempPath = generateTempPath ( ) ;
53- function getConfig ( ) {
54- readConfig ( 'development' , tempPath ) ;
55- }
56- expect ( getConfig ) . toThrowError (
53+ expect ( readConfig ( 'development' , tempPath ) ) . rejects . toThrow (
5754 new Error ( 'Synthetics config file does not exist: ' + tempPath )
5855 ) ;
5956 } ) ;
6057
6158 it ( 'recursively look for configs and exit' , async ( ) => {
62- expect ( readConfig ( 'development' ) ) . toEqual ( { } ) ;
59+ expect ( await readConfig ( 'development' ) ) . toEqual ( { } ) ;
60+ } ) ;
61+
62+ describe ( 'read config async' , ( ) => {
63+ it ( 'merge async config' , async ( ) => {
64+ const configPath = join ( FIXTURES_DIR , 'async-params.config.ts' ) ;
65+ expect ( await readConfig ( 'development' , configPath ) ) . toMatchObject ( {
66+ params : {
67+ url : 'dev' ,
68+ } ,
69+ } ) ;
70+ expect ( await readConfig ( 'testing' , configPath ) ) . toMatchObject ( {
71+ params : {
72+ url : 'non-dev' ,
73+ } ,
74+ } ) ;
75+ } ) ;
76+
77+ it ( 'catch errors on async config' , async ( ) => {
78+ const configPath = join ( FIXTURES_DIR , 'async-params-err.config.ts' ) ;
79+ expect ( readConfig ( 'development' , configPath ) ) . rejects . toThrow (
80+ 'failed to fetch params'
81+ ) ;
82+ } ) ;
6383 } ) ;
6484} ) ;
0 commit comments