This repository has been archived by the owner on Jun 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0d58bd
commit d3132b9
Showing
3 changed files
with
70 additions
and
1 deletion.
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
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
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,69 @@ | ||
const sinon = require("sinon"); | ||
|
||
const link = require("../src/link"); | ||
const unlink = require("../src/unlink"); | ||
const check = require("../src/check"); | ||
|
||
const command = require("../src/command"); | ||
|
||
describe("command", () => { | ||
let sandbox; | ||
let originalArgs; | ||
|
||
beforeAll(() => { | ||
originalArgs = [...process.argv]; | ||
}); | ||
|
||
beforeEach(() => { | ||
sandbox = sinon.createSandbox(); | ||
sandbox.stub(link, "all").resolves(); | ||
sandbox.stub(link, "select").resolves(); | ||
sandbox.stub(unlink, "all").resolves(); | ||
sandbox.stub(check, "avoidFileLinks").resolves(); | ||
}); | ||
|
||
afterEach(() => { | ||
process.argv = [...originalArgs]; | ||
sandbox.restore(); | ||
}); | ||
|
||
describe("runAndCatch method", () => { | ||
it("should mark process to exit with error if command throws an error", async () => { | ||
expect.assertions(2); | ||
link.select.rejects(new Error("Foo error")); | ||
sandbox.stub(console, "log"); | ||
await command.runAndCatch(); | ||
expect(process.exitCode).toEqual(1); | ||
process.exitCode = 0; | ||
expect(console.log.getCall(0).args[0]).toEqual(expect.stringContaining("Foo error")); | ||
}); | ||
|
||
it("should link selected packages by default", async () => { | ||
expect.assertions(1); | ||
await command.runAndCatch(); | ||
expect(link.select.callCount).toEqual(1); | ||
}); | ||
|
||
it("should link all packages if --all option is received", async () => { | ||
expect.assertions(1); | ||
process.argv.push("--all"); | ||
await command.runAndCatch(); | ||
expect(link.all.callCount).toEqual(1); | ||
}); | ||
|
||
it("should unlink all packages if --all and --unlink options are received", async () => { | ||
expect.assertions(1); | ||
process.argv.push("--all"); | ||
process.argv.push("--unlink"); | ||
await command.runAndCatch(); | ||
expect(unlink.all.callCount).toEqual(1); | ||
}); | ||
|
||
it("should check links if --check option is received", async () => { | ||
expect.assertions(1); | ||
process.argv.push("--check"); | ||
await command.runAndCatch(); | ||
expect(check.avoidFileLinks.callCount).toEqual(1); | ||
}); | ||
}); | ||
}); |