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

Standardize file names in packages/jest-worker and packages/pretty-format #7316

Merged
merged 12 commits into from
Nov 14, 2018
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@
- `[docs]` Add correct default value for `testUrl` config option ([#7277](https://github.com/facebook/jest/pull/7277))
- `[jest-util]` [**BREAKING**] Remove long-deprecated globals for fake timers ([#7285](https://github.com/facebook/jest/pull/7285))
- `[docs]` Remove duplicate code in `MockFunctions` ([#7297](https://github.com/facebook/jest/pull/7297))
- `[jest-worker]` Standardize filenames ([#7316](https://github.com/facebook/jest/pull/7316))
- `[pretty-format]` Standardize filenames ([#7316](https://github.com/facebook/jest/pull/7316))

### Performance

Expand Down
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
projects: ['<rootDir>', '<rootDir>/examples/*/'],
setupFilesAfterEnv: ['<rootDir>/testSetupFile.js'],
snapshotSerializers: [
'<rootDir>/packages/pretty-format/build/plugins/convert_ansi.js',
'<rootDir>/packages/pretty-format/build/plugins/ConvertAnsi.js',
],
testEnvironment: './packages/jest-environment-node',
testPathIgnorePatterns: [
Expand All @@ -35,7 +35,7 @@ module.exports = {
'\\.snap$',
'/packages/.*/build',
'/packages/.*/build-es5',
'/packages/.*/src/__tests__/expect_util.js',
'/packages/.*/src/__tests__/getPrettyPrint.js',
'/packages/jest-cli/src/__tests__/test_root',
'/packages/jest-cli/src/__tests__/__fixtures__/',
'/packages/jest-cli/src/lib/__tests__/fixtures/',
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-worker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ This example covers the minimal usage:
import Worker from 'jest-worker';

async function main() {
const worker = new Worker(require.resolve('./worker'));
const worker = new Worker(require.resolve('./Worker'));
const result = await worker.hello('Alice'); // "Hello, Alice"
}

Expand Down Expand Up @@ -114,7 +114,7 @@ This example covers the standard usage:
import Worker from 'jest-worker';

async function main() {
const myWorker = new Worker(require.resolve('./worker'), {
const myWorker = new Worker(require.resolve('./Worker'), {
exposedMethods: ['foo', 'bar', 'getWorkerId'],
numWorkers: 4,
});
Expand Down Expand Up @@ -155,7 +155,7 @@ This example covers the usage with a `computeWorkerKey` method:
import Worker from 'jest-worker';

async function main() {
const myWorker = new Worker(require.resolve('./worker'), {
const myWorker = new Worker(require.resolve('./Worker'), {
computeWorkerKey: (method, filename) => filename,
});

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ beforeEach(() => {
return forkInterface;
});

Worker = require('../worker').default;
Worker = require('../Worker').default;
});

afterEach(() => {
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-worker/src/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ beforeEach(() => {
// The worker mock returns a worker with custom methods, plus it stores them
// in a global list, so that they can be accessed later. This list is reset in
// every test.
jest.mock('../worker', () => {
jest.mock('../Worker', () => {
const fakeClass = jest.fn(() => {
const fakeWorker = {
getStderr: () => ({once() {}, pipe() {}}),
Expand Down Expand Up @@ -63,7 +63,7 @@ beforeEach(() => {
virtual: true,
});

Worker = require('../worker').default;
Worker = require('../Worker').default;
Farm = require('../index').default;
});

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-worker/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type {FarmOptions} from './types';
import type {Readable} from 'stream';

import {CHILD_MESSAGE_CALL, CHILD_MESSAGE_END} from './types';
import Worker from './worker';
import Worker from './Worker';

/* istanbul ignore next */
const emptyMethod = () => {};
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-worker/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type PARENT_MESSAGE_ERROR =

// Option objects.

import type Worker from './worker';
import type Worker from './Worker';

export type ForkOptions = {
cwd?: string,
Expand Down
2 changes: 1 addition & 1 deletion packages/pretty-format/perf/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const React = require('react');
const ReactTestRenderer = require('react-test-renderer');
const leftPad = require('left-pad');
const prettyFormat = require('../build');
const ReactTestComponent = require('../build/plugins/react_test_component');
const ReactTestComponent = require('../build/plugins/ReactTestComponent');
const worldGeoJson = require('./world.geo.json');

const NANOSECONDS = 1000000000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

const prettyFormat = require('../');
const {DOMCollection, DOMElement} = prettyFormat.plugins;
const toPrettyPrintTo = require('./expect_util').getPrettyPrint([
const toPrettyPrintTo = require('./getPrettyPrint').default([
DOMCollection,
DOMElement,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

const prettyFormat = require('../');
const {DOMElement} = prettyFormat.plugins;
const toPrettyPrintTo = require('./expect_util').getPrettyPrint([DOMElement]);
const toPrettyPrintTo = require('./getPrettyPrint').default([DOMElement]);

const expect: any = global.expect;
expect.extend({toPrettyPrintTo});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import React from 'react';
import Immutable from 'immutable';
import {getPrettyPrint} from './expect_util';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The getPrettyPrint now only exports a single fn with the same name. Since there's no other exports there, maybe it's worth to change it to default export?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did the changes, not sure if that's what you meant, please take a look 👍

import getPrettyPrint from './getPrettyPrint';

const {plugins: prettyPlugins} = require('..');
const {Immutable: ImmutablePlugin, ReactElement} = prettyPlugins;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {OptionsReceived, Plugins} from 'types/PrettyFormat';
const diff = require('jest-diff');
const prettyFormat = require('../');

export const getPrettyPrint = (plugins: Plugins) =>
const getPrettyPrint = (plugins: Plugins) =>
function(received: any, expected: any, options?: OptionsReceived) {
const prettyFormatted = prettyFormat(
received,
Expand Down Expand Up @@ -52,3 +52,5 @@ export const getPrettyPrint = (plugins: Plugins) =>

return {actual: prettyFormatted, message, pass};
};

export default getPrettyPrint;
14 changes: 7 additions & 7 deletions packages/pretty-format/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ import {
printObjectProperties,
} from './collections';

import AsymmetricMatcher from './plugins/asymmetric_matcher';
import ConvertAnsi from './plugins/convert_ansi';
import DOMCollection from './plugins/dom_collection';
import DOMElement from './plugins/dom_element';
import Immutable from './plugins/immutable';
import ReactElement from './plugins/react_element';
import ReactTestComponent from './plugins/react_test_component';
import AsymmetricMatcher from './plugins/AsymmetricMatcher';
import ConvertAnsi from './plugins/ConvertAnsi';
import DOMCollection from './plugins/DOMCollection';
import DOMElement from './plugins/DOMElement';
import Immutable from './plugins/Immutable';
import ReactElement from './plugins/ReactElement';
import ReactTestComponent from './plugins/ReactTestComponent';

const toString = Object.prototype.toString;
const toISOString = Date.prototype.toISOString;
Expand Down
2 changes: 1 addition & 1 deletion packages/pretty-format/src/plugins/lib/markup.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import type {Config, Printer, Refs} from 'types/PrettyFormat';

import escapeHTML from './escape_html';
import escapeHTML from './escapeHTML';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rename the rest of the files in pretty-format? There's quite a bunch of left

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, I might have missed some, could you point out what files are left? I thought that the ones in /src/ have multiple exports per file, hence I left files with snake_case

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to rename every file that doesn't stick to the convention.
E.g.

packages/pretty-format/src/__tests__/asymmetric_matcher.test.js
packages/pretty-format/src/plugins/asymmetric_matcher.js

to have names as variables:

import AsymmetricMatcher from './plugins/asymmetric_matcher';
import ConvertAnsi from './plugins/convert_ansi';
import DOMCollection from './plugins/dom_collection';
import DOMElement from './plugins/dom_element';
import Immutable from './plugins/immutable';
import ReactElement from './plugins/react_element';
import ReactTestComponent from './plugins/react_test_component';

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the './plugins/asymmetric_matcher' has 3 exports, so according to those:

All folders -> kabab-case
All files that export a single Class -> CapitalizeCase
All files that export a single function -> camelCase
All other files -> underscore_case

its falling into the underscore_case?

Copy link
Collaborator

@thymikee thymikee Nov 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a mistake in interface, they shouldn't expose serialize and test directly, as they do it in a default export – and we only use it that way. You can remove those named exports. cc @pedrottimark

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thymikee Great, I will redo the exports and fix those files, thanks 👍


// Return empty string if keys is empty.
export const printProps = (
Expand Down