Skip to content

Commit

Permalink
flowtype packages tests jestjs#1 (jestjs#4130)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronabramov committed Jul 26, 2017
1 parent ecbebd0 commit 938dd18
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 20 deletions.
15 changes: 14 additions & 1 deletion .eslintrc.js
Expand Up @@ -90,7 +90,20 @@ module.exports = {
},
},
{
files: ['integration_tests/__tests__/**/*'],
files: [
'integration_tests/__tests__/**/*',
'packages/babel-jest/**/*.test.js',
'packages/babel-plugin-jest-hoist/**/*.test.js',
'packages/babel-preset-jest/**/*.test.js',
'packages/eslint-config-fb-strict/**/*.test.js',
'packages/eslint-plugin-jest/**/*.test.js',
'packages/jest/**/*.test.js',
'packages/jest-changed-files/**/*.test.js',
'packages/jest-circus/**/*.test.js',
'packages/jest-diff/**/*.test.js',
'packages/jest-docblock/**/*.test.js',
'packages/jest-editor-support/**/*.test.js',
],
rules: {
'flowtype/require-valid-file-annotation': [2, 'always'],
},
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-diff/src/__tests__/diff.test.js
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails oncall+jsinfra
* @flow
*/

const stripAnsi = require('strip-ansi');
Expand All @@ -28,7 +28,7 @@ describe('different types', () => {
const typeA = values[2];
const typeB = values[3];

test(`'${a}' and '${b}'`, () => {
test(`'${String(a)}' and '${String(b)}'`, () => {
expect(stripAnsi(diff(a, b))).toBe(
' Comparing two different types of values. ' +
`Expected ${typeA} but received ${typeB}.`,
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-docblock/src/__tests__/index.test.js
Expand Up @@ -6,7 +6,7 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails oncall+jsinfra
* @flow
*/

'use strict';
Expand Down
Expand Up @@ -4,6 +4,8 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
*/

'use strict';
Expand Down
Expand Up @@ -4,6 +4,8 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
*/

'use strict';
Expand All @@ -12,7 +14,12 @@ const ProjectWorkspace = require('../project_workspace');

describe('setup', () => {
it('sets itself up fom the constructor', () => {
const workspace = new ProjectWorkspace('root_path', 'path_to_jest');
const workspace = new ProjectWorkspace(
'root_path',
'path_to_jest',
'path_to_config',
1000,
);
expect(workspace.rootPath).toEqual('root_path');
expect(workspace.pathToJest).toEqual('path_to_jest');
});
Expand Down
13 changes: 10 additions & 3 deletions packages/jest-editor-support/src/__tests__/runner.test.js
Expand Up @@ -4,6 +4,8 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
*/

'use strict';
Expand Down Expand Up @@ -42,9 +44,14 @@ describe('events', () => {

beforeEach(() => {
mockCreateProcess.mockClear();
const workspace = new ProjectWorkspace('.', 'node_modules/.bin/jest', 18);
const workspace = new ProjectWorkspace(
'.',
'node_modules/.bin/jest',
'test',
18,
);
runner = new Runner(workspace);
fakeProcess = new EventEmitter();
fakeProcess = (new EventEmitter(): any);
fakeProcess.stdout = new EventEmitter();
fakeProcess.stderr = new EventEmitter();
mockDebugProcess = fakeProcess;
Expand All @@ -66,7 +73,7 @@ describe('events', () => {

// And lets check what we emit
const dataAtPath = readFileSync(runner.outputPath);
const storedJSON = JSON.parse(dataAtPath);
const storedJSON = JSON.parse(dataAtPath.toString());
expect(data.mock.calls[0][0]).toEqual(storedJSON);
});

Expand Down
23 changes: 20 additions & 3 deletions packages/jest-editor-support/src/__tests__/settings.test.js
Expand Up @@ -4,6 +4,8 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
*/

'use strict';
Expand All @@ -14,14 +16,24 @@ const Settings = require('../Settings');

describe('Settings', () => {
it('sets itself up fom the constructor', () => {
const workspace = new ProjectWorkspace('root_path', 'path_to_jest');
const workspace = new ProjectWorkspace(
'root_path',
'path_to_jest',
'test',
1000,
);
const settings = new Settings(workspace);
expect(settings.workspace).toEqual(workspace);
expect(settings.settings).toEqual(expect.any(Object));
});

it('reads and parses the config', () => {
const workspace = new ProjectWorkspace('root_path', 'path_to_jest');
const workspace = new ProjectWorkspace(
'root_path',
'path_to_jest',
'test',
1000,
);
const completed = jest.fn();
const config = {cacheDirectory: '/tmp/jest', name: '[md5 hash]'};
const json = {
Expand All @@ -45,7 +57,12 @@ describe('Settings', () => {
});

it('calls callback even if no data is sent', () => {
const workspace = new ProjectWorkspace('root_path', 'path_to_jest');
const workspace = new ProjectWorkspace(
'root_path',
'path_to_jest',
'test',
1000,
);
const completed = jest.fn();

const mockProcess: any = new EventEmitter();
Expand Down
26 changes: 17 additions & 9 deletions packages/jest-editor-support/src/__tests__/test_reconciler.test.js
Expand Up @@ -4,6 +4,8 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
*/

const fs = require('fs');
Expand All @@ -29,7 +31,10 @@ describe('Test Reconciler', () => {
it('passes a passing method', () => {
parser = reconcilerWithFile('failing_jest_json.json');
const testName = 'does not validate without josh';
const status = parser.stateForTestAssertion(dangerFilePath, testName);
const status: any = parser.stateForTestAssertion(
dangerFilePath,
testName,
);
expect(status.status).toEqual('KnownSuccess');
expect(status.line).toBeNull();
});
Expand All @@ -40,7 +45,10 @@ describe('Test Reconciler', () => {
'validates when all Travis environment' +
' vars are set and Josh K says so';

const status = parser.stateForTestAssertion(dangerFilePath, testName);
const status: any = parser.stateForTestAssertion(
dangerFilePath,
testName,
);
expect(status.status).toEqual('KnownFail');
expect(status.line).toEqual(12);
const errorMessage = 'Expected value to be falsy, instead received true';
Expand All @@ -64,30 +72,30 @@ describe('Terse Messages', () => {

let message = 'Expected value to equal: 2, Received: 1';
let testName = 'numbers';
expect(terseForTest(testName).terseMessage).toEqual(message);
expect(terseForTest(testName)).toHaveProperty('terseMessage', message);

message = 'Expected value to equal: 2, Received: "1"';
testName = 'string to numbers: numbers';
expect(terseForTest(testName).terseMessage).toEqual(message);
expect(terseForTest(testName)).toHaveProperty('terseMessage', message);

message = 'Expected value to equal: {"a": 2}, Received: {}';
testName = 'objects';
expect(terseForTest(testName).terseMessage).toEqual(message);
expect(terseForTest(testName)).toHaveProperty('terseMessage', message);

message = 'Snapshot has changed';
testName = 'snapshots';
expect(terseForTest(testName).terseMessage).toEqual(message);
expect(terseForTest(testName)).toHaveProperty('terseMessage', message);

message = 'Expected value to be greater than: 3, Received: 2';
testName = 'greater than';
expect(terseForTest(testName).terseMessage).toEqual(message);
expect(terseForTest(testName)).toHaveProperty('terseMessage', message);

message = 'Expected value to be falsy, instead received 2';
testName = 'falsy';
expect(terseForTest(testName).terseMessage).toEqual(message);
expect(terseForTest(testName)).toHaveProperty('terseMessage', message);

message = 'Expected value to be truthy, instead received null';
testName = 'truthy';
expect(terseForTest(testName).terseMessage).toEqual(message);
expect(terseForTest(testName)).toHaveProperty('terseMessage', message);
});
});

0 comments on commit 938dd18

Please sign in to comment.