From 938dd18b3cfe2f93a1bb0f7b80093ec7dfcec171 Mon Sep 17 00:00:00 2001 From: Aaron Abramov Date: Wed, 26 Jul 2017 11:45:09 -0700 Subject: [PATCH] flowtype packages tests #1 (#4130) --- .eslintrc.js | 15 ++++++++++- packages/jest-diff/src/__tests__/diff.test.js | 4 +-- .../jest-docblock/src/__tests__/index.test.js | 2 +- .../__tests__/parsers/babylon_parser.test.js | 2 ++ .../src/__tests__/project_workspace.test.js | 9 ++++++- .../src/__tests__/runner.test.js | 13 +++++++--- .../src/__tests__/settings.test.js | 23 +++++++++++++--- .../src/__tests__/test_reconciler.test.js | 26 ++++++++++++------- 8 files changed, 74 insertions(+), 20 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index b7895d9cab1b..333e6afd7b1b 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -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'], }, diff --git a/packages/jest-diff/src/__tests__/diff.test.js b/packages/jest-diff/src/__tests__/diff.test.js index 714e9c27a557..a820c9eca493 100644 --- a/packages/jest-diff/src/__tests__/diff.test.js +++ b/packages/jest-diff/src/__tests__/diff.test.js @@ -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'); @@ -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}.`, diff --git a/packages/jest-docblock/src/__tests__/index.test.js b/packages/jest-docblock/src/__tests__/index.test.js index 482ae3ffa3d4..ba58b1aed701 100644 --- a/packages/jest-docblock/src/__tests__/index.test.js +++ b/packages/jest-docblock/src/__tests__/index.test.js @@ -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'; diff --git a/packages/jest-editor-support/src/__tests__/parsers/babylon_parser.test.js b/packages/jest-editor-support/src/__tests__/parsers/babylon_parser.test.js index 63940a4220e2..ccc4f9deef34 100644 --- a/packages/jest-editor-support/src/__tests__/parsers/babylon_parser.test.js +++ b/packages/jest-editor-support/src/__tests__/parsers/babylon_parser.test.js @@ -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'; diff --git a/packages/jest-editor-support/src/__tests__/project_workspace.test.js b/packages/jest-editor-support/src/__tests__/project_workspace.test.js index 9aa0d3cd3dba..9c1cdbebe8ba 100644 --- a/packages/jest-editor-support/src/__tests__/project_workspace.test.js +++ b/packages/jest-editor-support/src/__tests__/project_workspace.test.js @@ -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'; @@ -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'); }); diff --git a/packages/jest-editor-support/src/__tests__/runner.test.js b/packages/jest-editor-support/src/__tests__/runner.test.js index ef09a5606446..aec8d4aa8bef 100644 --- a/packages/jest-editor-support/src/__tests__/runner.test.js +++ b/packages/jest-editor-support/src/__tests__/runner.test.js @@ -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'; @@ -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; @@ -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); }); diff --git a/packages/jest-editor-support/src/__tests__/settings.test.js b/packages/jest-editor-support/src/__tests__/settings.test.js index 91be282ef35d..659218b52f06 100644 --- a/packages/jest-editor-support/src/__tests__/settings.test.js +++ b/packages/jest-editor-support/src/__tests__/settings.test.js @@ -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'; @@ -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 = { @@ -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(); diff --git a/packages/jest-editor-support/src/__tests__/test_reconciler.test.js b/packages/jest-editor-support/src/__tests__/test_reconciler.test.js index 1eabfa6b336e..74e505380f6c 100644 --- a/packages/jest-editor-support/src/__tests__/test_reconciler.test.js +++ b/packages/jest-editor-support/src/__tests__/test_reconciler.test.js @@ -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'); @@ -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(); }); @@ -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'; @@ -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); }); });