Skip to content

Commit

Permalink
--wip-- [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed May 7, 2017
1 parent 992e991 commit 4feb415
Show file tree
Hide file tree
Showing 230 changed files with 1,831 additions and 772 deletions.
3 changes: 2 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"transform-flow-strip-types",
"transform-es2015-destructuring",
"transform-es2015-parameters",
"transform-async-to-generator"
"transform-async-to-generator",
"transform-inline-imports-commonjs"
],
"retainLines": true
}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

/node_modules

/packages/*/build/
/packages/*/build-es5/
/packages/*/coverage/
/packages/*/node_modules/
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"babel-plugin-transform-es2015-destructuring": "^6.23.0",
"babel-plugin-transform-es2015-parameters": "^6.23.0",
"babel-plugin-transform-flow-strip-types": "^6.18.0",
"babel-plugin-transform-inline-imports-commonjs": "^1.2.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.4.0",
"babel-preset-react": "^6.24.1",
Expand Down
22 changes: 9 additions & 13 deletions packages/babel-jest/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
import type {Path, ProjectConfig} from 'types/Config';
import type {TransformOptions} from 'types/Transform';

const crypto = require('crypto');
const fs = require('fs');
const jestPreset = require('babel-preset-jest');
const path = require('path');
import crypto from 'crypto';
import fs from 'fs';
import jestPreset from 'babel-preset-jest';
import path from 'path';
import {transform as babelTransform, util as babelUtil} from 'babel-core';
import babelIstanbul from 'babel-plugin-istanbul';

const BABELRC_FILENAME = '.babelrc';
const BABELRC_JS_FILENAME = '.babelrc.js';
const BABEL_CONFIG_KEY = 'babel';
const PACAKAGE_JSON = 'package.json';
const THIS_FILE = fs.readFileSync(__filename);

let babel;

const createTransformer = (options: any) => {
const cache = Object.create(null);

Expand Down Expand Up @@ -100,11 +100,7 @@ const createTransformer = (options: any) => {
config: ProjectConfig,
transformOptions: TransformOptions,
): string {
if (!babel) {
babel = require('babel-core');
}

if (babel.util && !babel.util.canCompile(filename)) {
if (babelUtil && !babelUtil.canCompile(filename)) {
return src;
}

Expand All @@ -114,7 +110,7 @@ const createTransformer = (options: any) => {
// Copied from jest-runtime transform.js
theseOptions.plugins = theseOptions.plugins.concat([
[
require('babel-plugin-istanbul').default,
babelIstanbul,
{
// files outside `cwd` will not be instrumented
cwd: config.rootDir,
Expand All @@ -124,7 +120,7 @@ const createTransformer = (options: any) => {
]);
}

return babel.transform(src, theseOptions).code;
return babelTransform(src, theseOptions).code;
},
};
};
Expand Down
13 changes: 9 additions & 4 deletions packages/eslint-plugin-jest/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

'use strict';

import noDisabledTests from './rules/no-disabled-tests';
import noFocusedTests from './rules/no-focused-tests';
import noIdenticalTests from './rules/no-identical-title';
import validExpect from './rules/valid-expect';

module.exports = {
configs: {
recommended: {
Expand Down Expand Up @@ -44,9 +49,9 @@ module.exports = {
},
},
rules: {
'no-disabled-tests': require('./rules/no-disabled-tests'),
'no-focused-tests': require('./rules/no-focused-tests'),
'no-identical-title': require('./rules/no-identical-title'),
'valid-expect': require('./rules/valid-expect'),
'no-disabled-tests': noDisabledTests,
'no-focused-tests': noFocusedTests,
'no-identical-title': noIdenticalTests,
'valid-expect': validExpect,
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

'use strict';

const RuleTester = require('eslint').RuleTester;
const rules = require('../../').rules;
import {RuleTester} from 'eslint';
import {rules} from '../../';

const ruleTester = new RuleTester();
const expectedErrorMessage = 'Unexpected focused test.';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

'use strict';

const RuleTester = require('eslint').RuleTester;
const rules = require('../../').rules;
import {RuleTester} from 'eslint';
import {rules} from '../../';

const ruleTester = new RuleTester();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

'use strict';

const RuleTester = require('eslint').RuleTester;
const rules = require('../../').rules;
import {RuleTester} from 'eslint';
import {rules} from '../../';

const ruleTester = new RuleTester();
const expectedErrorMessage = 'Unexpected disabled test.';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

'use strict';

const RuleTester = require('eslint').RuleTester;
const rules = require('../../').rules;
import {RuleTester} from 'eslint';
import {rules} from '../../';

const ruleTester = new RuleTester();

Expand Down
12 changes: 6 additions & 6 deletions packages/jest-changed-files/src/__tests__/git-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
*/
'use strict';

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');
import os from 'os';
import fs from 'fs';
import path from 'path';
import rimraf from 'rimraf';
import mkdirp from 'mkdirp';
import childProcess from 'child_process';

const tmpdir = path.resolve(os.tmpdir(), 'jest-changed-files-git');
const tmpfile = path.resolve(tmpdir, Date.now() + '.js');
Expand Down
12 changes: 6 additions & 6 deletions packages/jest-changed-files/src/__tests__/hg-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
*/
'use strict';

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');
import os from 'os';
import fs from 'fs';
import path from 'path';
import rimraf from 'rimraf';
import mkdirp from 'mkdirp';
import childProcess from 'child_process';

const tmpdir = path.resolve(os.tmpdir(), 'jest-changed-files-hg');
const tmpfile = path.resolve(tmpdir, Date.now() + '.js');
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-changed-files/src/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

import type {Path} from 'types/Config';

const path = require('path');
const childProcess = require('child_process');
import path from 'path';
import childProcess from 'child_process';

type Options = {|
lastCommit?: boolean,
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-changed-files/src/hg.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

import type {Path} from 'types/Config';

const path = require('path');
const childProcess = require('child_process');
import path from 'path';
import childProcess from 'child_process';

const env = Object.assign({}, process.env, {
HGPLAIN: 1,
Expand Down
7 changes: 5 additions & 2 deletions packages/jest-changed-files/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

'use strict';

import git from './git';
import hg from './hg';

module.exports = {
git: require('./git'),
hg: require('./hg'),
git,
hg,
};
6 changes: 3 additions & 3 deletions packages/jest-cli/src/PatternPrompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

import type {ScrollOptions} from './lib/scrollList';

const chalk = require('chalk');
const ansiEscapes = require('ansi-escapes');
const Prompt = require('./lib/Prompt');
import chalk from 'chalk';
import ansiEscapes from 'ansi-escapes';
import Prompt from './lib/Prompt';

const usage = (entity: string) =>
`\n${chalk.bold('Pattern Mode Usage')}\n` +
Expand Down
15 changes: 6 additions & 9 deletions packages/jest-cli/src/SearchSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import type {Glob, Path} from 'types/Config';
import type {ResolveModuleConfig} from 'types/Resolve';
import type {Test} from 'types/TestRunner';

const micromatch = require('micromatch');
import {matcher as micromatchMatcher} from 'micromatch';

const DependencyResolver = require('jest-resolve-dependencies');
import DependencyResolver from 'jest-resolve-dependencies';

const changedFiles = require('jest-changed-files');
const path = require('path');
const {escapePathForRegex, replacePathSepForRegex} = require('jest-regex-util');
import {git, hg} from 'jest-changed-files';
import path from 'path';
import {escapePathForRegex, replacePathSepForRegex} from 'jest-regex-util';

type SearchResult = {|
noSCM?: boolean,
Expand All @@ -48,9 +48,6 @@ export type PathPattern = {|
watch?: boolean,
|};

const git = changedFiles.git;
const hg = changedFiles.hg;

const determineSCM = path =>
Promise.all([git.isGitRepository(path), hg.isHGRepository(path)]);
const pathToRegex = p => replacePathSepForRegex(p);
Expand All @@ -60,7 +57,7 @@ const globsToMatcher = (globs: ?Array<Glob>) => {
return () => true;
}

const matchers = globs.map(each => micromatch.matcher(each, {dot: true}));
const matchers = globs.map(each => micromatchMatcher(each, {dot: true}));
return path => matchers.some(each => each(path));
};

Expand Down
14 changes: 7 additions & 7 deletions packages/jest-cli/src/TestNamePatternPrompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@
import type {TestResult} from 'types/TestResult';
import type {ScrollOptions} from './lib/scrollList';

const scroll = require('./lib/scrollList');
const {getTerminalWidth} = require('./lib/terminalUtils');
const Prompt = require('./lib/Prompt');
const formatTestNameByPattern = require('./lib/formatTestNameByPattern');
const {
import scroll from './lib/scrollList';
import {getTerminalWidth} from './lib/terminalUtils';
import Prompt from './lib/Prompt';
import formatTestNameByPattern from './lib/formatTestNameByPattern';
import {
formatTypeaheadSelection,
printMore,
printPatternCaret,
printPatternMatches,
printRestoredPatternCaret,
printStartTyping,
printTypeaheadItem,
} = require('./lib/patternModeHelpers');
const PatternPrompt = require('./PatternPrompt');
} from './lib/patternModeHelpers';
import PatternPrompt from './PatternPrompt';

module.exports = class TestNamePatternPrompt extends PatternPrompt {
_cachedTestResults: Array<TestResult>;
Expand Down
20 changes: 10 additions & 10 deletions packages/jest-cli/src/TestPathPatternPrompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ import type {Test} from 'types/TestRunner';
import type {ScrollOptions} from './lib/scrollList';
import type SearchSource from './SearchSource';

const chalk = require('chalk');
const scroll = require('./lib/scrollList');
const {getTerminalWidth} = require('./lib/terminalUtils');
const highlight = require('./lib/highlight');
const stringLength = require('string-length');
const {trimAndFormatPath} = require('./reporters/utils');
const Prompt = require('./lib/Prompt');
const {
import chalk from 'chalk';
import scroll from './lib/scrollList';
import {getTerminalWidth} from './lib/terminalUtils';
import highlight from './lib/highlight';
import stringLength from 'string-length';
import {trimAndFormatPath} from './reporters/utils';
import Prompt from './lib/Prompt';
import {
formatTypeaheadSelection,
printMore,
printPatternCaret,
printPatternMatches,
printRestoredPatternCaret,
printStartTyping,
printTypeaheadItem,
} = require('./lib/patternModeHelpers');
const PatternPrompt = require('./PatternPrompt');
} from './lib/patternModeHelpers';
import PatternPrompt from './PatternPrompt';

type SearchSources = Array<{|
context: Context,
Expand Down
28 changes: 14 additions & 14 deletions packages/jest-cli/src/TestRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@ import type {Context} from 'types/Context';
import type {PathPattern} from './SearchSource';
import type {Reporter, Test} from 'types/TestRunner';

const {formatExecError} = require('jest-message-util');

const DefaultReporter = require('./reporters/DefaultReporter');
const NotifyReporter = require('./reporters/NotifyReporter');
const SummaryReporter = require('./reporters/SummaryReporter');
const VerboseReporter = require('./reporters/VerboseReporter');
const pify = require('pify');
const runTest = require('./runTest');
const snapshot = require('jest-snapshot');
const throat = require('throat');
const workerFarm = require('worker-farm');
const TestWatcher = require('./TestWatcher');
const ReporterDispatcher = require('./ReporterDispatcher');
import {formatExecError} from 'jest-message-util';

import DefaultReporter from './reporters/DefaultReporter';
import NotifyReporter from './reporters/NotifyReporter';
import SummaryReporter from './reporters/SummaryReporter';
import VerboseReporter from './reporters/VerboseReporter';
import pify from 'pify';
import runTest from './runTest';
import snapshot from 'jest-snapshot';
import throat from 'throat';
import workerFarm from 'worker-farm';
import TestWatcher from './TestWatcher';
import ReporterDispatcher from './ReporterDispatcher';
import CoverageReporter from './reporters/CoverageReporter';

const SLOW_TEST_TIME = 3000;

Expand Down Expand Up @@ -299,7 +300,6 @@ class TestRunner {
if (collectCoverage) {
// coverage reporter dependency graph is pretty big and we don't
// want to require it if we're not in the `--coverage` mode
const CoverageReporter = require('./reporters/CoverageReporter');
this.addReporter(
new CoverageReporter(this._globalConfig, {
maxWorkers: this._options.maxWorkers,
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-cli/src/TestSequencer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import type {AggregatedResult} from 'types/TestResult';
import type {Context} from 'types/Context';
import type {Test} from 'types/TestRunner';

const fs = require('fs');
const getCacheFilePath = require('jest-haste-map').getCacheFilePath;
import fs from 'fs';
import {getCacheFilePath} from 'jest-haste-map';

const FAIL = 0;
const SUCCESS = 1;
Expand Down
Loading

0 comments on commit 4feb415

Please sign in to comment.