Skip to content

Commit

Permalink
Flip silent default value and fix worker shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoH2O1999 committed Jan 17, 2023
1 parent 6d57199 commit f7ea251
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docs/Configuration.md
Expand Up @@ -1278,7 +1278,7 @@ export default config;

#### GitHub Actions Reporter

If included in the list, the built-in GitHub Actions Reporter will annotate changed files with test failure messages and print logs with github group features for easy navigation. Note that `'default'` should not be used in this case as `'github-actions'` will handle that already, so remember to also include `'summary'`. If you wish to use it only for annotations simply pass `'silent: true'` as option (default is `false`):
If included in the list, the built-in GitHub Actions Reporter will annotate changed files with test failure messages and (if used with `'silent: false'`) print logs with github group features for easy navigation. Note that `'default'` should not be used in this case as `'github-actions'` will handle that already, so remember to also include `'summary'`. If you wish to use it only for annotations simply leave only the reporter without options as the default value of `'silent'` is `'true'`:

```js tab
/** @type {import('jest').Config} */
Expand Down
15 changes: 9 additions & 6 deletions packages/jest-reporters/src/GitHubActionsReporter.ts
Expand Up @@ -66,10 +66,15 @@ export default class GitHubActionsReporter extends BaseReporter {

constructor(
_globalConfig: Config.GlobalConfig,
reporterOptions: {silent?: boolean} = {silent: false},
reporterOptions: {silent?: boolean} = {silent: true},
) {
super();
this.options = {silent: reporterOptions.silent || false};
this.options = {
silent:
typeof reporterOptions.silent === 'boolean'
? reporterOptions.silent
: true,
};
}

override onTestResult(
Expand Down Expand Up @@ -215,12 +220,10 @@ export default class GitHubActionsReporter extends BaseReporter {
root.passed = false;
passed = false;
}
if (!element.duration || isNaN(element.duration)) {
throw new Error('Expected duration to be a number, got NaN');
}
const duration = element.duration || 1;
root.children.push({
children: [],
duration: Math.max(element.duration, 1),
duration,
name: element.title,
passed,
});
Expand Down
40 changes: 30 additions & 10 deletions packages/jest-reporters/src/__tests__/GitHubActionsReporter.test.ts
Expand Up @@ -186,7 +186,9 @@ describe('logs', () => {
start: 10,
},
};
const gha = new GitHubActionsReporter({} as Config.GlobalConfig);
const gha = new GitHubActionsReporter({} as Config.GlobalConfig, {
silent: false,
});

const generated = gha['getResultTree'](testResults, '/', suitePerf);

Expand Down Expand Up @@ -227,7 +229,9 @@ describe('logs', () => {
start: 10,
},
};
const gha = new GitHubActionsReporter({} as Config.GlobalConfig);
const gha = new GitHubActionsReporter({} as Config.GlobalConfig, {
silent: false,
});

const generated = gha['getResultTree'](testResults, '/', suitePerf);

Expand Down Expand Up @@ -274,7 +278,9 @@ describe('logs', () => {
start: 10,
},
};
const gha = new GitHubActionsReporter({} as Config.GlobalConfig);
const gha = new GitHubActionsReporter({} as Config.GlobalConfig, {
silent: false,
});

const generated = gha['getResultTree'](testResults, '/', suitePerf);

Expand Down Expand Up @@ -321,7 +327,9 @@ describe('logs', () => {
start: 10,
},
};
const gha = new GitHubActionsReporter({} as Config.GlobalConfig);
const gha = new GitHubActionsReporter({} as Config.GlobalConfig, {
silent: false,
});

const generated = gha['getResultTree'](testResults, '/', suitePerf);

Expand Down Expand Up @@ -350,7 +358,9 @@ describe('logs', () => {
start: 10,
},
};
const gha = new GitHubActionsReporter({} as Config.GlobalConfig);
const gha = new GitHubActionsReporter({} as Config.GlobalConfig, {
silent: false,
});

gha['printResultTree'](generatedTree);

Expand All @@ -376,7 +386,9 @@ describe('logs', () => {
start: 10,
},
};
const gha = new GitHubActionsReporter({} as Config.GlobalConfig);
const gha = new GitHubActionsReporter({} as Config.GlobalConfig, {
silent: false,
});

gha['printResultTree'](generatedTree);

Expand Down Expand Up @@ -408,7 +420,9 @@ describe('logs', () => {
start: 10,
},
};
const gha = new GitHubActionsReporter({} as Config.GlobalConfig);
const gha = new GitHubActionsReporter({} as Config.GlobalConfig, {
silent: false,
});

gha['printResultTree'](generatedTree);

Expand Down Expand Up @@ -440,7 +454,9 @@ describe('logs', () => {
start: 10,
},
};
const gha = new GitHubActionsReporter({} as Config.GlobalConfig);
const gha = new GitHubActionsReporter({} as Config.GlobalConfig, {
silent: false,
});

gha['printResultTree'](generatedTree);

Expand Down Expand Up @@ -477,7 +493,9 @@ describe('logs', () => {
numPassedTestSuites: 1,
numTotalTestSuites: 3,
};
const gha = new GitHubActionsReporter({} as Config.GlobalConfig);
const gha = new GitHubActionsReporter({} as Config.GlobalConfig, {
silent: false,
});
gha['generateAnnotations'] = jest.fn();

gha.onTestResult(
Expand Down Expand Up @@ -519,7 +537,9 @@ describe('logs', () => {
numTotalTestSuites: 3,
testResults: [mockTestResult],
};
const gha = new GitHubActionsReporter({} as Config.GlobalConfig);
const gha = new GitHubActionsReporter({} as Config.GlobalConfig, {
silent: false,
});
gha['generateAnnotations'] = jest.fn();

gha.onTestResult(
Expand Down

0 comments on commit f7ea251

Please sign in to comment.