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

flowtype packages tests #1 #4130

Merged
merged 1 commit into from
Jul 26, 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
15 changes: 14 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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);
});
});