-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add check for msbridge config files (#26)
- Loading branch information
1 parent
4553799
commit 0498aa7
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
jest.mock("fs"); | ||
const { readdirSync } = require("fs"); | ||
const { FatalError } = require("../errors"); | ||
const hasMSBridgeConfig = require("../checks/msbridge"); | ||
|
||
describe("Fail if yarn.lock exists", () => { | ||
it("should fail for local config", () => { | ||
jest | ||
.mocked(readdirSync) | ||
.mockImplementationOnce(() => [ | ||
"index.js", | ||
".msbridge.local.json", | ||
"package.json", | ||
]); | ||
expect(hasMSBridgeConfig()).toBeInstanceOf(FatalError); | ||
}); | ||
it("should fail for amplify config", () => { | ||
jest | ||
.mocked(readdirSync) | ||
.mockImplementationOnce(() => [ | ||
"index.js", | ||
".msbridge.amplify.json", | ||
"package.json", | ||
]); | ||
expect(hasMSBridgeConfig()).toBeInstanceOf(FatalError); | ||
}); | ||
it("should fail for standard config", () => { | ||
jest | ||
.mocked(readdirSync) | ||
.mockImplementationOnce(() => [ | ||
"index.js", | ||
".msbridge.json", | ||
"package.json", | ||
]); | ||
expect(hasMSBridgeConfig()).toBeInstanceOf(FatalError); | ||
}); | ||
it("should not fail when no config", () => { | ||
jest | ||
.mocked(readdirSync) | ||
.mockImplementationOnce(() => ["index.js", "package.json"]); | ||
expect(hasMSBridgeConfig()).toBeUndefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const { readdirSync } = require("fs"); | ||
const { FatalError } = require("../errors"); | ||
|
||
function hasMSBridgeConfig() { | ||
try { | ||
const allRootFiles = readdirSync("."); | ||
for (const file of allRootFiles) { | ||
if (file.startsWith(".msbridge") && file.endsWith(".json")) { | ||
return new FatalError("Unexpected " + file + " file detected"); | ||
} | ||
} | ||
} catch (e) { | ||
return undefined; | ||
} | ||
} | ||
|
||
module.exports = hasMSBridgeConfig; |