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

Rename HasteContext to Context. #3171

Merged
merged 1 commit into from
Mar 17, 2017
Merged
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
14 changes: 7 additions & 7 deletions packages/jest-cli/src/SearchSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'use strict';

import type {Config} from 'types/Config';
import type {HasteContext} from 'types/HasteMap';
import type {Context} from 'types/Context';
import type {Glob, Path} from 'types/Config';
import type {ResolveModuleConfig} from 'types/Resolve';

Expand Down Expand Up @@ -86,7 +86,7 @@ const regexToMatcher = (testRegex: string) => {
};

class SearchSource {
_hasteContext: HasteContext;
_context: Context;
_config: SearchSourceConfig;
_options: ResolveModuleConfig;
_rootPattern: RegExp;
Expand All @@ -99,11 +99,11 @@ class SearchSource {
};

constructor(
hasteMap: HasteContext,
context: Context,
config: SearchSourceConfig,
options?: ResolveModuleConfig,
) {
this._hasteContext = hasteMap;
this._context = context;
this._config = config;
this._options = options || {
skipNodeResolution: false,
Expand Down Expand Up @@ -164,7 +164,7 @@ class SearchSource {

_getAllTestPaths(testPathPattern: StrOrRegExpPattern): SearchResult {
return this._filterTestPathsWithStats(
this._hasteContext.hasteFS.getAllFiles(),
this._context.hasteFS.getAllFiles(),
testPathPattern,
);
}
Expand All @@ -180,8 +180,8 @@ class SearchSource {

findRelatedTests(allPaths: Set<Path>): SearchResult {
const dependencyResolver = new DependencyResolver(
this._hasteContext.resolver,
this._hasteContext.hasteFS,
this._context.resolver,
this._context.hasteFS,
);
return {
paths: dependencyResolver.resolveInverse(
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-cli/src/TestPathPatternPrompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

'use strict';

import type {HasteContext} from 'types/HasteMap';
import type {Context} from 'types/Context';
import type {Config, Path} from 'types/Config';

const ansiEscapes = require('ansi-escapes');
Expand Down Expand Up @@ -116,8 +116,8 @@ module.exports = (
pipe.write(ansiEscapes.cursorRestorePosition);
}

updateSearchSource(hasteContext: HasteContext) {
this.searchSource = new SearchSource(hasteContext, config);
updateSearchSource(context: Context) {
this.searchSource = new SearchSource(context, config);
}
}

Expand Down
60 changes: 32 additions & 28 deletions packages/jest-cli/src/TestRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import type {
TestResult,
} from 'types/TestResult';
import type {Config} from 'types/Config';
import type {HasteContext, HasteFS} from 'types/HasteMap';
import type {Context} from 'types/Context';
import type {HasteFS} from 'types/HasteMap';
import type {RunnerContext} from 'types/Reporters';
import type {Test, Tests} from 'types/TestRunner';
import type BaseReporter from './reporters/BaseReporter';
Expand Down Expand Up @@ -53,14 +54,14 @@ type OnTestSuccess = (test: Test, result: TestResult) => void;
const TEST_WORKER_PATH = require.resolve('./TestWorker');

class TestRunner {
_hasteContext: HasteContext;
_context: Context;
_config: Config;
_options: Options;
_startRun: () => *;
_dispatcher: ReporterDispatcher;

constructor(
hasteContext: HasteContext,
hasteContext: Context,
config: Config,
options: Options,
startRun: () => *,
Expand All @@ -70,7 +71,7 @@ class TestRunner {
hasteContext.hasteFS,
options.getTestSummary,
);
this._hasteContext = hasteContext;
this._context = hasteContext;
this._options = options;
this._startRun = startRun;
this._setupReporters();
Expand Down Expand Up @@ -140,7 +141,7 @@ class TestRunner {

const updateSnapshotState = () => {
const status = snapshot.cleanup(
this._hasteContext.hasteFS,
this._context.hasteFS,
config.updateSnapshot,
);
aggregatedResults.snapshot.filesRemoved += status.filesRemoved;
Expand Down Expand Up @@ -190,17 +191,19 @@ class TestRunner {
) {
const mutex = throat(1);
return tests.reduce(
(promise, test) => mutex(() => promise
.then(() => {
if (watcher.isInterrupted()) {
throw new CancelRun();
}

this._dispatcher.onTestStart(test.config, test.path);
return runTest(test.path, test.config, this._hasteContext.resolver);
})
.then(result => onResult(test, result))
.catch(err => onFailure(test, err))),
(promise, test) =>
mutex(() =>
promise
.then(() => {
if (watcher.isInterrupted()) {
throw new CancelRun();
}

this._dispatcher.onTestStart(test.config, test.path);
return runTest(test.path, test.config, this._context.resolver);
})
.then(result => onResult(test, result))
.catch(err => onFailure(test, err))),
Promise.resolve(),
);
}
Expand All @@ -225,19 +228,20 @@ class TestRunner {

// Send test suites to workers continuously instead of all at once to track
// the start time of individual tests.
const runTestInWorker = ({config, path}) => mutex(() => {
if (watcher.isInterrupted()) {
return Promise.reject();
}
this._dispatcher.onTestStart(config, path);
return worker({
config,
path,
rawModuleMap: watcher.isWatchMode()
? this._hasteContext.moduleMap.getRawModuleMap()
: null,
const runTestInWorker = ({config, path}) =>
mutex(() => {
if (watcher.isInterrupted()) {
return Promise.reject();
}
this._dispatcher.onTestStart(config, path);
return worker({
config,
path,
rawModuleMap: watcher.isWatchMode()
? this._context.moduleMap.getRawModuleMap()
: null,
});
});
});

const onError = (err, test) => {
onFailure(test, err);
Expand Down
10 changes: 5 additions & 5 deletions packages/jest-cli/src/__tests__/SearchSource-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('SearchSource', () => {
rootDir: '.',
roots: [],
}).config;
return Runtime.createHasteContext(config, {maxWorkers}).then(hasteMap => {
return Runtime.createContext(config, {maxWorkers}).then(hasteMap => {
searchSource = new SearchSource(hasteMap, config);
});
});
Expand All @@ -62,7 +62,7 @@ describe('SearchSource', () => {
testMatch: null,
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.jsx?$',
}).config;
return Runtime.createHasteContext(config, {
return Runtime.createContext(config, {
maxWorkers,
}).then(hasteMap => {
searchSource = new SearchSource(hasteMap, config);
Expand Down Expand Up @@ -93,7 +93,7 @@ describe('SearchSource', () => {
describe('testPathsMatching', () => {
beforeEach(() => {
findMatchingTests = config =>
Runtime.createHasteContext(config, {
Runtime.createContext(config, {
maxWorkers,
}).then(hasteMap =>
new SearchSource(hasteMap, config).findMatchingTests());
Expand Down Expand Up @@ -309,7 +309,7 @@ describe('SearchSource', () => {
name: 'SearchSource-findRelatedTests-tests',
rootDir,
});
Runtime.createHasteContext(config, {maxWorkers}).then(hasteMap => {
Runtime.createContext(config, {maxWorkers}).then(hasteMap => {
searchSource = new SearchSource(hasteMap, config);
done();
});
Expand Down Expand Up @@ -342,7 +342,7 @@ describe('SearchSource', () => {
rootDir,
testMatch,
});
Runtime.createHasteContext(config, {maxWorkers}).then(hasteMap => {
Runtime.createContext(config, {maxWorkers}).then(hasteMap => {
searchSource = new SearchSource(hasteMap, config);
done();
});
Expand Down
8 changes: 4 additions & 4 deletions packages/jest-cli/src/cli/runCLI.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const Runtime = require('jest-runtime');
const chalk = require('chalk');
const {Console, clearLine} = require('jest-util');
const {createDirectory} = require('jest-util');
const createHasteContext = require('../lib/createHasteContext');
const createContext = require('../lib/createContext');
const getMaxWorkers = require('../lib/getMaxWorkers');
const logDebugMessages = require('../lib/logDebugMessages');
const preRunMessage = require('../preRunMessage');
Expand Down Expand Up @@ -59,22 +59,22 @@ module.exports = (
});

const hasteMap = await hasteMapInstance.build();
const hasteContext = createHasteContext(config, hasteMap);
const context = createContext(config, hasteMap);
if (argv.watch || argv.watchAll) {
return watch(
config,
pipe,
argv,
hasteMapInstance,
hasteContext,
context,
hasDeprecationWarnings,
);
} else {
const startRun = () => {
preRunMessage.print(pipe);
const testWatcher = new TestWatcher({isWatchMode: false});
return runJest(
hasteContext,
context,
config,
argv,
pipe,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@
'use strict';

import type {Config} from 'types/Config';
import type {HasteMap, HasteContext} from 'types/HasteMap';
import type {Context} from 'types/Context';
import type {HasteMap} from 'types/HasteMap';

const Runtime = require('jest-runtime');

const createHasteContext = (
config: Config,
{hasteFS, moduleMap}: HasteMap,
): HasteContext => ({
module.exports = (config: Config, {hasteFS, moduleMap}: HasteMap): Context => ({
config,
hasteFS,
moduleMap,
resolver: Runtime.createResolver(config, moduleMap),
});

module.exports = createHasteContext;
23 changes: 12 additions & 11 deletions packages/jest-cli/src/runJest.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'use strict';

import type {Config} from 'types/Config';
import type {HasteContext} from 'types/HasteMap';
import type {Context} from 'types/Context';
import type {PatternInfo} from './SearchSource';

const fs = require('graceful-fs');
Expand Down Expand Up @@ -43,7 +43,7 @@ const getTestSummary = (argv: Object, patternInfo: PatternInfo) => {
};

const runJest = async (
hasteContext: HasteContext,
hasteContext: Context,
config: Config,
argv: Object,
pipe: stream$Writable | tty$WriteStream,
Expand Down Expand Up @@ -94,15 +94,16 @@ const runJest = async (
return data;
};

const runTests = async tests => new TestRunner(
hasteContext,
config,
{
getTestSummary: () => getTestSummary(argv, patternInfo),
maxWorkers,
},
startRun,
).runTests(tests, testWatcher);
const runTests = async tests =>
new TestRunner(
hasteContext,
config,
{
getTestSummary: () => getTestSummary(argv, patternInfo),
maxWorkers,
},
startRun,
).runTests(tests, testWatcher);

const processResults = runResults => {
if (config.testResultsProcessor) {
Expand Down
8 changes: 4 additions & 4 deletions packages/jest-cli/src/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
*/
'use strict';

import type {HasteContext} from 'types/HasteMap';
import type {Context} from 'types/Context';
import type {Config} from 'types/Config';

const ansiEscapes = require('ansi-escapes');
const chalk = require('chalk');
const createHasteContext = require('./lib/createHasteContext');
const createTestContext = require('./lib/createContext');
const HasteMap = require('jest-haste-map');
const isValidPath = require('./lib/isValidPath');
const preRunMessage = require('./preRunMessage');
Expand All @@ -31,7 +31,7 @@ const watch = (
pipe: stream$Writable | tty$WriteStream,
argv: Object,
hasteMap: HasteMap,
hasteContext: HasteContext,
hasteContext: Context,
hasDeprecationWarnings?: boolean,
stdin?: stream$Readable | tty$ReadStream = process.stdin,
) => {
Expand Down Expand Up @@ -66,7 +66,7 @@ const watch = (
});

if (validPaths.length) {
hasteContext = createHasteContext(config, {hasteFS, moduleMap});
hasteContext = createTestContext(config, {hasteFS, moduleMap});
prompt.abort();
testPathPatternPrompt.updateSearchSource(hasteContext);
startRun();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ beforeEach(() => {
rootDir: '.',
roots: ['./packages/jest-resolve-dependencies'],
}).config;
return Runtime.createHasteContext(config, {maxWorkers}).then(hasteMap => {
return Runtime.createContext(config, {maxWorkers}).then(hasteMap => {
dependencyResolver = new DependencyResolver(
hasteMap.resolver,
hasteMap.hasteFS,
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-runtime/src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function run(cliArgv?: Object, cliInfo?: Array<string>) {
automock: false,
unmockedModulePathPatterns: null,
});
Runtime.createHasteContext(config, {
Runtime.createContext(config, {
maxWorkers: os.cpus().length - 1,
})
.then(hasteMap => {
Expand Down
Loading