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

Add es5 build of pretty-format #4075

Merged
merged 1 commit into from
Jul 20, 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
5 changes: 5 additions & 0 deletions integration_tests/browser-support/browser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* eslint-disable */
var expect = require('../../packages/jest-matchers/build-es5/index.js');
var mock = require('../../packages/jest-mock/build-es5/index.js');
var prettyFormat = require('../../packages/pretty-format/build-es5/index.js');

describe('es5 builds in browser', function() {
it('runs assertions', function() {
Expand All @@ -21,4 +22,8 @@ describe('es5 builds in browser', function() {
someMockFunction();
expect(someMockFunction).toHaveBeenCalledTimes(1);
});

it('pretty formats a string', function() {
expect(prettyFormat('obj')).toBe('"obj"');
});
});
1 change: 1 addition & 0 deletions packages/pretty-format/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"license": "BSD-3-Clause",
"description": "Stringify any JavaScript value.",
"main": "build/index.js",
"browser": "build-es5/index.js",
"author": "James Kyle <me@thejameskyle.com>",
"dependencies": {
"ansi-regex": "^3.0.0",
Expand Down
14 changes: 8 additions & 6 deletions packages/pretty-format/src/__tests__/immutable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

'use strict';

const React = require('react');
const Immutable = require('immutable');
const ReactElementPlugin = require('../plugins/react_element');
const ReactTestComponentPlugin = require('../plugins/react_test_component');
const ImmutablePlugins = require('../plugins/immutable_plugins');
const toPrettyPrintTo = require('./expect_util').getPrettyPrint(
import React from 'react';
import Immutable from 'immutable';
import ReactElementPlugin from '../plugins/react_element';
import ReactTestComponentPlugin from '../plugins/react_test_component';
import ImmutablePlugins from '../plugins/immutable_plugins';
import expectUtil from './expect_util';

const toPrettyPrintTo = expectUtil.getPrettyPrint(
[ReactElementPlugin, ReactTestComponentPlugin].concat(ImmutablePlugins),
);

Expand Down
7 changes: 4 additions & 3 deletions packages/pretty-format/src/plugins/asymmetric_matcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const SPACE = ' ';
class ArrayContaining extends Array {}
class ObjectContaining extends Object {}

const print = (
export const print = (
val: any,
print: Print,
indent: Indent,
Expand Down Expand Up @@ -56,6 +56,7 @@ const print = (
return val.toAsymmetricMatcher();
};

const test = (object: any) => object && object.$$typeof === asymmetricMatcher;
export const test = (object: any) =>
object && object.$$typeof === asymmetricMatcher;

module.exports = ({print, test}: Plugin);
export default ({print, test}: Plugin);
6 changes: 3 additions & 3 deletions packages/pretty-format/src/plugins/convert_ansi.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ const toHumanReadableAnsi = text => {
});
};

const test = (value: any) =>
export const test = (value: any) =>
typeof value === 'string' && value.match(ansiRegex());

const print = (
export const print = (
val: any,
print: Print,
indent: Indent,
opts: PluginOptions,
colors: Colors,
) => print(toHumanReadableAnsi(val));

module.exports = ({print, test}: Plugin);
export default ({print, test}: Plugin);
6 changes: 3 additions & 3 deletions packages/pretty-format/src/plugins/html_element.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type HTMLComment = {
};

const HTML_ELEMENT_REGEXP = /(HTML\w*?Element)|Text|Comment/;
const test = isHTMLElement;
export const test = isHTMLElement;

function isHTMLElement(value: any) {
return (
Expand Down Expand Up @@ -93,7 +93,7 @@ function printAttributes(
.join('');
}

const print = (
export const print = (
element: HTMLElement | HTMLText | HTMLComment,
print: Print,
indent: Indent,
Expand Down Expand Up @@ -155,4 +155,4 @@ const print = (
return result;
};

module.exports = ({print, test}: Plugin);
export default ({print, test}: Plugin);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

By adding both the default and named export we support both ES6 module consumers (like rollup) and CommonJS require use several places in Jest source code.

6 changes: 3 additions & 3 deletions packages/pretty-format/src/plugins/immutable_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import type {
import printImmutable from './lib/print_immutable';

const IS_LIST = '@@__IMMUTABLE_LIST__@@';
const test = (maybeList: any) => !!(maybeList && maybeList[IS_LIST]);
export const test = (maybeList: any) => !!(maybeList && maybeList[IS_LIST]);

const print = (
export const print = (
val: any,
print: Print,
indent: Indent,
opts: PluginOptions,
colors: Colors,
) => printImmutable(val, print, indent, opts, colors, 'List', false);

module.exports = ({print, test}: Plugin);
export default ({print, test}: Plugin);
6 changes: 3 additions & 3 deletions packages/pretty-format/src/plugins/immutable_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import printImmutable from './lib/print_immutable';

const IS_MAP = '@@__IMMUTABLE_MAP__@@';
const IS_ORDERED = '@@__IMMUTABLE_ORDERED__@@';
const test = (maybeMap: any) =>
export const test = (maybeMap: any) =>
!!(maybeMap && maybeMap[IS_MAP] && !maybeMap[IS_ORDERED]);

const print = (
export const print = (
val: any,
print: Print,
indent: Indent,
opts: PluginOptions,
colors: Colors,
) => printImmutable(val, print, indent, opts, colors, 'Map', true);

module.exports = ({print, test}: Plugin);
export default ({print, test}: Plugin);
6 changes: 3 additions & 3 deletions packages/pretty-format/src/plugins/immutable_ordered_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import printImmutable from './lib/print_immutable';

const IS_MAP = '@@__IMMUTABLE_MAP__@@';
const IS_ORDERED = '@@__IMMUTABLE_ORDERED__@@';
const test = (maybeOrderedMap: any) =>
export const test = (maybeOrderedMap: any) =>
maybeOrderedMap && maybeOrderedMap[IS_MAP] && maybeOrderedMap[IS_ORDERED];

const print = (
export const print = (
val: any,
print: Print,
indent: Indent,
opts: PluginOptions,
colors: Colors,
) => printImmutable(val, print, indent, opts, colors, 'OrderedMap', true);

module.exports = ({print, test}: Plugin);
export default ({print, test}: Plugin);
6 changes: 3 additions & 3 deletions packages/pretty-format/src/plugins/immutable_ordered_set.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import printImmutable from './lib/print_immutable';

const IS_SET = '@@__IMMUTABLE_SET__@@';
const IS_ORDERED = '@@__IMMUTABLE_ORDERED__@@';
const test = (maybeOrderedSet: any) =>
export const test = (maybeOrderedSet: any) =>
maybeOrderedSet && maybeOrderedSet[IS_SET] && maybeOrderedSet[IS_ORDERED];

const print = (
export const print = (
val: any,
print: Print,
indent: Indent,
opts: PluginOptions,
colors: Colors,
) => printImmutable(val, print, indent, opts, colors, 'OrderedSet', false);

module.exports = ({print, test}: Plugin);
export default ({print, test}: Plugin);
2 changes: 1 addition & 1 deletion packages/pretty-format/src/plugins/immutable_plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import ImmutableOrderedSet from './immutable_ordered_set';
import ImmutableOrderedMap from './immutable_ordered_map';
import ImmutableRecord from './immutable_record';

module.exports = [
export default [
ImmutableList,
ImmutableSet,
ImmutableMap,
Expand Down
7 changes: 4 additions & 3 deletions packages/pretty-format/src/plugins/immutable_record.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ import type {
import printImmutable from './lib/print_immutable';

const IS_RECORD = '@@__IMMUTABLE_RECORD__@@';
const test = (maybeRecord: any) => !!(maybeRecord && maybeRecord[IS_RECORD]);
export const test = (maybeRecord: any) =>
!!(maybeRecord && maybeRecord[IS_RECORD]);

const print = (
export const print = (
val: any,
print: Print,
indent: Indent,
opts: PluginOptions,
colors: Colors,
) => printImmutable(val, print, indent, opts, colors, 'Record', true);

module.exports = ({print, test}: Plugin);
export default ({print, test}: Plugin);
6 changes: 3 additions & 3 deletions packages/pretty-format/src/plugins/immutable_set.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import printImmutable from './lib/print_immutable';

const IS_SET = '@@__IMMUTABLE_SET__@@';
const IS_ORDERED = '@@__IMMUTABLE_ORDERED__@@';
const test = (maybeSet: any) =>
export const test = (maybeSet: any) =>
!!(maybeSet && maybeSet[IS_SET] && !maybeSet[IS_ORDERED]);

const print = (
export const print = (
val: any,
print: Print,
indent: Indent,
opts: PluginOptions,
colors: Colors,
) => printImmutable(val, print, indent, opts, colors, 'Set', false);

module.exports = ({print, test}: Plugin);
export default ({print, test}: Plugin);
6 changes: 3 additions & 3 deletions packages/pretty-format/src/plugins/immutable_stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import type {
import printImmutable from './lib/print_immutable';

const IS_STACK = '@@__IMMUTABLE_STACK__@@';
const test = (maybeStack: any) => !!(maybeStack && maybeStack[IS_STACK]);
export const test = (maybeStack: any) => !!(maybeStack && maybeStack[IS_STACK]);

const print = (
export const print = (
val: any,
print: Print,
indent: Indent,
opts: PluginOptions,
colors: Colors,
) => printImmutable(val, print, indent, opts, colors, 'Stack', false);

module.exports = ({print, test}: Plugin);
export default ({print, test}: Plugin);
4 changes: 1 addition & 3 deletions packages/pretty-format/src/plugins/lib/escape_html.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
* @flow
*/

function escapeHTML(str: string): string {
export default function escapeHTML(str: string): string {
return str.replace(/</g, '&lt;').replace(/>/g, '&gt;');
}

module.exports = escapeHTML;
2 changes: 1 addition & 1 deletion packages/pretty-format/src/plugins/lib/print_immutable.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ const printImmutable = (
);
};

module.exports = printImmutable;
export default printImmutable;
6 changes: 3 additions & 3 deletions packages/pretty-format/src/plugins/react_element.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function printProps(props, print, indent, colors, opts) {
.join('');
}

const print = (
export const print = (
element: React$Element<*>,
print: Print,
indent: Indent,
Expand Down Expand Up @@ -127,7 +127,7 @@ const print = (

// Disabling lint rule as we don't know type ahead of time.
/* eslint-disable flowtype/no-weak-types */
const test = (object: any) => object && object.$$typeof === reactElement;
export const test = (object: any) => object && object.$$typeof === reactElement;
/* eslint-enable flowtype/no-weak-types */

module.exports = ({print, test}: Plugin);
export default ({print, test}: Plugin);
6 changes: 3 additions & 3 deletions packages/pretty-format/src/plugins/react_test_component.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function printProps(props: Object, print, indent, colors, opts) {
.join('');
}

const print = (
export const print = (
instance: ReactTestObject,
print: Print,
indent: Indent,
Expand Down Expand Up @@ -113,7 +113,7 @@ const print = (
return result;
};

const test = (object: Object) =>
export const test = (object: Object) =>
object && object.$$typeof === reactTestInstance;

module.exports = ({print, test}: Plugin);
export default ({print, test}: Plugin);