From 2f32100c0e8ae04dc24da25f0713c004bb6b2c51 Mon Sep 17 00:00:00 2001 From: Andrew Pyle Date: Wed, 31 Oct 2018 04:29:05 -0500 Subject: [PATCH] Standardize filenames in packages/jest circus (#7301) * Rename event_handler -> eventHandler. Function & Mocks * Rename error_handlers -> globalErrorHandlers. File & imports * Rename format_node_assert_errors -> formatNodeAssertErrors - File, Function & Imports renamed - `export default (...` changed to `const formatNodeAssertErrors = (...` with `export default formatNodeAssertErrors` at end of file * Rename test_utils & runTest -> testUtils - Rename file, function, imports, mocks, & tests * Rename after_all.test.js -> afterAll.test.js - Rename file only * Rename after_all.test.js.snap -> afterAll.test.js.snap - Forgot snapshot when renaming afterAll.test.js - Rename snapshot to match test filename * Rename base_test.test.js -> baseTest.test.js - Rename file & snap * Rename circus_it_test_error.test.js -> circusItTestError.test.js * Rename circus_todo_test_error.test.js -> CircusItTodoTestError.test.js - Added "it" to name to match CircusItTestError.test.js - Rename file * Rename hooks_error.test.js -> hooksError.test.js - Rename file * Rename legacy_code_todo_rewrite -> legacy-code-todo-rewrite - Directory names should use dashes * Add CHANGELOG.md entry * Fix broken link to legacy-code-todo-rewrite/ in jest-circus/runner.js * Revert export in testUtils.js to runTest per @thymikee's request * Rename files in legacy-code-todo-rewrite/ - jest_adapter.js -> jestAdapter.js - jest_adapter_init.js -> jestAdapterInit.js - jest_expect.js -> jestExpect.js - Fixed imports within directory and in runner.js --- CHANGELOG.md | 1 + packages/jest-circus/runner.js | 2 +- .../{test_event_handler.js => testEventHandler.js} | 0 .../src/__mocks__/{test_utils.js => testUtils.js} | 2 +- .../{after_all.test.js.snap => afterAll.test.js.snap} | 0 .../{base_test.test.js.snap => baseTest.test.js.snap} | 0 .../src/__tests__/{after_all.test.js => afterAll.test.js} | 2 +- .../src/__tests__/{base_test.test.js => baseTest.test.js} | 2 +- ...rcus_it_test_error.test.js => circusItTestError.test.js} | 0 ...odo_test_error.test.js => circusItTodoTestError.test.js} | 0 packages/jest-circus/src/__tests__/hooks.test.js | 2 +- .../__tests__/{hooks_error.test.js => hooksError.test.js} | 0 .../jest-circus/src/{event_handler.js => eventHandler.js} | 6 +++--- ...rmat_node_assert_errors.js => formatNodeAssertErrors.js} | 4 +++- .../src/{error_handlers.js => globalErrorHandlers.js} | 0 .../jestAdapter.js} | 4 ++-- .../jestAdapterInit.js} | 0 .../jestExpect.js} | 0 packages/jest-circus/src/state.js | 4 ++-- 19 files changed, 16 insertions(+), 13 deletions(-) rename packages/jest-circus/src/__mocks__/{test_event_handler.js => testEventHandler.js} (100%) rename packages/jest-circus/src/__mocks__/{test_utils.js => testUtils.js} (97%) rename packages/jest-circus/src/__tests__/__snapshots__/{after_all.test.js.snap => afterAll.test.js.snap} (100%) rename packages/jest-circus/src/__tests__/__snapshots__/{base_test.test.js.snap => baseTest.test.js.snap} (100%) rename packages/jest-circus/src/__tests__/{after_all.test.js => afterAll.test.js} (97%) rename packages/jest-circus/src/__tests__/{base_test.test.js => baseTest.test.js} (94%) rename packages/jest-circus/src/__tests__/{circus_it_test_error.test.js => circusItTestError.test.js} (100%) rename packages/jest-circus/src/__tests__/{circus_todo_test_error.test.js => circusItTodoTestError.test.js} (100%) rename packages/jest-circus/src/__tests__/{hooks_error.test.js => hooksError.test.js} (100%) rename packages/jest-circus/src/{event_handler.js => eventHandler.js} (97%) rename packages/jest-circus/src/{format_node_assert_errors.js => formatNodeAssertErrors.js} (97%) rename packages/jest-circus/src/{error_handlers.js => globalErrorHandlers.js} (100%) rename packages/jest-circus/src/{legacy_code_todo_rewrite/jest_adapter.js => legacy-code-todo-rewrite/jestAdapter.js} (95%) rename packages/jest-circus/src/{legacy_code_todo_rewrite/jest_adapter_init.js => legacy-code-todo-rewrite/jestAdapterInit.js} (100%) rename packages/jest-circus/src/{legacy_code_todo_rewrite/jest_expect.js => legacy-code-todo-rewrite/jestExpect.js} (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b67389a430c..42f65a4894b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,7 @@ ### Chore & Maintenance +- `[jest-circus]` Standardize file naming in `jest-circus` ([#7301](https://github.com/facebook/jest/pull/7301)) - `[docs]` Add synchronous test.each setup ([#7150](https://github.com/facebook/jest/pull/7150)) - `[docs]` Add `this.extend` to the Custom Matchers API reference ([#7130](https://github.com/facebook/jest/pull/7130)) - `[docs]` Fix default value for `coverageReporters` value in configuration docs ([#7126](https://github.com/facebook/jest/pull/7126)) diff --git a/packages/jest-circus/runner.js b/packages/jest-circus/runner.js index 214956a9f42a..8ed8163ee414 100644 --- a/packages/jest-circus/runner.js +++ b/packages/jest-circus/runner.js @@ -9,5 +9,5 @@ */ // Allow people to use `jest-circus/runner` as a runner. -const runner = require('./build/legacy_code_todo_rewrite/jest_adapter'); +const runner = require('./build/legacy-code-todo-rewrite/jestAdapter'); module.exports = runner; diff --git a/packages/jest-circus/src/__mocks__/test_event_handler.js b/packages/jest-circus/src/__mocks__/testEventHandler.js similarity index 100% rename from packages/jest-circus/src/__mocks__/test_event_handler.js rename to packages/jest-circus/src/__mocks__/testEventHandler.js diff --git a/packages/jest-circus/src/__mocks__/test_utils.js b/packages/jest-circus/src/__mocks__/testUtils.js similarity index 97% rename from packages/jest-circus/src/__mocks__/test_utils.js rename to packages/jest-circus/src/__mocks__/testUtils.js index 39594b009a2b..4e3ca543dccb 100644 --- a/packages/jest-circus/src/__mocks__/test_utils.js +++ b/packages/jest-circus/src/__mocks__/testUtils.js @@ -20,7 +20,7 @@ import {skipSuiteOnWindows} from '../../../../scripts/ConditionalTest'; const CIRCUS_PATH = require.resolve('../../build/index'); const CIRCUS_RUN_PATH = require.resolve('../../build/run'); const CIRCUS_STATE_PATH = require.resolve('../../build/state'); -const TEST_EVENT_HANDLER_PATH = require.resolve('./test_event_handler'); +const TEST_EVENT_HANDLER_PATH = require.resolve('./testEventHandler'); const BABEL_REGISTER_PATH = require.resolve('babel-register'); skipSuiteOnWindows(); diff --git a/packages/jest-circus/src/__tests__/__snapshots__/after_all.test.js.snap b/packages/jest-circus/src/__tests__/__snapshots__/afterAll.test.js.snap similarity index 100% rename from packages/jest-circus/src/__tests__/__snapshots__/after_all.test.js.snap rename to packages/jest-circus/src/__tests__/__snapshots__/afterAll.test.js.snap diff --git a/packages/jest-circus/src/__tests__/__snapshots__/base_test.test.js.snap b/packages/jest-circus/src/__tests__/__snapshots__/baseTest.test.js.snap similarity index 100% rename from packages/jest-circus/src/__tests__/__snapshots__/base_test.test.js.snap rename to packages/jest-circus/src/__tests__/__snapshots__/baseTest.test.js.snap diff --git a/packages/jest-circus/src/__tests__/after_all.test.js b/packages/jest-circus/src/__tests__/afterAll.test.js similarity index 97% rename from packages/jest-circus/src/__tests__/after_all.test.js rename to packages/jest-circus/src/__tests__/afterAll.test.js index 22e424d96f20..7cccc1f66d49 100644 --- a/packages/jest-circus/src/__tests__/after_all.test.js +++ b/packages/jest-circus/src/__tests__/afterAll.test.js @@ -10,7 +10,7 @@ 'use strict'; -import {runTest} from '../__mocks__/test_utils'; +import {runTest} from '../__mocks__/testUtils'; test('tests are not marked done until their parent afterAll runs', () => { const {stdout} = runTest(` diff --git a/packages/jest-circus/src/__tests__/base_test.test.js b/packages/jest-circus/src/__tests__/baseTest.test.js similarity index 94% rename from packages/jest-circus/src/__tests__/base_test.test.js rename to packages/jest-circus/src/__tests__/baseTest.test.js index ec83663ba8db..1cc1c2abab94 100644 --- a/packages/jest-circus/src/__tests__/base_test.test.js +++ b/packages/jest-circus/src/__tests__/baseTest.test.js @@ -10,7 +10,7 @@ 'use strict'; -import {runTest} from '../__mocks__/test_utils'; +import {runTest} from '../__mocks__/testUtils'; test('simple test', () => { const {stdout} = runTest(` diff --git a/packages/jest-circus/src/__tests__/circus_it_test_error.test.js b/packages/jest-circus/src/__tests__/circusItTestError.test.js similarity index 100% rename from packages/jest-circus/src/__tests__/circus_it_test_error.test.js rename to packages/jest-circus/src/__tests__/circusItTestError.test.js diff --git a/packages/jest-circus/src/__tests__/circus_todo_test_error.test.js b/packages/jest-circus/src/__tests__/circusItTodoTestError.test.js similarity index 100% rename from packages/jest-circus/src/__tests__/circus_todo_test_error.test.js rename to packages/jest-circus/src/__tests__/circusItTodoTestError.test.js diff --git a/packages/jest-circus/src/__tests__/hooks.test.js b/packages/jest-circus/src/__tests__/hooks.test.js index 2486cc3d6e62..6d9b58bce341 100644 --- a/packages/jest-circus/src/__tests__/hooks.test.js +++ b/packages/jest-circus/src/__tests__/hooks.test.js @@ -10,7 +10,7 @@ 'use strict'; -import {runTest} from '../__mocks__/test_utils'; +import {runTest} from '../__mocks__/testUtils'; test('beforeEach is executed before each test in current/child describe blocks', () => { const {stdout} = runTest(` diff --git a/packages/jest-circus/src/__tests__/hooks_error.test.js b/packages/jest-circus/src/__tests__/hooksError.test.js similarity index 100% rename from packages/jest-circus/src/__tests__/hooks_error.test.js rename to packages/jest-circus/src/__tests__/hooksError.test.js diff --git a/packages/jest-circus/src/event_handler.js b/packages/jest-circus/src/eventHandler.js similarity index 97% rename from packages/jest-circus/src/event_handler.js rename to packages/jest-circus/src/eventHandler.js index fb5af141b802..893e61f61410 100644 --- a/packages/jest-circus/src/event_handler.js +++ b/packages/jest-circus/src/eventHandler.js @@ -20,12 +20,12 @@ import { import { injectGlobalErrorHandlers, restoreGlobalErrorHandlers, -} from './error_handlers'; +} from './globalErrorHandlers'; // To pass this value from Runtime object to state we need to use global[sym] const TEST_TIMEOUT_SYMBOL = Symbol.for('TEST_TIMEOUT_SYMBOL'); -const handler: EventHandler = (event, state): void => { +const eventHandler: EventHandler = (event, state): void => { switch (event.name) { case 'include_test_location_in_result': { state.includeTestLocationInResult = true; @@ -183,4 +183,4 @@ const handler: EventHandler = (event, state): void => { } }; -export default handler; +export default eventHandler; diff --git a/packages/jest-circus/src/format_node_assert_errors.js b/packages/jest-circus/src/formatNodeAssertErrors.js similarity index 97% rename from packages/jest-circus/src/format_node_assert_errors.js rename to packages/jest-circus/src/formatNodeAssertErrors.js index 9151fa9fe3fa..d6080ce0b168 100644 --- a/packages/jest-circus/src/format_node_assert_errors.js +++ b/packages/jest-circus/src/formatNodeAssertErrors.js @@ -43,7 +43,7 @@ const humanReadableOperators = { strictEqual: 'to strictly be equal', }; -export default (event: Event, state: State) => { +const formatNodeAssertErrors = (event: Event, state: State) => { switch (event.name) { case 'test_done': { event.test.errors = event.test.errors.map(errors => { @@ -167,3 +167,5 @@ function assertionErrorMessage(error: AssertionError, options: DiffOptions) { trimmedStack ); } + +export default formatNodeAssertErrors; diff --git a/packages/jest-circus/src/error_handlers.js b/packages/jest-circus/src/globalErrorHandlers.js similarity index 100% rename from packages/jest-circus/src/error_handlers.js rename to packages/jest-circus/src/globalErrorHandlers.js diff --git a/packages/jest-circus/src/legacy_code_todo_rewrite/jest_adapter.js b/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapter.js similarity index 95% rename from packages/jest-circus/src/legacy_code_todo_rewrite/jest_adapter.js rename to packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapter.js index bf2d87b9f4bd..af85e4d095b4 100644 --- a/packages/jest-circus/src/legacy_code_todo_rewrite/jest_adapter.js +++ b/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapter.js @@ -12,7 +12,7 @@ import type {GlobalConfig, ProjectConfig} from 'types/Config'; import type {TestResult} from 'types/TestResult'; import type Runtime from 'jest-runtime'; -const FRAMEWORK_INITIALIZER = require.resolve('./jest_adapter_init'); +const FRAMEWORK_INITIALIZER = require.resolve('./jestAdapterInit'); import path from 'path'; const jestAdapter = async ( @@ -28,7 +28,7 @@ const jestAdapter = async ( } = runtime.requireInternalModule(FRAMEWORK_INITIALIZER); runtime - .requireInternalModule(path.resolve(__dirname, './jest_expect.js')) + .requireInternalModule(path.resolve(__dirname, './jestExpect.js')) .default({ expand: globalConfig.expand, }); diff --git a/packages/jest-circus/src/legacy_code_todo_rewrite/jest_adapter_init.js b/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.js similarity index 100% rename from packages/jest-circus/src/legacy_code_todo_rewrite/jest_adapter_init.js rename to packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.js diff --git a/packages/jest-circus/src/legacy_code_todo_rewrite/jest_expect.js b/packages/jest-circus/src/legacy-code-todo-rewrite/jestExpect.js similarity index 100% rename from packages/jest-circus/src/legacy_code_todo_rewrite/jest_expect.js rename to packages/jest-circus/src/legacy-code-todo-rewrite/jestExpect.js diff --git a/packages/jest-circus/src/state.js b/packages/jest-circus/src/state.js index 3187775bcc2f..36d4fa69cf04 100644 --- a/packages/jest-circus/src/state.js +++ b/packages/jest-circus/src/state.js @@ -10,8 +10,8 @@ import type {Event, State, EventHandler} from 'types/Circus'; import {makeDescribe} from './utils'; -import eventHandler from './event_handler'; -import formatNodeAssertErrors from './format_node_assert_errors'; +import eventHandler from './eventHandler'; +import formatNodeAssertErrors from './formatNodeAssertErrors'; const eventHandlers: Array = [ eventHandler,