File tree Expand file tree Collapse file tree 2 files changed +60
-0
lines changed
Expand file tree Collapse file tree 2 files changed +60
-0
lines changed Original file line number Diff line number Diff line change 1+ jest . mock ( "fs" ) ;
2+ const { readdirSync } = require ( "fs" ) ;
3+ const { FatalError } = require ( "../errors" ) ;
4+ const hasMSBridgeConfig = require ( "../checks/msbridge" ) ;
5+
6+ describe ( "Fail if yarn.lock exists" , ( ) => {
7+ it ( "should fail for local config" , ( ) => {
8+ jest
9+ . mocked ( readdirSync )
10+ . mockImplementationOnce ( ( ) => [
11+ "index.js" ,
12+ ".msbridge.local.json" ,
13+ "package.json" ,
14+ ] ) ;
15+ expect ( hasMSBridgeConfig ( ) ) . toBeInstanceOf ( FatalError ) ;
16+ } ) ;
17+ it ( "should fail for amplify config" , ( ) => {
18+ jest
19+ . mocked ( readdirSync )
20+ . mockImplementationOnce ( ( ) => [
21+ "index.js" ,
22+ ".msbridge.amplify.json" ,
23+ "package.json" ,
24+ ] ) ;
25+ expect ( hasMSBridgeConfig ( ) ) . toBeInstanceOf ( FatalError ) ;
26+ } ) ;
27+ it ( "should fail for standard config" , ( ) => {
28+ jest
29+ . mocked ( readdirSync )
30+ . mockImplementationOnce ( ( ) => [
31+ "index.js" ,
32+ ".msbridge.json" ,
33+ "package.json" ,
34+ ] ) ;
35+ expect ( hasMSBridgeConfig ( ) ) . toBeInstanceOf ( FatalError ) ;
36+ } ) ;
37+ it ( "should not fail when no config" , ( ) => {
38+ jest
39+ . mocked ( readdirSync )
40+ . mockImplementationOnce ( ( ) => [ "index.js" , "package.json" ] ) ;
41+ expect ( hasMSBridgeConfig ( ) ) . toBeUndefined ( ) ;
42+ } ) ;
43+ } ) ;
Original file line number Diff line number Diff line change 1+ const { readdirSync } = require ( "fs" ) ;
2+ const { FatalError } = require ( "../errors" ) ;
3+
4+ function hasMSBridgeConfig ( ) {
5+ try {
6+ const allRootFiles = readdirSync ( "." ) ;
7+ for ( const file of allRootFiles ) {
8+ if ( file . startsWith ( ".msbridge" ) && file . endsWith ( ".json" ) ) {
9+ return new FatalError ( "Unexpected " + file + " file detected" ) ;
10+ }
11+ }
12+ } catch ( e ) {
13+ return undefined ;
14+ }
15+ }
16+
17+ module . exports = hasMSBridgeConfig ;
You can’t perform that action at this time.
0 commit comments