11import fs from 'node:fs' ;
2- import { describe , it , after , mock } from 'node:test' ;
2+ import { describe , it , afterEach , mock } from 'node:test' ;
33import assert from 'node:assert' ;
44import { resolve } from 'node:path' ;
55import { version } from '../../../package.json' ;
@@ -13,21 +13,29 @@ describe('./utils/config.ts', () => {
1313 // behaving
1414 describe ( 'variables' , ( ) => {
1515 const originalReadFileSync = fs . readFileSync ;
16- function mockRc ( env : Record < string , string > = { } ) {
16+ function mockRc (
17+ env : Record < string , string > = { } ,
18+ prodEnv : Record < string , string > = { } ,
19+ ) {
1720 mock . method ( fs , 'readFileSync' , ( path : string , options : object ) => {
21+ // mock the rc files as users might have customized it which may break our tests
1822 if ( path === resolve ( __dirname , '../../../.metamaskrc' ) ) {
19- // mock `.metamaskrc`, as users might have customized it which may
20- // break our tests
2123 return `
22- ${ Object . entries ( env )
23- . map ( ( [ key , value ] ) => `${ key } =${ value } ` )
24- . join ( '\n' ) }
25- ` ;
24+ ${ Object . entries ( env )
25+ . map ( ( [ key , value ] ) => `${ key } =${ value } ` )
26+ . join ( '\n' ) }
27+ ` ;
28+ } else if ( path === resolve ( __dirname , '../../../.metamaskprodrc' ) ) {
29+ return `
30+ ${ Object . entries ( prodEnv )
31+ . map ( ( [ key , value ] ) => `${ key } =${ value } ` )
32+ . join ( '\n' ) }
33+ ` ;
2634 }
2735 return originalReadFileSync ( path , options ) ;
2836 } ) ;
2937 }
30- after ( ( ) => mock . restoreAll ( ) ) ;
38+ afterEach ( ( ) => mock . restoreAll ( ) ) ;
3139
3240 it ( 'should return valid build variables for the default build' , ( ) => {
3341 const buildTypes = loadBuildTypesConfig ( ) ;
@@ -49,17 +57,31 @@ ${Object.entries(env)
4957 ) ;
5058 } ) ;
5159
52- it ( 'should prefer .metamaskrc variables over others ' , ( ) => {
60+ it ( 'should prefer .metamaskprodrc over .metamaskrc ' , ( ) => {
5361 const buildTypes = loadBuildTypesConfig ( ) ;
5462 const { args } = parseArgv ( [ ] , buildTypes ) ;
5563 const defaultVars = config . getVariables ( args , buildTypes ) ;
5664
5765 // verify the default value of the main build is false
5866 assert . strictEqual ( defaultVars . variables . get ( 'ALLOW_LOCAL_SNAPS' ) , false ) ;
5967
60- mockRc ( {
61- ALLOW_LOCAL_SNAPS : 'true' ,
62- } ) ;
68+ mockRc ( { ALLOW_LOCAL_SNAPS : 'false' } , { ALLOW_LOCAL_SNAPS : 'true' } ) ;
69+
70+ const overrides = config . getVariables ( args , buildTypes ) ;
71+
72+ // verify the value of the main build is set to the value in .metamaskprodrc
73+ assert . strictEqual ( overrides . variables . get ( 'ALLOW_LOCAL_SNAPS' ) , true ) ;
74+ } ) ;
75+
76+ it ( 'should prefer .metamaskrc variables over builds.yml' , ( ) => {
77+ const buildTypes = loadBuildTypesConfig ( ) ;
78+ const { args } = parseArgv ( [ ] , buildTypes ) ;
79+ const defaultVars = config . getVariables ( args , buildTypes ) ;
80+
81+ // verify the default value of the main build is false
82+ assert . strictEqual ( defaultVars . variables . get ( 'ALLOW_LOCAL_SNAPS' ) , false ) ;
83+
84+ mockRc ( { ALLOW_LOCAL_SNAPS : 'true' } ) ;
6385
6486 const overrides = config . getVariables ( args , buildTypes ) ;
6587
@@ -68,10 +90,8 @@ ${Object.entries(env)
6890 } ) ;
6991
7092 it ( 'should return valid build variables for a non-default build' , ( ) => {
71- mockRc ( {
72- // required by the `beta` build type
73- SEGMENT_BETA_WRITE_KEY : '.' ,
74- } ) ;
93+ // required by the `beta` build type
94+ mockRc ( { SEGMENT_BETA_WRITE_KEY : '.' } ) ;
7595 const buildTypes = loadBuildTypesConfig ( ) ;
7696 const { args } = parseArgv (
7797 [ '--type' , 'beta' , '--test' , '--env' , 'production' ] ,
0 commit comments