Skip to content

Commit

Permalink
feat(docs): add terraform-docs tests
Browse files Browse the repository at this point in the history
Additionally, support installing and running the action
on Windows based systems.
  • Loading branch information
virgofx committed Oct 31, 2024
1 parent 367702d commit 4c661d8
Show file tree
Hide file tree
Showing 12 changed files with 750 additions and 102 deletions.
32 changes: 25 additions & 7 deletions __tests__/__mocks__/context.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,33 @@ const defaultPullRequestPayload = {
},
};

// Create a mock context factory function
//export function createContextMock(overrides: Partial<Context> = {}): Context {
// return merge(defaultContext, overrides);
//}

// Create a mock pull request factory function
export function createPullRequestMock(overrides = {}) {
return merge(defaultPullRequestPayload, overrides);
}

// Create the mock handler
export const contextMock = vi.fn(() => defaultContext);
// Create a mocked context object with a set method to deep merge additional ovverides.
export const contextMock: Context & {
reset: () => void;
set: (overrides?: Partial<Context>) => void;
} = {
...defaultContext,

reset: () => {
for (const key of Object.keys(defaultContext)) {
if (key !== 'reset' && key !== 'set') {
contextMock[key] = defaultContext[key];
}
}
},

// Method to update specific values
set: (overrides: Partial<Context> = {}) => {
const updated = merge(contextMock, overrides);
for (const key of Object.keys(updated)) {
if (key !== 'reset' && key !== 'set') {
contextMock[key] = updated[key];
}
}
},
};
14 changes: 9 additions & 5 deletions __tests__/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ import { clearContextForTesting, context, getContext } from '../src/context';
import { createPullRequestMock } from './__mocks__/context.mock';
import { mockCore } from './setup';

// Mock functions
vi.mock('node:fs', () => ({
existsSync: vi.fn(),
readFileSync: vi.fn(),
}));
// Mock node:fs. (Note: Appears we can't spy on functions via node:fs)
vi.mock('node:fs', async () => {
const original = await vi.importActual('node:fs');
return {
...original,
existsSync: vi.fn(),
readFileSync: vi.fn(),
};
});

describe('context', () => {
// Mock implementations for fs just in this current test
Expand Down
Loading

0 comments on commit 4c661d8

Please sign in to comment.