Skip to content

Commit

Permalink
Add initial Flow annotations.
Browse files Browse the repository at this point in the history
  • Loading branch information
cpojer committed Jun 14, 2016
1 parent 72037d2 commit 7c6b029
Show file tree
Hide file tree
Showing 34 changed files with 253 additions and 138 deletions.
2 changes: 2 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"comma-style": [2, "last"],
"computed-property-spacing": [2, "never"],
"eol-last": [2],
"max-len": [2, {"code": 80, "ignoreUrls": true, "ignorePattern": "^(\\s*const\\s.+=\\s*require\\s*\\(|\\s*it\\()"}],
"no-const-assign": [2],
"no-extra-parens": [2],
"no-irregular-whitespace": [2],
Expand All @@ -28,6 +29,7 @@
"prefer-arrow-callback": [2],
"prefer-const": [2],
"quotes": [2, "single", {"avoidEscape": true, "allowTemplateLiterals": true}],
"semi": [2, "always"],
"space-before-blocks": [2],
"space-before-function-paren": [2, "never"],
"space-in-parens": [2, "never"]
Expand Down
10 changes: 10 additions & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[ignore]
.*/packages/babel-plugin-jest-hoist/node_modules/fbjs/.*
.*/examples/.*
.*/website/.*

[include]

[libs]

[options]
2 changes: 1 addition & 1 deletion integration_tests/__tests__/snapshot-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe('Snapshot', () => {
expect(infoSR).toMatch('4 total in 2 test suites');
});

it('deletes the snapshot when a test does removes all the snapshots', () => {
it('deletes a snapshot when a test does removes all the snapshots', () => {
const firstRun = runJest.json('snapshot', []);

fs.writeFileSync(copyOfTestPath, emptyTest);
Expand Down
3 changes: 3 additions & 0 deletions integration_tests/__tests__/stack_trace-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,12 @@ describe('Stack Trace', () => {
);

// Make sure we show Jest's jest-resolve as part of the stack trace
/* eslint-disable max-len */
expect(stdout).toMatch(
/Error: Cannot find module 'this-module-does-not-exist' from 'test-error-test\.js'/
);
/* eslint-enable max-len */

expect(stdout).toMatch(
/\s+at\s(?:.+?)\s\((?:.+?)jest-resolve\/src\/index\.js/
);
Expand Down
7 changes: 5 additions & 2 deletions integration_tests/promise_it/__tests__/promise_it-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ describe('promise it', () => {
done();
});

it('is bount to context object', () => {
it('is bound to context object', () => {
return new Promise(resolve => {
if (this.someContextValue !== 'value') {
throw new Error('expected this.someContextValue to be set', this.someContextValue);
throw new Error(
'expected this.someContextValue to be set: ' +
this.someContextValue
);
}
resolve();
});
Expand Down
7 changes: 5 additions & 2 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"lerna": "2.0.0-beta.18",
"version": "12.1.1"
"lerna": "2.0.0-beta.19",
"version": "12.1.1",
"linkedFiles": {
"prefix": "/**\n * @flow\n */\n"
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
"eslint": "^2.12.0",
"eslint-plugin-babel": "^3.2.0",
"fbjs-scripts": "^0.7.1",
"flow-bin": "^0.27.0",
"glob": "^7.0.3",
"lerna": "2.0.0-beta.18",
"lerna": "2.0.0-beta.19",
"minimatch": "^3.0.0",
"progress": "^1.1.8",
"rimraf": "^2.5.2"
Expand Down
8 changes: 4 additions & 4 deletions packages/jest-changed-files/src/__tests__/git-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ describe('gitChecker', () => {

describe('isGitRepository', () => {

pit('returns null for non git repo folder', () => {
it('returns null for non git repo folder', () => {
return git.isGitRepository(tmpdir).then(res => {
expect(res).toBeNull();
});
});

pit('returns dirname for git repo folder', () => {
it('returns dirname for git repo folder', () => {
childProcess.spawnSync('git', ['init', tmpdir]);

return git.isGitRepository(tmpdir).then(res => {
Expand All @@ -53,13 +53,13 @@ describe('gitChecker', () => {
childProcess.spawnSync('git', ['init', tmpdir]);
});

pit('returns an empty array for git repo folder without modified files', () => {
it('returns an empty array for git repo folder without modified files', () => {
return git.findChangedFiles(tmpdir).then(res => {
expect(res).toEqual([]);
});
});

pit('returns an array of modified files for git repo folder', () => {
it('returns an array of modified files for git repo folder', () => {
fs.writeFileSync(tmpfile);
fs.writeFileSync(tmpfileNested);

Expand Down
1 change: 0 additions & 1 deletion packages/jest-cli/.npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
__tests__
__mocks__
.haste_cache
setup.js
3 changes: 2 additions & 1 deletion packages/jest-cli/src/Runtime/Runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class Runtime {
this._explicitShouldMock = Object.create(null);
this._isCurrentlyExecutingManualMock = null;
this._mockFactories = Object.create(null);
this._mocksPattern = config.mocksPattern ? new RegExp(config.mocksPattern) : null;
this._mocksPattern =
config.mocksPattern ? new RegExp(config.mocksPattern) : null;
this._shouldAutoMock = config.automock;
this._testRegex = new RegExp(config.testRegex.replace(/\//g, path.sep));
this._virtualMocks = Object.create(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('Runtime', () => {
};
});

pit('uses NODE_PATH to find modules', () => {
it('uses NODE_PATH to find modules', () => {
const nodePath = __dirname + '/NODE_PATH_dir';
return createLocalRuntime(nodePath).then(runtime => {
const exports = runtime.requireModuleOrMock(
Expand All @@ -42,7 +42,7 @@ describe('Runtime', () => {
});
});

pit('uses modulePaths to find modules', () => {
it('uses modulePaths to find modules', () => {
const nodePath = __dirname + '/NODE_PATH_dir';
return createLocalRuntime(null, {modulePaths: nodePath}).then(runtime => {
const exports = runtime.requireModuleOrMock(
Expand All @@ -53,7 +53,7 @@ describe('Runtime', () => {
});
});

pit('finds modules in NODE_PATH containing multiple paths', () => {
it('finds modules in NODE_PATH containing multiple paths', () => {
const nodePath =
cwd + '/some/other/path' + path.delimiter + __dirname + '/NODE_PATH_dir';
return createLocalRuntime(nodePath).then(runtime => {
Expand All @@ -65,7 +65,7 @@ describe('Runtime', () => {
});
});

pit('does not find modules if NODE_PATH is relative', () => {
it('does not find modules if NODE_PATH is relative', () => {
const nodePath =
cwd.substr(path.sep.length) + 'src/Runtime/__tests__/NODE_PATH_dir';
return createLocalRuntime(nodePath).then(runtime => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Runtime', () => {
});

describe('genMockFromModule', () => {
pit('does not cause side effects in the rest of the module system when generating a mock', () =>
it('does not cause side effects in the rest of the module system when generating a mock', () =>
createRuntime(__filename).then(runtime => {
const testRequire = runtime.requireModule.bind(
runtime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ describe('Runtime', () => {
createRuntime = require('createRuntime');
});

pit('passes config data through to jest.envData', () =>
it('passes config data through to jest.envData', () =>
createRuntime(__filename, config).then(runtime => {
const root = runtime.requireModule(runtime.__mockRootPath);
const envData = root.jest.getTestEnvData();
expect(envData).toEqual(config.testEnvData);
})
);

pit('freezes jest.envData object', () =>
it('freezes jest.envData object', () =>
createRuntime(__filename, config).then(runtime => {
const root = runtime.requireModule(runtime.__mockRootPath);
const envData = root.jest.getTestEnvData();
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-cli/src/Runtime/__tests__/Runtime-jest-fn.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Runtime', () => {
});

describe('jest.fn', () => {
pit('creates mock functions', () =>
it('creates mock functions', () =>
createRuntime(__filename).then(runtime => {
const root = runtime.requireModule(runtime.__mockRootPath);
const mock = root.jest.fn();
Expand All @@ -34,7 +34,7 @@ describe('Runtime', () => {
})
);

pit('creates mock functions with mock implementations', () =>
it('creates mock functions with mock implementations', () =>
createRuntime(__filename).then(runtime => {
const root = runtime.requireModule(runtime.__mockRootPath);
const mock = root.jest.fn(string => string + ' implementation');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('Runtime', () => {
});

describe('requireModule', () => {
pit('emulates a node stack trace during module load', () =>
it('emulates a node stack trace during module load', () =>
createRuntime(__filename).then(runtime => {
let hasThrown = false;
try {
Expand All @@ -34,7 +34,7 @@ describe('Runtime', () => {
})
);

pit('emulates a node stack trace during function execution', () =>
it('emulates a node stack trace during function execution', () =>
createRuntime(__filename).then(runtime => {
let hasThrown = false;
const sum = runtime.requireModule(
Expand All @@ -47,6 +47,7 @@ describe('Runtime', () => {
} catch (err) {
hasThrown = true;

/* eslint-disable max-len */
if (process.platform === 'win32') {
expect(err.stack).toMatch(
/^Error: throwing fn\s+at sum.+Runtime\\__tests__\\test_root\\throwing-fn.js:12:9/
Expand All @@ -56,6 +57,7 @@ describe('Runtime', () => {
/^Error: throwing fn\s+at sum.+Runtime\/__tests__\/test_root\/throwing-fn.js:12:9/
);
}
/* eslint-enable max-len */
}
expect(hasThrown).toBe(true);
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('Runtime', () => {
createRuntime = require('createRuntime');
});

pit('uses configured moduleDirectories', () =>
it('uses configured moduleDirectories', () =>
createRuntime(__filename, {moduleDirectories}).then(runtime => {
const exports = runtime.requireModule(
runtime.__mockRootPath,
Expand All @@ -39,7 +39,7 @@ describe('Runtime', () => {
})
);

pit('resolves packages', () =>
it('resolves packages', () =>
createRuntime(__filename, {moduleDirectories}).then(runtime => {
const exports = runtime.requireModule(
runtime.__mockRootPath,
Expand All @@ -49,7 +49,7 @@ describe('Runtime', () => {
})
);

pit('finds closest module from moduleDirectories', () =>
it('finds closest module from moduleDirectories', () =>
createRuntime(__filename, {moduleDirectories}).then(runtime => {
const exports = runtime.requireModule(
path.join(rootDir, 'subdir2', 'MyModule.js'),
Expand All @@ -60,7 +60,7 @@ describe('Runtime', () => {
})
);

pit('only checks the configured directories', () =>
it('only checks the configured directories', () =>
createRuntime(__filename, {moduleDirectories}).then(runtime => {
expect(() => {
runtime.requireModule(runtime.__mockRootPath, 'not-a-haste-package');
Expand Down
24 changes: 12 additions & 12 deletions packages/jest-cli/src/Runtime/__tests__/Runtime-requireMock-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Runtime', () => {
});

describe('requireMock', () => {
pit('uses manual mocks before attempting to automock', () =>
it('uses manual mocks before attempting to automock', () =>
createRuntime(__filename).then(runtime => {
const exports = runtime.requireMock(
runtime.__mockRootPath,
Expand All @@ -34,7 +34,7 @@ describe('Runtime', () => {
})
);

pit('can resolve modules that are only referenced from mocks', () =>
it('can resolve modules that are only referenced from mocks', () =>
createRuntime(__filename).then(runtime => {
const exports = runtime.requireMock(
runtime.__mockRootPath,
Expand All @@ -46,7 +46,7 @@ describe('Runtime', () => {
})
);

pit('stores and re-uses manual mock exports', () =>
it('stores and re-uses manual mock exports', () =>
createRuntime(__filename).then(runtime => {
let exports = runtime.requireMock(
runtime.__mockRootPath,
Expand All @@ -58,7 +58,7 @@ describe('Runtime', () => {
})
);

pit('automocks @providesModule modules without a manual mock', () =>
it('automocks @providesModule modules without a manual mock', () =>
createRuntime(__filename).then(runtime => {
const exports = runtime.requireMock(
runtime.__mockRootPath,
Expand All @@ -68,7 +68,7 @@ describe('Runtime', () => {
})
);

pit('automocks relative-path modules without a file extension', () =>
it('automocks relative-path modules without a file extension', () =>
createRuntime(__filename).then(runtime => {
const exports = runtime.requireMock(
__filename,
Expand All @@ -78,7 +78,7 @@ describe('Runtime', () => {
})
);

pit('automocks relative-path modules with a file extension', () =>
it('automocks relative-path modules with a file extension', () =>
createRuntime(__filename).then(runtime => {
const exports = runtime.requireMock(
__filename,
Expand All @@ -88,7 +88,7 @@ describe('Runtime', () => {
})
);

pit('just falls back when loading a native module', () =>
it('just falls back when loading a native module', () =>
createRuntime(__filename).then(runtime => {
let error;
// Okay so this is a really WAT way to test this, but we
Expand All @@ -111,7 +111,7 @@ describe('Runtime', () => {
})
);

pit('stores and re-uses automocked @providesModule exports', () =>
it('stores and re-uses automocked @providesModule exports', () =>
createRuntime(__filename).then(runtime => {
let exports = runtime.requireMock(
runtime.__mockRootPath,
Expand All @@ -123,7 +123,7 @@ describe('Runtime', () => {
})
);

pit('stores and re-uses automocked relative-path modules', () =>
it('stores and re-uses automocked relative-path modules', () =>
createRuntime(__filename).then(runtime => {
let exports = runtime.requireMock(
__filename,
Expand All @@ -138,7 +138,7 @@ describe('Runtime', () => {
})
);

pit('multiple node core modules returns correct module', () =>
it('multiple node core modules returns correct module', () =>
createRuntime(__filename).then(runtime => {
runtime.requireMock(runtime.__mockRootPath, 'fs');
expect(
Expand All @@ -147,15 +147,15 @@ describe('Runtime', () => {
})
);

pit('throws on non-existent @providesModule modules', () =>
it('throws on non-existent @providesModule modules', () =>
createRuntime(__filename).then(runtime => {
expect(() => {
runtime.requireMock(runtime.__mockRootPath, 'DoesntExist');
}).toThrow();
})
);

pit('uses the closest manual mock when duplicates exist', () =>
it('uses the closest manual mock when duplicates exist', () =>
createRuntime(__filename).then(runtime => {
const exports1 = runtime.requireMock(
runtime.__mockRootPath,
Expand Down
Loading

0 comments on commit 7c6b029

Please sign in to comment.