Skip to content

Commit

Permalink
feat(jest-test-sequencer): exposes contexts from runJest
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Tyrrell22 committed Sep 16, 2023
1 parent 5372e85 commit ab2d755
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/jest-core/src/runJest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export default async function runJest({
const Sequencer: typeof TestSequencer = await requireOrImportModule(
globalConfig.testSequencer,
);
const sequencer = new Sequencer(globalConfig);
const sequencer = new Sequencer({contexts, globalConfig});
let allTests: Array<Test> = [];

if (changedFilesPromise && globalConfig.watch) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as path from 'path';
import * as mockedFs from 'graceful-fs';
import type {AggregatedResult, Test, TestContext} from '@jest/test-result';
import {makeProjectConfig} from '@jest/test-utils';
import type {Config} from '@jest/types';
import TestSequencer from '../index';

jest.mock('graceful-fs', () => ({
Expand Down Expand Up @@ -56,7 +57,10 @@ const toTests = (paths: Array<string>) =>

beforeEach(() => {
jest.clearAllMocks();
sequencer = new TestSequencer();
sequencer = new TestSequencer({
contexts: [],
globalConfig: {} as Config.GlobalConfig,
});
});

test('sorts by file size if there is no timing information', () => {
Expand Down
13 changes: 12 additions & 1 deletion packages/jest-test-sequencer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ import HasteMap from 'jest-haste-map';
const FAIL = 0;
const SUCCESS = 1;

export type TestSequencerOptions = {
contexts: Array<TestContext>;
globalConfig: Config.GlobalConfig;
};

type Cache = {
[key: string]:
| [testStatus: typeof FAIL | typeof SUCCESS, testDuration: number]
Expand Down Expand Up @@ -47,7 +52,13 @@ type ShardPositionOptions = ShardOptions & {
export default class TestSequencer {
private readonly _cache = new Map<TestContext, Cache>();

constructor(protected readonly globalConfig: Config.GlobalConfig) {}
protected readonly globalConfig: Config.GlobalConfig;
protected readonly contexts: Array<TestContext>;

constructor({contexts, globalConfig}: TestSequencerOptions) {
this.globalConfig = globalConfig;
this.contexts = contexts;
}

_getCachePath(testContext: TestContext): string {
const {config} = testContext;
Expand Down

0 comments on commit ab2d755

Please sign in to comment.