1+ /* eslint-disable global-require */
12jest . mock ( "./stepDefinitionPath.js" , ( ) => ( ) => "stepDefinitionPath" ) ;
23jest . mock ( "glob" , ( ) => ( {
34 sync ( pattern ) {
45 return pattern ;
56 }
67} ) ) ;
78
9+ let getConfig ;
10+
811describe ( "getStepDefinitionsPaths" , ( ) => {
9- it ( "should return the default common folder" , ( ) => {
12+ beforeEach ( ( ) => {
1013 jest . resetModules ( ) ;
11- jest . mock ( "cosmiconfig" , ( ) => ( ) => ( {
12- load : ( ) => ( {
13- config : {
14- nonGlobalStepDefinitions : true
15- }
16- } )
17- } ) ) ;
18- // eslint-disable-next-line global-require
14+ ( { getConfig } = require ( "./getConfig" ) ) ;
15+ jest . mock ( "./getConfig" ) ;
16+ } ) ;
17+ it ( "should return the default common folder" , ( ) => {
18+ getConfig . mockReturnValue ( {
19+ nonGlobalStepDefinitions : true
20+ } ) ;
21+
1922 const { getStepDefinitionsPaths } = require ( "./getStepDefinitionsPaths" ) ;
2023
2124 const actual = getStepDefinitionsPaths ( "/path" ) ;
@@ -24,26 +27,28 @@ describe("getStepDefinitionsPaths", () => {
2427 expect ( actual ) . to . include ( expected ) ;
2528 } ) ;
2629
27- it ( "should return the common folder defined by the developper" , ( ) => {
28- jest . resetModules ( ) ;
30+ it ( "should return the common folder defined by the developer" , ( ) => {
31+ jest . mock ( "path" , ( ) => ( {
32+ resolve ( appRoot , commonPath ) {
33+ return `./${ appRoot } /${ commonPath } ` ;
34+ } ,
35+ extname ( ) {
36+ return ".js" ;
37+ }
38+ } ) ) ;
2939
3040 jest . mock ( "fs" ) ;
3141 jest . spyOn ( process , "cwd" ) . mockImplementation ( ( ) => "cwd" ) ;
3242
33- jest . mock ( "cosmiconfig" , ( ) => ( ) => ( {
34- load : ( ) => ( {
35- config : {
36- nonGlobalStepDefinitions : true ,
37- commonPath : "myPath/"
38- }
39- } )
40- } ) ) ;
41- // eslint-disable-next-line global-require
43+ getConfig . mockReturnValue ( {
44+ nonGlobalStepDefinitions : true ,
45+ commonPath : "myPath/"
46+ } ) ;
47+
4248 const { getStepDefinitionsPaths } = require ( "./getStepDefinitionsPaths" ) ;
4349
4450 const actual = getStepDefinitionsPaths ( "/path" ) ;
45- const expected = "cwd/myPath/**/*.+(js|ts)" ;
46-
51+ const expected = "./cwd/myPath/**/*.+(js|ts)" ;
4752 expect ( actual ) . to . include ( expected ) ;
4853 } ) ;
4954} ) ;
0 commit comments