Skip to content

Commit 4c661d8

Browse files
committed
feat(docs): add terraform-docs tests
Additionally, support installing and running the action on Windows based systems.
1 parent 367702d commit 4c661d8

12 files changed

+750
-102
lines changed

__tests__/__mocks__/context.mock.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,33 @@ const defaultPullRequestPayload = {
7979
},
8080
};
8181

82-
// Create a mock context factory function
83-
//export function createContextMock(overrides: Partial<Context> = {}): Context {
84-
// return merge(defaultContext, overrides);
85-
//}
86-
8782
// Create a mock pull request factory function
8883
export function createPullRequestMock(overrides = {}) {
8984
return merge(defaultPullRequestPayload, overrides);
9085
}
9186

92-
// Create the mock handler
93-
export const contextMock = vi.fn(() => defaultContext);
87+
// Create a mocked context object with a set method to deep merge additional ovverides.
88+
export const contextMock: Context & {
89+
reset: () => void;
90+
set: (overrides?: Partial<Context>) => void;
91+
} = {
92+
...defaultContext,
93+
94+
reset: () => {
95+
for (const key of Object.keys(defaultContext)) {
96+
if (key !== 'reset' && key !== 'set') {
97+
contextMock[key] = defaultContext[key];
98+
}
99+
}
100+
},
101+
102+
// Method to update specific values
103+
set: (overrides: Partial<Context> = {}) => {
104+
const updated = merge(contextMock, overrides);
105+
for (const key of Object.keys(updated)) {
106+
if (key !== 'reset' && key !== 'set') {
107+
contextMock[key] = updated[key];
108+
}
109+
}
110+
},
111+
};

__tests__/context.test.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ import { clearContextForTesting, context, getContext } from '../src/context';
44
import { createPullRequestMock } from './__mocks__/context.mock';
55
import { mockCore } from './setup';
66

7-
// Mock functions
8-
vi.mock('node:fs', () => ({
9-
existsSync: vi.fn(),
10-
readFileSync: vi.fn(),
11-
}));
7+
// Mock node:fs. (Note: Appears we can't spy on functions via node:fs)
8+
vi.mock('node:fs', async () => {
9+
const original = await vi.importActual('node:fs');
10+
return {
11+
...original,
12+
existsSync: vi.fn(),
13+
readFileSync: vi.fn(),
14+
};
15+
});
1216

1317
describe('context', () => {
1418
// Mock implementations for fs just in this current test

0 commit comments

Comments
 (0)