This repository has been archived by the owner on Mar 22, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: throw unsupported OS error on a method call (#296)
- Loading branch information
Showing
10 changed files
with
41 additions
and
20 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
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
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 |
---|---|---|
@@ -1,8 +1,3 @@ | ||
export { default as print } from "./print/print"; | ||
export { default as getPrinters } from "./get-printers/get-printers"; | ||
export { default as getDefaultPrinter } from "./get-default-printer/get-default-printer"; | ||
import os from "os"; | ||
|
||
if (os.platform() !== "win32") { | ||
throw new Error("Platform not supported"); | ||
} |
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,24 @@ | ||
jest.mock("os"); | ||
|
||
let os; | ||
let throwIfUnsupportedOs; | ||
|
||
beforeEach(() => { | ||
jest.resetModules(); | ||
os = require("os"); | ||
throwIfUnsupportedOs = require("./throw-if-unsupported-os").default; | ||
}); | ||
|
||
it("does not throw on Windows", () => { | ||
os.platform.mockImplementation(() => "win32"); | ||
expect(() => throwIfUnsupportedOs()).not.toThrowError(); | ||
}); | ||
|
||
["linux", "darwin", "test"].forEach((platform) => { | ||
it(`throws on unsupported platform ${platform}`, () => { | ||
os.platform.mockImplementation(() => platform); | ||
expect(() => throwIfUnsupportedOs()).toThrowError( | ||
"Operating System not supported" | ||
); | ||
}); | ||
}); |
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,7 @@ | ||
import os from "os"; | ||
|
||
export default function throwIfUnsupportedOs() { | ||
if (os.platform() !== "win32") { | ||
throw "Operating System not supported"; | ||
} | ||
} |