Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: serialize changedFiles passed to workers #8090

Merged
merged 5 commits into from Mar 8, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@

- `[expect]` Compare DOM nodes even if there are multiple Node classes ([#8064](https://github.com/facebook/jest/pull/8064))
- `[jest-worker]` `worker.getStdout()` can return `null` ([#8083](https://github.com/facebook/jest/pull/8083))
- `[jest-reporters/jest-runner]` Serialize `changedFiles` passed to workers ([#8090](https://github.com/facebook/jest/pull/8090))

### Chore & Maintenance

Expand Down
7 changes: 6 additions & 1 deletion packages/jest-reporters/src/coverage_reporter.ts
Expand Up @@ -170,7 +170,12 @@ export default class CoverageReporter extends BaseReporter {
const result = await worker.worker({
config,
globalConfig,
options: this._options,
options: {
...this._options,
changedFiles:
this._options.changedFiles &&
Array.from(this._options.changedFiles),
},
path: filename,
});

Expand Down
6 changes: 3 additions & 3 deletions packages/jest-reporters/src/coverage_worker.ts
Expand Up @@ -8,7 +8,7 @@
import fs from 'fs';
import {Config} from '@jest/types';
import exit from 'exit';
import {CoverageReporterOptions} from './types';
import {CoverageReporterSerializedOptions} from './types';

import generateEmptyCoverage, {
CoverageWorkerResult,
Expand All @@ -18,7 +18,7 @@ export type CoverageWorkerData = {
globalConfig: Config.GlobalConfig;
config: Config.ProjectConfig;
path: Config.Path;
options?: CoverageReporterOptions;
options?: CoverageReporterSerializedOptions;
};

export {CoverageWorkerResult};
Expand All @@ -40,6 +40,6 @@ export function worker({
path,
globalConfig,
config,
options && options.changedFiles,
options && options.changedFiles && new Set(options.changedFiles),
);
}
4 changes: 4 additions & 0 deletions packages/jest-reporters/src/types.ts
Expand Up @@ -41,6 +41,10 @@ export type CoverageReporterOptions = {
changedFiles?: Set<Config.Path>;
};

export type CoverageReporterSerializedOptions = {
changedFiles?: Array<Config.Path>;
};

export type OnTestStart = (test: Test) => Promise<void>;
export type OnTestFailure = (
test: Test,
Expand Down
7 changes: 6 additions & 1 deletion packages/jest-runner/src/index.ts
Expand Up @@ -127,7 +127,12 @@ class TestRunner {

return worker.worker({
config: test.context.config,
context: this._context,
context: {
...this._context,
changedFiles:
this._context.changedFiles &&
Array.from(this._context.changedFiles),
},
globalConfig: this._globalConfig,
path: test.path,
serializableModuleMap: watcher.isWatchMode()
Expand Down
9 changes: 6 additions & 3 deletions packages/jest-runner/src/testWorker.ts
Expand Up @@ -12,15 +12,15 @@ import HasteMap, {SerializableModuleMap, ModuleMap} from 'jest-haste-map';
import exit from 'exit';
import {separateMessageFromStack} from 'jest-message-util';
import Runtime from 'jest-runtime';
import {ErrorWithCode, TestRunnerContext} from './types';
import {ErrorWithCode, TestRunnerSerializedContext} from './types';
import runTest from './runTest';

type WorkerData = {
config: Config.ProjectConfig;
globalConfig: Config.GlobalConfig;
path: Config.Path;
serializableModuleMap: SerializableModuleMap | null;
context?: TestRunnerContext;
context?: TestRunnerSerializedContext;
};

// Make sure uncaught errors are logged before we exit.
Expand Down Expand Up @@ -86,7 +86,10 @@ export async function worker({
globalConfig,
config,
getResolver(config, moduleMap),
context,
context && {
...context,
changedFiles: context.changedFiles && new Set(context.changedFiles),
},
);
} catch (error) {
throw formatError(error);
Expand Down
4 changes: 4 additions & 0 deletions packages/jest-runner/src/types.ts
Expand Up @@ -53,6 +53,10 @@ export type TestRunnerContext = {
changedFiles?: Set<Config.Path>;
};

export type TestRunnerSerializedContext = {
changedFiles?: Array<Config.Path>;
};

// TODO: Should live in `@jest/core` or `jest-watcher`
export type WatcherState = {
interrupted: boolean;
Expand Down