Skip to content

Commit

Permalink
Update with new spec
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoH2O1999 committed Jan 10, 2023
1 parent 3939431 commit 92f6a29
Show file tree
Hide file tree
Showing 6 changed files with 327 additions and 578 deletions.
13 changes: 3 additions & 10 deletions packages/jest-core/src/TestScheduler.ts
Expand Up @@ -12,7 +12,6 @@ import {
CoverageReporter,
DefaultReporter,
GitHubActionsReporter,
GithubActionsLogsReporter,
BaseReporter as JestReporter,
NotifyReporter,
Reporter,
Expand Down Expand Up @@ -343,15 +342,9 @@ class TestScheduler {
switch (reporter) {
case 'default':
summary = true;
if (verbose) {
this.addReporter(new VerboseReporter(this._globalConfig));
} else {
GITHUB_ACTIONS
? this.addReporter(
new GithubActionsLogsReporter(this._globalConfig),
)
: this.addReporter(new DefaultReporter(this._globalConfig));
}
verbose
? this.addReporter(new VerboseReporter(this._globalConfig))
: this.addReporter(new DefaultReporter(this._globalConfig));
break;
case 'github-actions':
GITHUB_ACTIONS && this.addReporter(new GitHubActionsReporter());
Expand Down
206 changes: 3 additions & 203 deletions packages/jest-core/src/__tests__/TestScheduler.test.js
Expand Up @@ -10,7 +10,6 @@ import {
CoverageReporter,
DefaultReporter,
GitHubActionsReporter,
GithubActionsLogsReporter,
NotifyReporter,
SummaryReporter,
VerboseReporter,
Expand Down Expand Up @@ -60,203 +59,13 @@ beforeEach(() => {
spyShouldRunInBand.mockClear();
});

describe('reporters with GITHUB_ACTIONS = true', () => {
describe('reporters', () => {
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 @@ -267,7 +76,6 @@ describe('reporters with GITHUB_ACTIONS = false', () => {
);

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

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

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

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('does not set up github actions reporter', async () => {
test('sets up github actions reporter', async () => {
await createTestScheduler(
makeGlobalConfig({
reporters: [
Expand All @@ -343,9 +148,8 @@ describe('reporters with GITHUB_ACTIONS = false', () => {
);

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

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

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

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

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 92f6a29

Please sign in to comment.