Skip to content

Commit ae0d282

Browse files
committed
test(terraform-module): add terraform-module tests
- Adds full coverage for the terraform-module component - Refactor shared types into `/src/types` - Add one additional function into `/utils/string`
1 parent 0ff826e commit ae0d282

27 files changed

+981
-427
lines changed

__tests__/_setup.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ vi.mock('@actions/core');
77
vi.mock('@/config');
88
vi.mock('@/context');
99

10+
11+
// Mock console time/timeEnd to be a no-op
12+
vi.spyOn(console, 'time').mockImplementation(() => {});
13+
vi.spyOn(console, 'timeEnd').mockImplementation(() => {});
14+
1015
const defaultEnvironmentVariables = {
1116
GITHUB_EVENT_NAME: 'pull_request',
1217
GITHUB_REPOSITORY: 'techpivot/terraform-module-releaser',

__tests__/changelog.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { getModuleChangelog, getModuleReleaseChangelog, getPullRequestChangelog } from '@/changelog';
22
import { context } from '@/mocks/context';
3-
import type { TerraformChangedModule, TerraformModule } from '@/terraform-module';
3+
import type { TerraformChangedModule, TerraformModule } from '@/types';
44
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
55

66
describe('changelog', () => {
77
const mockDate = new Date('2024-11-05');
88

99
beforeEach(() => {
10-
vi.useFakeTimers();
10+
//vi.useFakeTimers();
1111
vi.setSystemTime(mockDate);
1212

1313
// Reset context mock before each test

__tests__/config.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { clearConfigForTesting, config, getConfig } from '@/config';
2+
import { booleanConfigKeys, booleanInputs, requiredInputs, stubInputEnv } from '@/tests/helpers/inputs';
23
import { endGroup, getBooleanInput, getInput, info, startGroup } from '@actions/core';
34
import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
45

5-
import { booleanConfigKeys, booleanInputs, requiredInputs, stubInputEnv } from '@/tests/helpers/inputs';
6-
76
describe('config', () => {
87
beforeAll(() => {
98
// We globally mock context to facilitate majority of testing; however,

__tests__/helpers/inputs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Config } from '@/config';
1+
import type { Config } from '@/types';
22
import { vi } from 'vitest';
33

44
const INPUT_KEY = 'INPUT_';

__tests__/index.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as main from '@/main';
2+
import { describe, expect, it, vi } from 'vitest';
3+
4+
// Mock the main module's run function
5+
vi.spyOn(main, 'run').mockImplementation(async () => {});
6+
7+
describe('index', () => {
8+
it('calls run when imported', async () => {
9+
await import('@/index');
10+
expect(main.run).toHaveBeenCalled();
11+
});
12+
});

__tests__/pull-request.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { config } from '@/mocks/config';
22
import { context } from '@/mocks/context';
33
import { addPostReleaseComment, addReleasePlanComment, getPullRequestCommits, hasReleaseComment } from '@/pull-request';
4-
import type { GitHubRelease } from '@/releases';
5-
import type { TerraformChangedModule } from '@/terraform-module';
64
import { stubOctokitImplementation, stubOctokitReturnData } from '@/tests/helpers/octokit';
5+
import type { GitHubRelease, TerraformChangedModule } from '@/types';
76
import { BRANDING_COMMENT, GITHUB_ACTIONS_BOT_USER_ID, PR_RELEASE_MARKER, PR_SUMMARY_MARKER } from '@/utils/constants';
87
import { WikiStatus } from '@/wiki';
98
import { debug, endGroup, info, startGroup } from '@actions/core';

__tests__/releases.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { config } from '@/mocks/config';
22
import { context } from '@/mocks/context';
33
import { createTaggedRelease, deleteLegacyReleases, getAllReleases } from '@/releases';
4-
import type { GitHubRelease } from '@/releases';
5-
import type { TerraformChangedModule } from '@/terraform-module';
64
import { stubOctokitReturnData } from '@/tests/helpers/octokit';
5+
import type { GitHubRelease, TerraformChangedModule } from '@/types';
76
import { debug, endGroup, info, startGroup } from '@actions/core';
87
import { RequestError } from '@octokit/request-error';
98
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';

__tests__/terraform-docs.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { join } from 'node:path';
55
import { promisify } from 'node:util';
66
import { context } from '@/mocks/context';
77
import { ensureTerraformDocsConfigDoesNotExist, generateTerraformDocs, installTerraformDocs } from '@/terraform-docs';
8-
import type { TerraformModule } from '@/terraform-module';
8+
import type { TerraformModule } from '@/types';
99
import { info } from '@actions/core';
1010
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
1111
import which from 'which';

0 commit comments

Comments
 (0)