Skip to content

Commit

Permalink
Add unit tests for new default reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoH2O1999 committed Nov 24, 2022
1 parent 51a2d18 commit 5eaf7cb
Showing 1 changed file with 203 additions and 3 deletions.
206 changes: 203 additions & 3 deletions packages/jest-core/src/__tests__/TestScheduler.test.js
Expand Up @@ -10,6 +10,7 @@ import {
CoverageReporter,
DefaultReporter,
GitHubActionsReporter,
GithubActionsLogsReporter,
NotifyReporter,
SummaryReporter,
VerboseReporter,
Expand Down Expand Up @@ -59,13 +60,203 @@ beforeEach(() => {
spyShouldRunInBand.mockClear();
});

describe('reporters', () => {
describe('reporters with GITHUB_ACTIONS = true', () => {
const CustomReporter = require('/custom-reporter.js');

afterEach(() => {
jest.clearAllMocks();
});

test('works with default value', async () => {
await createTestScheduler(
makeGlobalConfig({
reporters: undefined,
}),
{},
{},
);

expect(DefaultReporter).toHaveBeenCalledTimes(0);
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(1);
expect(VerboseReporter).toHaveBeenCalledTimes(0);
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
expect(NotifyReporter).toHaveBeenCalledTimes(0);
expect(CoverageReporter).toHaveBeenCalledTimes(0);
expect(SummaryReporter).toHaveBeenCalledTimes(1);
});

test('does not enable any reporters, if empty list is passed', async () => {
await createTestScheduler(
makeGlobalConfig({
reporters: [],
}),
{},
{},
);

expect(DefaultReporter).toHaveBeenCalledTimes(0);
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(0);
expect(VerboseReporter).toHaveBeenCalledTimes(0);
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
expect(NotifyReporter).toHaveBeenCalledTimes(0);
expect(CoverageReporter).toHaveBeenCalledTimes(0);
expect(SummaryReporter).toHaveBeenCalledTimes(0);
});

test('sets up default reporters', async () => {
await createTestScheduler(
makeGlobalConfig({
reporters: [['default', {}]],
}),
{},
{},
);

expect(DefaultReporter).toHaveBeenCalledTimes(0);
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(1);
expect(VerboseReporter).toHaveBeenCalledTimes(0);
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
expect(NotifyReporter).toHaveBeenCalledTimes(0);
expect(CoverageReporter).toHaveBeenCalledTimes(0);
expect(SummaryReporter).toHaveBeenCalledTimes(1);
});

test('sets up verbose reporter', async () => {
await createTestScheduler(
makeGlobalConfig({
reporters: [['default', {}]],
verbose: true,
}),
{},
{},
);

expect(DefaultReporter).toHaveBeenCalledTimes(0);
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(0);
expect(VerboseReporter).toHaveBeenCalledTimes(1);
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
expect(NotifyReporter).toHaveBeenCalledTimes(0);
expect(CoverageReporter).toHaveBeenCalledTimes(0);
expect(SummaryReporter).toHaveBeenCalledTimes(1);
});

test('sets up github actions reporter', async () => {
await createTestScheduler(
makeGlobalConfig({
reporters: [
['default', {}],
['github-actions', {}],
],
}),
{},
{},
);

expect(DefaultReporter).toHaveBeenCalledTimes(0);
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(1);
expect(VerboseReporter).toHaveBeenCalledTimes(0);
expect(GitHubActionsReporter).toHaveBeenCalledTimes(1);
expect(NotifyReporter).toHaveBeenCalledTimes(0);
expect(CoverageReporter).toHaveBeenCalledTimes(0);
expect(SummaryReporter).toHaveBeenCalledTimes(1);
});

test('sets up notify reporter', async () => {
await createTestScheduler(
makeGlobalConfig({
notify: true,
reporters: [['default', {}]],
}),
{},
{},
);

expect(DefaultReporter).toHaveBeenCalledTimes(0);
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(1);
expect(VerboseReporter).toHaveBeenCalledTimes(0);
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
expect(NotifyReporter).toHaveBeenCalledTimes(1);
expect(CoverageReporter).toHaveBeenCalledTimes(0);
expect(SummaryReporter).toHaveBeenCalledTimes(1);
});

test('sets up coverage reporter', async () => {
await createTestScheduler(
makeGlobalConfig({
collectCoverage: true,
reporters: [['default', {}]],
}),
{},
{},
);

expect(DefaultReporter).toHaveBeenCalledTimes(0);
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(1);
expect(VerboseReporter).toHaveBeenCalledTimes(0);
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
expect(NotifyReporter).toHaveBeenCalledTimes(0);
expect(CoverageReporter).toHaveBeenCalledTimes(1);
expect(SummaryReporter).toHaveBeenCalledTimes(1);
});

test('allows enabling summary reporter separately', async () => {
await createTestScheduler(
makeGlobalConfig({
reporters: [['summary', {}]],
}),
{},
{},
);

expect(DefaultReporter).toHaveBeenCalledTimes(0);
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(0);
expect(VerboseReporter).toHaveBeenCalledTimes(0);
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
expect(NotifyReporter).toHaveBeenCalledTimes(0);
expect(CoverageReporter).toHaveBeenCalledTimes(0);
expect(SummaryReporter).toHaveBeenCalledTimes(1);
});

test('sets up custom reporter', async () => {
await createTestScheduler(
makeGlobalConfig({
reporters: [
['default', {}],
['/custom-reporter.js', {}],
],
}),
{},
{},
);

expect(DefaultReporter).toHaveBeenCalledTimes(0);
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(1);
expect(VerboseReporter).toHaveBeenCalledTimes(0);
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
expect(NotifyReporter).toHaveBeenCalledTimes(0);
expect(CoverageReporter).toHaveBeenCalledTimes(0);
expect(SummaryReporter).toHaveBeenCalledTimes(1);
expect(CustomReporter).toHaveBeenCalledTimes(1);
});
});

describe('reporters with GITHUB_ACTIONS = false', () => {
const CustomReporter = require('/custom-reporter.js');

afterEach(() => {
jest.clearAllMocks();
});

beforeAll(() => {
const ci = require('ci-info');
ci.GITHUB_ACTIONS = false;
});

afterAll(() => {
const ci = require('ci-info');
ci.GITHUB_ACTIONS = true;
});

test('works with default value', async () => {
await createTestScheduler(
makeGlobalConfig({
Expand All @@ -76,6 +267,7 @@ describe('reporters', () => {
);

expect(DefaultReporter).toHaveBeenCalledTimes(1);
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(0);
expect(VerboseReporter).toHaveBeenCalledTimes(0);
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
expect(NotifyReporter).toHaveBeenCalledTimes(0);
Expand All @@ -93,6 +285,7 @@ describe('reporters', () => {
);

expect(DefaultReporter).toHaveBeenCalledTimes(0);
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(0);
expect(VerboseReporter).toHaveBeenCalledTimes(0);
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
expect(NotifyReporter).toHaveBeenCalledTimes(0);
Expand All @@ -110,6 +303,7 @@ describe('reporters', () => {
);

expect(DefaultReporter).toHaveBeenCalledTimes(1);
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(0);
expect(VerboseReporter).toHaveBeenCalledTimes(0);
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
expect(NotifyReporter).toHaveBeenCalledTimes(0);
Expand All @@ -128,14 +322,15 @@ describe('reporters', () => {
);

expect(DefaultReporter).toHaveBeenCalledTimes(0);
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(0);
expect(VerboseReporter).toHaveBeenCalledTimes(1);
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
expect(NotifyReporter).toHaveBeenCalledTimes(0);
expect(CoverageReporter).toHaveBeenCalledTimes(0);
expect(SummaryReporter).toHaveBeenCalledTimes(1);
});

test('sets up github actions reporter', async () => {
test('does not set up github actions reporter', async () => {
await createTestScheduler(
makeGlobalConfig({
reporters: [
Expand All @@ -148,8 +343,9 @@ describe('reporters', () => {
);

expect(DefaultReporter).toHaveBeenCalledTimes(1);
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(0);
expect(VerboseReporter).toHaveBeenCalledTimes(0);
expect(GitHubActionsReporter).toHaveBeenCalledTimes(1);
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
expect(NotifyReporter).toHaveBeenCalledTimes(0);
expect(CoverageReporter).toHaveBeenCalledTimes(0);
expect(SummaryReporter).toHaveBeenCalledTimes(1);
Expand All @@ -166,6 +362,7 @@ describe('reporters', () => {
);

expect(DefaultReporter).toHaveBeenCalledTimes(1);
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(0);
expect(VerboseReporter).toHaveBeenCalledTimes(0);
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
expect(NotifyReporter).toHaveBeenCalledTimes(1);
Expand All @@ -184,6 +381,7 @@ describe('reporters', () => {
);

expect(DefaultReporter).toHaveBeenCalledTimes(1);
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(0);
expect(VerboseReporter).toHaveBeenCalledTimes(0);
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
expect(NotifyReporter).toHaveBeenCalledTimes(0);
Expand All @@ -201,6 +399,7 @@ describe('reporters', () => {
);

expect(DefaultReporter).toHaveBeenCalledTimes(0);
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(0);
expect(VerboseReporter).toHaveBeenCalledTimes(0);
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
expect(NotifyReporter).toHaveBeenCalledTimes(0);
Expand All @@ -221,6 +420,7 @@ describe('reporters', () => {
);

expect(DefaultReporter).toHaveBeenCalledTimes(1);
expect(GithubActionsLogsReporter).toHaveBeenCalledTimes(0);
expect(VerboseReporter).toHaveBeenCalledTimes(0);
expect(GitHubActionsReporter).toHaveBeenCalledTimes(0);
expect(NotifyReporter).toHaveBeenCalledTimes(0);
Expand Down

0 comments on commit 5eaf7cb

Please sign in to comment.