Skip to content

Commit

Permalink
Add check for msbridge config files (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippeauriach committed Apr 24, 2023
1 parent 4553799 commit 0498aa7
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
43 changes: 43 additions & 0 deletions lib/__tests__/msbridge.test.js
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();
});
});
17 changes: 17 additions & 0 deletions lib/checks/msbridge.js
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;

0 comments on commit 0498aa7

Please sign in to comment.