Skip to content

Commit

Permalink
initial mocking of the os module works
Browse files Browse the repository at this point in the history
  • Loading branch information
khill-fbmc committed Nov 19, 2023
1 parent 1c614e0 commit 320b203
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
5 changes: 5 additions & 0 deletions __mocks__/os.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { vi } from "vitest";

export default {
type: vi.fn(() => 'Linux')
}
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
},
"devDependencies": {
"node-gyp": "^10.0.1",
"vite": "^5.0.0",
"vitest": "^0.34.6"
}
}
7 changes: 6 additions & 1 deletion test/00-core.test.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { describe, it } from "vitest";
import os from "os";
import { describe, it, vi } from "vitest";

describe("libgpiod miscellaneous bindings", () => {
it("should be running in a mocked Linux", async ({ expect }) => {
expect(os.type()).toBe('Linux');
});

it("should be available", async ({ expect }) => {
expect(gpiod.available()).toBeTruthy();
});
Expand Down
12 changes: 6 additions & 6 deletions test/setup.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { gpiod } from "../index.mjs";

import { afterAll, beforeAll } from 'vitest';
import { afterEach, beforeEach } from 'vitest';

beforeAll(() => {
if (!globalThis.gpiod) {
globalThis.gpiod = gpiod;
}
vi.mock("os");

beforeEach(async () => {
if (!globalThis.gpiod) globalThis.gpiod = gpiod;
});

afterAll(() => {
afterEach(() => {
delete globalThis.gpiod;
});

0 comments on commit 320b203

Please sign in to comment.