Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into map-coverage
Browse files Browse the repository at this point in the history
# Conflicts:
#	packages/jest-cli/package.json
  • Loading branch information
jwbay committed Feb 24, 2017
2 parents 998c640 + f67fc6d commit 6a3ac5d
Show file tree
Hide file tree
Showing 94 changed files with 283 additions and 371 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@

'use strict';

import type {ParserReturn} from '../../ScriptParser';
const fixtures = __dirname;

const path = require('path');
const fixtures = path.resolve(__dirname, '../fixtures');

function parserTests(parse: (file: string) => ParserReturn) {
function parserTests(parse: (file: string) => any) {
describe('File parsing without throwing', () => {
it('Should not throw', () => {
expect(() => {
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"lerna": "2.0.0-beta.37",
"version": "19.0.1",
"version": "19.0.2",
"linkedFiles": {
"prefix": "/**\n * @flow\n */\n"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/babel-jest/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ const createTransformer = (options: any) => {
configString: string,
{instrument, watch}: TransformOptions,
): string {
return crypto.createHash('md5')
return crypto
.createHash('md5')
.update(THIS_FILE)
.update('\0', 'utf8')
.update(fileData)
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-changed-files/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jest-changed-files",
"version": "19.0.0",
"version": "19.0.2",
"repository": {
"type": "git",
"url": "https://github.com/facebook/jest.git"
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-changed-files/src/__tests__/git-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const os = require('os');
const fs = require('fs');
const path = require('path');
const rimraf = require('rimraf');
const mkdirp = require('mkdirp');
const childProcess = require('child_process');

const tmpdir = path.resolve(os.tmpdir(), 'jest-changed-files-git');
Expand All @@ -26,7 +27,7 @@ describe('git', () => {

beforeEach(() => {
git = require('../git');
childProcess.spawnSync('mkdir', ['-p', tmpdirNested]);
mkdirp.sync(tmpdirNested);
});

afterEach(() => rimraf.sync(tmpdir));
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-changed-files/src/__tests__/hg-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const os = require('os');
const fs = require('fs');
const path = require('path');
const rimraf = require('rimraf');
const mkdirp = require('mkdirp');
const childProcess = require('child_process');

const tmpdir = path.resolve(os.tmpdir(), 'jest-changed-files-hg');
Expand All @@ -28,7 +29,7 @@ describe('hg', () => {
jest.resetModules();

hg = require('../hg');
childProcess.spawnSync('mkdir', ['-p', tmpdirNested]);
mkdirp.sync(tmpdirNested);
});

afterEach(() => rimraf.sync(tmpdir));
Expand Down
14 changes: 8 additions & 6 deletions packages/jest-changed-files/src/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ function findChangedFiles(
options?: Options,
): Promise<Array<Path>> {
return new Promise((resolve, reject) => {
const args = (options && options.lastCommit)
? ['show', '--name-only', '--pretty=%b', 'HEAD']
: ['ls-files', '--other', '--modified', '--exclude-standard'];
const args = options && options.lastCommit
? ['show', '--name-only', '--pretty=%b', 'HEAD']
: ['ls-files', '--other', '--modified', '--exclude-standard'];
const child = childProcess.spawn('git', args, {cwd});
let stdout = '';
let stderr = '';
Expand All @@ -40,9 +40,11 @@ function findChangedFiles(
if (stdout === '') {
resolve([]);
} else {
resolve(stdout.split('\n').map(
changedPath => path.resolve(cwd, changedPath),
));
resolve(
stdout
.split('\n')
.map(changedPath => path.resolve(cwd, changedPath)),
);
}
} else {
reject(code + ': ' + stderr);
Expand Down
8 changes: 5 additions & 3 deletions packages/jest-changed-files/src/hg.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ function findChangedFiles(cwd: string, options: Options): Promise<Array<Path>> {
if (stdout === '') {
resolve([]);
} else {
resolve(stdout.split('\n').map(
changedPath => path.resolve(cwd, changedPath),
));
resolve(
stdout
.split('\n')
.map(changedPath => path.resolve(cwd, changedPath)),
);
}
} else {
reject(code + ': ' + stderr);
Expand Down
16 changes: 8 additions & 8 deletions packages/jest-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jest-cli",
"description": "Painless JavaScript Testing.",
"version": "19.0.1",
"version": "19.0.2",
"main": "build/jest.js",
"dependencies": {
"ansi-escapes": "^1.4.0",
Expand All @@ -13,17 +13,17 @@
"istanbul-lib-coverage": "^1.0.0",
"istanbul-lib-instrument": "^1.1.1",
"istanbul-lib-source-maps": "^1.1.0",
"jest-changed-files": "^19.0.0",
"jest-config": "^19.0.1",
"jest-environment-jsdom": "^19.0.1",
"jest-changed-files": "^19.0.2",
"jest-config": "^19.0.2",
"jest-environment-jsdom": "^19.0.2",
"jest-haste-map": "^19.0.0",
"jest-jasmine2": "^19.0.1",
"jest-jasmine2": "^19.0.2",
"jest-message-util": "^19.0.0",
"jest-regex-util": "^19.0.0",
"jest-resolve-dependencies": "^19.0.0",
"jest-runtime": "^19.0.1",
"jest-snapshot": "^19.0.1",
"jest-util": "^19.0.1",
"jest-runtime": "^19.0.2",
"jest-snapshot": "^19.0.2",
"jest-util": "^19.0.2",
"node-notifier": "^5.0.1",
"micromatch": "^2.3.11",
"slash": "^1.0.0",
Expand Down
22 changes: 5 additions & 17 deletions packages/jest-cli/src/TestNamePatternPrompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,25 @@ module.exports = (
_cachedTestResults;

constructor() {
(this:any).onChange = this.onChange.bind(this);
(this: any).onChange = this.onChange.bind(this);
}

run(
onSuccess: Function,
onCancel: Function,
) {
run(onSuccess: Function, onCancel: Function) {
pipe.write(ansiEscapes.cursorHide);
pipe.write(ansiEscapes.clearScreen);
pipe.write(usage());
pipe.write(ansiEscapes.cursorShow);

prompt.enter(
this.onChange,
onSuccess,
onCancel,
);
prompt.enter(this.onChange, onSuccess, onCancel);
}

onChange(
pattern: string,
) {
onChange(pattern: string) {
pipe.write(ansiEscapes.eraseLine);
pipe.write(ansiEscapes.cursorLeft);
this.printTypeahead(pattern, 10);
}

printTypeahead(
pattern: string,
max: number,
) {
printTypeahead(pattern: string, max: number) {
const matchedTests = this.getMatchedTests(pattern);

const total = matchedTests.length;
Expand Down
37 changes: 11 additions & 26 deletions packages/jest-cli/src/TestPathPatternPrompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,47 +42,35 @@ module.exports = (
searchSource: SearchSource;

constructor() {
(this:any).onChange = this.onChange.bind(this);
(this: any).onChange = this.onChange.bind(this);
}

run(
onSuccess: Function,
onCancel: Function,
) {
run(onSuccess: Function, onCancel: Function) {
pipe.write(ansiEscapes.cursorHide);
pipe.write(ansiEscapes.clearScreen);
pipe.write(usage());
pipe.write(ansiEscapes.cursorShow);

prompt.enter(
this.onChange,
onSuccess,
onCancel,
);
prompt.enter(this.onChange, onSuccess, onCancel);
}

onChange(
pattern: string,
) {
onChange(pattern: string) {
let regex;

try {
regex = new RegExp(pattern, 'i');
} catch (e) {}

const paths = regex ?
this.searchSource.findMatchingTests(pattern).paths : [];
const paths = regex
? this.searchSource.findMatchingTests(pattern).paths
: [];

pipe.write(ansiEscapes.eraseLine);
pipe.write(ansiEscapes.cursorLeft);
this.printTypeahead(pattern, paths, 10);
}

printTypeahead(
pattern: string,
allResults: Array<Path>,
max: number,
) {
printTypeahead(pattern: string, allResults: Array<Path>, max: number) {
const total = allResults.length;
const results = allResults.slice(0, max);
const inputText = `${chalk.dim(' pattern \u203A')} ${pattern}`;
Expand All @@ -107,9 +95,8 @@ module.exports = (
const filePath = trimAndFormatPath(padding, config, rawPath, width);
return highlight(rawPath, filePath, pattern, config.rootDir);
})
.forEach(
filePath => pipe.write(`\n ${chalk.dim('\u203A')} ${filePath}`)
);
.forEach(filePath =>
pipe.write(`\n ${chalk.dim('\u203A')} ${filePath}`));

if (total > max) {
const more = total - max;
Expand All @@ -127,9 +114,7 @@ module.exports = (
pipe.write(ansiEscapes.cursorRestorePosition);
}

updateSearchSource(
hasteContext: HasteContext,
) {
updateSearchSource(hasteContext: HasteContext) {
this.searchSource = new SearchSource(hasteContext, config);
}
}
Expand Down
24 changes: 7 additions & 17 deletions packages/jest-cli/src/TestRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,9 @@ type Options = {|
getTestSummary: () => string,
|};

type OnRunFailure = (
path: string,
err: TestError,
) => void;
type OnRunFailure = (path: string, err: TestError) => void;

type OnTestResult = (
path: string,
result: TestResult,
) => void;
type OnTestResult = (path: string, result: TestResult) => void;

const TEST_WORKER_PATH = require.resolve('./TestWorker');

Expand All @@ -73,7 +67,7 @@ class TestRunner {
hasteContext: HasteContext,
config: Config,
options: Options,
startRun: () => *
startRun: () => *,
) {
this._config = config;
this._dispatcher = new ReporterDispatcher(
Expand Down Expand Up @@ -132,7 +126,7 @@ class TestRunner {
stats[filePath] || (stats[filePath] = fs.statSync(filePath).size);
const getTestRunTime = filePath => {
if (cache[filePath]) {
return (cache[filePath][0] === FAIL) ? Infinity : cache[filePath][1];
return cache[filePath][0] === FAIL ? Infinity : cache[filePath][1];
}
return null;
};
Expand Down Expand Up @@ -164,7 +158,7 @@ class TestRunner {
const perf = test.perfStats;
cache[test.testFilePath] = [
test.numFailingTests ? FAIL : SUCCESS,
(perf.end - perf.start) || 0,
perf.end - perf.start || 0,
];
}
});
Expand Down Expand Up @@ -582,8 +576,7 @@ class ReporterDispatcher {

onRunComplete(config, results) {
this._reporters.forEach(reporter =>
reporter.onRunComplete(config, results, this._runnerContext),
);
reporter.onRunComplete(config, results, this._runnerContext));
}

// Return a list of last errors for every reporter
Expand Down Expand Up @@ -612,10 +605,7 @@ const getEstimatedTime = (timings, workers) => {
return max;
}

return Math.max(
timings.reduce((sum, time) => sum + time) / workers,
max,
);
return Math.max(timings.reduce((sum, time) => sum + time) / workers, max);
};

module.exports = TestRunner;
1 change: 0 additions & 1 deletion packages/jest-cli/src/TestWatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class TestWatcher extends EventEmitter {
isWatchMode() {
return this._isWatchMode;
}

}

module.exports = TestWatcher;
2 changes: 1 addition & 1 deletion packages/jest-cli/src/TestWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type WorkerData = {|

type WorkerCallback = (error: ?SerializableError, result?: TestResult) => void;

const formatError = (error: string|Error): SerializableError => {
const formatError = (error: string | Error): SerializableError => {
if (typeof error === 'string') {
const {message, stack} = separateMessageFromStack(error);
return {
Expand Down
7 changes: 2 additions & 5 deletions packages/jest-cli/src/runJest.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ const getMaxWorkers = require('./lib/getMaxWorkers');
const path = require('path');
const setState = require('./lib/setState');

const getTestSummary = (
argv: Object,
patternInfo: PatternInfo,
) => {
const getTestSummary = (argv: Object, patternInfo: PatternInfo) => {
const testPathPattern = SearchSource.getTestPathPattern(patternInfo);
const testInfo = patternInfo.onlyChanged
? chalk.dim(' related to changed files')
Expand Down Expand Up @@ -101,7 +98,7 @@ const runJest = (
getTestSummary: () => getTestSummary(argv, patternInfo),
maxWorkers,
},
startRun
startRun,
).runTests(data.paths, testWatcher);
})
.then(runResults => {
Expand Down
1 change: 0 additions & 1 deletion packages/jest-cli/src/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const TestPathPatternPrompt = require('./TestPathPatternPrompt');
const TestNamePatternPrompt = require('./TestNamePatternPrompt');
const {KEYS, CLEAR} = require('./constants');


const watch = (
config: Config,
pipe: stream$Writable | tty$WriteStream,
Expand Down
Loading

0 comments on commit 6a3ac5d

Please sign in to comment.