Skip to content

Commit

Permalink
Update type CamelCase and fix silent option
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoH2O1999 committed Jan 10, 2023
1 parent c964cb6 commit b0527e1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
5 changes: 4 additions & 1 deletion packages/jest-core/src/TestScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,10 @@ class TestScheduler {
: this.addReporter(new DefaultReporter(this._globalConfig));
break;
case 'github-actions':
GITHUB_ACTIONS && this.addReporter(new GitHubActionsReporter());
GITHUB_ACTIONS &&
this.addReporter(
new GitHubActionsReporter(this._globalConfig, options),
);
break;
case 'summary':
summary = true;
Expand Down
42 changes: 18 additions & 24 deletions packages/jest-reporters/src/GitHubActionsReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,31 @@ type AnnotationOptions = {

const titleSeparator = ' \u203A ';

type performaceInfo = {
type PerformanceInfo = {
end: number;
runtime: number;
slow: boolean;
start: number;
};

type resultTreeLeaf = {
type ResultTreeLeaf = {
name: string;
passed: boolean;
duration: number;
children: Array<never>;
};

type resultTreeNode = {
type ResultTreeNode = {
name: string;
passed: boolean;
children: Array<resultTreeNode | resultTreeLeaf>;
children: Array<ResultTreeNode | ResultTreeLeaf>;
};

type resultTree = {
children: Array<resultTreeLeaf | resultTreeNode>;
type ResultTree = {
children: Array<ResultTreeLeaf | ResultTreeNode>;
name: string;
passed: boolean;
performanceInfo: performaceInfo;
performanceInfo: PerformanceInfo;
};

export default class GitHubActionsReporter extends BaseReporter {
Expand All @@ -66,17 +66,10 @@ export default class GitHubActionsReporter extends BaseReporter {

constructor(
_globalConfig: Config.GlobalConfig,
reporterOptions: Config.ReporterConfig,
reporterOptions: Record<string, unknown> = {silent: false},
) {
super();
if (reporterOptions === null || reporterOptions === undefined) {
reporterOptions = ['github-actions', {silent: false}];
}
let options = reporterOptions[1];
if (options === null || options === undefined) {
options = {silent: false};
}
const silentOption = options.silent;
const silentOption = reporterOptions.silent;
if (silentOption !== null && silentOption !== undefined) {
this.silent = silentOption as boolean;
} else {
Expand All @@ -89,6 +82,7 @@ export default class GitHubActionsReporter extends BaseReporter {
testResult: TestResult,
aggregatedResults: AggregatedResult,
): void {
this.generateAnnotations(test, testResult);
if (this.silent) {
return;
}
Expand All @@ -101,7 +95,7 @@ export default class GitHubActionsReporter extends BaseReporter {
}
}

onTestFileResult({context}: Test, {testResults}: TestResult): void {
generateAnnotations({context}: Test, {testResults}: TestResult): void {
testResults.forEach(result => {
const title = [...result.ancestorTitles, result.title].join(
titleSeparator,
Expand Down Expand Up @@ -211,9 +205,9 @@ export default class GitHubActionsReporter extends BaseReporter {
private getResultTree(
suiteResult: Array<AssertionResult>,
testPath: string,
suitePerf: performaceInfo,
): resultTree {
const root: resultTree = {
suitePerf: PerformanceInfo,
): ResultTree {
const root: ResultTree = {
children: [],
name: testPath,
passed: true,
Expand Down Expand Up @@ -264,8 +258,8 @@ export default class GitHubActionsReporter extends BaseReporter {
private getResultChildren(
suiteResult: Array<AssertionResult>,
ancestors: Array<string>,
): resultTreeNode {
const node: resultTreeNode = {
): ResultTreeNode {
const node: ResultTreeNode = {
children: [],
name: ancestors[ancestors.length - 1],
passed: true,
Expand Down Expand Up @@ -321,7 +315,7 @@ export default class GitHubActionsReporter extends BaseReporter {
return node;
}

private printResultTree(resultTree: resultTree): void {
private printResultTree(resultTree: ResultTree): void {
let perfMs;
if (resultTree.performanceInfo.slow) {
perfMs = ` (${chalk.red.inverse(
Expand Down Expand Up @@ -349,7 +343,7 @@ export default class GitHubActionsReporter extends BaseReporter {
}

private recursivePrintResultTree(
resultTree: resultTreeNode | resultTreeLeaf,
resultTree: ResultTreeNode | ResultTreeLeaf,
alreadyGrouped: boolean,
depth: number,
): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import type {Test, TestCaseResult, TestResult} from '@jest/test-result';
import type {Config} from '@jest/types';
import GitHubActionsReporter from '../GitHubActionsReporter';

const mockedStderrWrite = jest
Expand All @@ -16,7 +17,7 @@ afterEach(() => {
jest.clearAllMocks();
});

const reporter = new GitHubActionsReporter();
const reporter = new GitHubActionsReporter({} as Config.GlobalConfig);

const testMeta = {
context: {config: {rootDir: '/user/project'}},
Expand Down Expand Up @@ -74,7 +75,7 @@ const testCaseResult = {

describe('logs error annotation', () => {
test('when an expectation fails to pass', () => {
reporter.onTestFileResult(testMeta, {
reporter.generateAnnotations(testMeta, {
testResults: [
{
...testCaseResult,
Expand All @@ -88,7 +89,7 @@ describe('logs error annotation', () => {
});

test('when a test has reference error', () => {
reporter.onTestFileResult(
reporter.generateAnnotations(
{...testMeta, path: '/user/project/__tests__/example.test.js:25:12'},
{
testResults: [
Expand All @@ -105,7 +106,7 @@ describe('logs error annotation', () => {
});

test('when test is wrapped in describe block', () => {
reporter.onTestFileResult(testMeta, {
reporter.generateAnnotations(testMeta, {
testResults: [
{
...testCaseResult,
Expand All @@ -121,7 +122,7 @@ describe('logs error annotation', () => {

describe('logs warning annotation before logging errors', () => {
test('when test result includes retry reasons', () => {
reporter.onTestFileResult(testMeta, {
reporter.generateAnnotations(testMeta, {
testResults: [
{
...testCaseResult,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ describe('Reporter interface', () => {
` ${chalk.green(ySymbol)} test1 (10 ms)` +
'::endgroup::';
const gha = new GhaReporter();
gha.generateAnnotations = jest.fn();

gha.onTestResult(mockTest, mockTestResult, mockResults);

Expand Down Expand Up @@ -406,6 +407,7 @@ describe('Reporter interface', () => {
'Failure message' +
'::endgroup::';
const gha = new GhaReporter();
gha.generateAnnotations = jest.fn();

gha.onTestResult(mockTest, mockTestResult, mockResults);

Expand Down

0 comments on commit b0527e1

Please sign in to comment.