Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- `[@jest-environment/jsdom-abstract]` Make `@types/jsdom` a peer dependency ([#16166](https://github.com/jestjs/jest/pull/16166))
- `[jest-runtime]` Fall back to native ESM when a `.js` file contains ESM syntax but has no `"type":"module"` marker ([#16152](https://github.com/jestjs/jest/pull/16152))
- `[jest-runtime]` Support older test environments whose `moduleMocker` does not implement `clearMocksOnScope` ([#16169](https://github.com/jestjs/jest/pull/16169))
- `[jest-reporters]` Fix coverage report table formatting in CI/GitHub Actions environments where `process.stdout.columns` is undefined by falling back to the `COLUMNS` env var or `80` columns in CI, preserving existing behaviour in other non-TTY environments ([#16227](https://github.com/jestjs/jest/pull/16227))

### Chore & Maintenance

Expand Down
9 changes: 8 additions & 1 deletion packages/jest-reporters/src/CoverageReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,14 @@ export default class CoverageReporter extends BaseReporter {
}
istanbulReports
.create(reporter, {
maxCols: process.stdout.columns || Number.POSITIVE_INFINITY,
maxCols:
process.stdout.columns ||
Number.parseInt(process.env.COLUMNS || '', 10) ||
((process.env.CI === 'true' ||
process.env.GITHUB_ACTIONS === 'true') &&
!process.env.JEST_WORKER_ID
? 80
: Number.POSITIVE_INFINITY),
...additionalOptions,
})
.execute(reportContext);
Expand Down
54 changes: 53 additions & 1 deletion packages/jest-reporters/src/__tests__/CoverageReporter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,12 +454,64 @@ describe('onRunComplete', () => {
await testReporter.onRunComplete(new Set(), {}, mockAggResults);

expect(istanbulReports.create).toHaveBeenCalledWith('json', {
maxCols: process.stdout.columns || Number.POSITIVE_INFINITY,
maxCols:
process.stdout.columns ||
Number.parseInt(process.env.COLUMNS || '', 10) ||
((process.env.CI === 'true' || process.env.GITHUB_ACTIONS === 'true') &&
!process.env.JEST_WORKER_ID
? 80
: Number.POSITIVE_INFINITY),
});
expect(istanbulReports.create).toHaveBeenCalledWith('lcov', {
maxCols: 10,
projectRoot: './',
});
expect(testReporter.getLastError()).toBeUndefined();
});

describe('maxCols fallback logic in CI', () => {
const originalEnv = process.env;

beforeEach(() => {
jest.resetModules();
process.env = {...originalEnv};
delete process.env.COLUMNS;
});

afterEach(() => {
process.env = originalEnv;
});

test('falls back to 80 in CI without JEST_WORKER_ID', async () => {
process.env.CI = 'true';
delete process.env.JEST_WORKER_ID;

const testReporter = new CoverageReporter({
coverageReporters: ['json'],
});
testReporter.log = jest.fn();

await testReporter.onRunComplete(new Set(), {}, mockAggResults);

expect(istanbulReports.create).toHaveBeenCalledWith('json', {
maxCols: process.stdout.columns || 80,
});
});

test('falls back to Infinity in CI with JEST_WORKER_ID', async () => {
process.env.CI = 'true';
process.env.JEST_WORKER_ID = '1';

const testReporter = new CoverageReporter({
coverageReporters: ['json'],
});
testReporter.log = jest.fn();

await testReporter.onRunComplete(new Set(), {}, mockAggResults);

expect(istanbulReports.create).toHaveBeenCalledWith('json', {
maxCols: process.stdout.columns || Number.POSITIVE_INFINITY,
});
});
});
});
Loading