Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtiomTr committed Mar 6, 2024
1 parent d1c72f2 commit 151a065
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 27 deletions.
9 changes: 5 additions & 4 deletions tests/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from '../src/stages/switchBranch';
import { JsonReport } from '../src/typings/JsonReport';
import { getOptions, Options } from '../src/typings/Options';
import { SummaryReport, TestRunReport } from '../src/typings/Report';
import { SummaryReport } from '../src/typings/Report';
import { CollectedData, createDataCollector } from '../src/utils/DataCollector';

const { mockContext, clearContextMock } = all as any;
Expand Down Expand Up @@ -237,6 +237,9 @@ const loadConfigMock = mocked(loadConfig);
create: (fn: () => any) => {
fn();
},
listForRef: () => {
throw new Error('failure');
},
},
},
});
Expand All @@ -254,9 +257,7 @@ beforeEach(() => {

getOptionsMock.mockResolvedValue(defaultOptions);
getCoverageMock.mockResolvedValue(standardReport);
createReportMock.mockReturnValue({
runReport: {} as TestRunReport,
} as SummaryReport);
createReportMock.mockReturnValue({} as SummaryReport);
loadConfigMock.mockResolvedValue({
config: {},
});
Expand Down
21 changes: 0 additions & 21 deletions tests/stages/__snapshots__/createReport.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@

exports[`createReport should match snapshots (failed report) 1`] = `
Object {
"runReport": Object {
"failures": "",
"success": false,
"summary": "Failed tests: 0/12. Failed suites: 0/5.",
"title": "Test suite run failed",
},
"text": "<!-- jest coverage report action for options with hash 07a2060717d2c01f3ad9c6a8cfe3ca1b -->
## Coverage report
Expand All @@ -31,11 +25,6 @@ Failed tests: 0/12. Failed suites: 0/5.
exports[`createReport should match snapshots 1`] = `
Object {
"runReport": Object {
"success": true,
"summary": "12 tests passing in 5 suites.",
"title": "Test suite run success",
},
"text": "<!-- jest coverage report action for options with hash 8f0735414be39738f79dc9c8549004e2 -->
## Coverage report for \`custom directory\`
Expand All @@ -59,11 +48,6 @@ Object {
exports[`createReport should match snapshots 2`] = `
Object {
"runReport": Object {
"success": true,
"summary": "12 tests passing in 5 suites.",
"title": "Test suite run success",
},
"text": "<!-- jest coverage report action for options with hash 07a2060717d2c01f3ad9c6a8cfe3ca1b -->
## Coverage report
Expand All @@ -87,11 +71,6 @@ Object {
exports[`createReport should match snapshots 3`] = `
Object {
"runReport": Object {
"success": true,
"summary": "12 tests passing in 5 suites.",
"title": "Test suite run success",
},
"text": "<!-- jest coverage report action for options with hash 7e82ebc2d1870f828e62dde34753f616 -->
## Custom title with directory - for \`directory\`
Expand Down
17 changes: 15 additions & 2 deletions tests/stages/createReport.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as all from '@actions/github';

import { createReport, getSha } from '../../src/stages/createReport';
import { createRunReport } from '../../src/stages/createRunReport';
import { JsonReport } from '../../src/typings/JsonReport';
import { Options } from '../../src/typings/Options';
import { createDataCollector } from '../../src/utils/DataCollector';
Expand Down Expand Up @@ -41,6 +42,7 @@ describe('createReport', () => {
expect(
await createReport(
dataCollector,
createRunReport(report),
{
...DEFAULT_OPTIONS,
workingDirectory: 'custom directory',
Expand All @@ -49,12 +51,18 @@ describe('createReport', () => {
)
).toMatchSnapshot();
expect(
await createReport(dataCollector, DEFAULT_OPTIONS, [])
await createReport(
dataCollector,
createRunReport(report),
DEFAULT_OPTIONS,
[]
)
).toMatchSnapshot();

expect(
await createReport(
dataCollector,
createRunReport(report),
{
...DEFAULT_OPTIONS,
workingDirectory: 'directory',
Expand All @@ -74,7 +82,12 @@ describe('createReport', () => {
mockContext({ payload: { after: '123456' } });

expect(
await createReport(dataCollector, DEFAULT_OPTIONS, [])
await createReport(
dataCollector,
createRunReport({ ...report, success: false }),
DEFAULT_OPTIONS,
[]
)
).toMatchSnapshot();

clearContextMock();
Expand Down

0 comments on commit 151a065

Please sign in to comment.