Skip to content

Commit d83d34a

Browse files
committed
test(credential-providers): attempt to migrate integ tests to vitest
mock for readFile is not working, probably because of imports across multiple transitive dependencies
1 parent ac8960b commit d83d34a

File tree

3 files changed

+13
-19
lines changed

3 files changed

+13
-19
lines changed

packages/credential-providers/jest.config.integ.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

packages/credential-providers/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
1818
"extract:docs": "api-extractor run --local",
1919
"test": "yarn g:vitest run",
20-
"test:integration": "npx jest -c jest.config.integ.js",
21-
"test:watch": "yarn g:vitest watch"
20+
"test:watch": "yarn g:vitest watch",
21+
"test:integration": "yarn g:vitest run -c vitest.config.integ.mts",
22+
"test:integration:watch": "yarn g:vitest watch -c vitest.config.integ.mts"
2223
},
2324
"keywords": [
2425
"aws",
Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import fs from "fs";
1+
import { promises } from "fs";
22
import { homedir } from "os";
33
import { join } from "path";
4+
import { afterEach, beforeEach, describe, expect, test as it, vi } from "vitest";
45

56
import { fromSSO } from "./fromSSO";
67

@@ -15,22 +16,18 @@ sso_start_url = https://my-sso-portal.awsapps.com/start
1516
sso_registration_scopes = sso:account:access
1617
`;
1718

18-
jest.mock("fs", () => {
19-
return {
20-
promises: {
21-
readFile: jest.fn(),
22-
},
23-
};
24-
});
19+
vi.mock("fs", () => ({ promises: { readFile: vi.fn() } }));
2520

2621
describe("fromSSO integration test", () => {
2722
beforeEach(() => {
28-
jest.resetAllMocks();
23+
vi.mocked(promises.readFile).mockResolvedValue(SAMPLE_CONFIG);
2924
});
3025

31-
it("should expand relative homedir", async () => {
32-
const mockReadFile = (fs.promises.readFile as jest.Mock).mockResolvedValue(SAMPLE_CONFIG);
26+
afterEach(() => {
27+
vi.clearAllMocks();
28+
});
3329

30+
it("should expand relative homedir", async () => {
3431
try {
3532
await fromSSO({
3633
profile: "dev",
@@ -39,7 +36,7 @@ describe("fromSSO integration test", () => {
3936
})();
4037
} catch (ignored) {}
4138

42-
expect(mockReadFile).toHaveBeenCalledWith(join(homedir(), "custom/path/to/credentials"), "utf8");
43-
expect(mockReadFile).toHaveBeenCalledWith(join(homedir(), "custom/path/to/config"), "utf8");
39+
expect(promises.readFile).toHaveBeenCalledWith(join(homedir(), "custom/path/to/credentials"), "utf8");
40+
expect(promises.readFile).toHaveBeenCalledWith(join(homedir(), "custom/path/to/config"), "utf8");
4441
});
4542
});

0 commit comments

Comments
 (0)