From e19d0b0e6bc568f6859213283be8fd445377b0fd Mon Sep 17 00:00:00 2001 From: skovhus Date: Wed, 19 Jul 2017 16:17:23 +0200 Subject: [PATCH] Add es5 build of pretty-format --- integration_tests/browser-support/browser-test.js | 5 +++++ packages/pretty-format/package.json | 1 + packages/pretty-format/src/plugins/asymmetric_matcher.js | 7 ++++--- packages/pretty-format/src/plugins/convert_ansi.js | 6 +++--- packages/pretty-format/src/plugins/html_element.js | 6 +++--- packages/pretty-format/src/plugins/immutable_list.js | 6 +++--- packages/pretty-format/src/plugins/immutable_map.js | 6 +++--- .../pretty-format/src/plugins/immutable_ordered_map.js | 6 +++--- .../pretty-format/src/plugins/immutable_ordered_set.js | 6 +++--- packages/pretty-format/src/plugins/immutable_plugins.js | 5 ++++- packages/pretty-format/src/plugins/immutable_record.js | 7 ++++--- packages/pretty-format/src/plugins/immutable_set.js | 6 +++--- packages/pretty-format/src/plugins/immutable_stack.js | 6 +++--- packages/pretty-format/src/plugins/lib/escape_html.js | 4 +--- packages/pretty-format/src/plugins/lib/print_immutable.js | 2 +- packages/pretty-format/src/plugins/react_element.js | 6 +++--- packages/pretty-format/src/plugins/react_test_component.js | 6 +++--- 17 files changed, 50 insertions(+), 41 deletions(-) diff --git a/integration_tests/browser-support/browser-test.js b/integration_tests/browser-support/browser-test.js index 738c56a15a07..ab8d7479cd74 100644 --- a/integration_tests/browser-support/browser-test.js +++ b/integration_tests/browser-support/browser-test.js @@ -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() { @@ -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"'); + }); }); diff --git a/packages/pretty-format/package.json b/packages/pretty-format/package.json index d2dea9a967fd..c94e1de2dc22 100644 --- a/packages/pretty-format/package.json +++ b/packages/pretty-format/package.json @@ -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 ", "dependencies": { "ansi-regex": "^3.0.0", diff --git a/packages/pretty-format/src/plugins/asymmetric_matcher.js b/packages/pretty-format/src/plugins/asymmetric_matcher.js index b98d4b484ae9..7bc867d5c770 100644 --- a/packages/pretty-format/src/plugins/asymmetric_matcher.js +++ b/packages/pretty-format/src/plugins/asymmetric_matcher.js @@ -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, @@ -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); diff --git a/packages/pretty-format/src/plugins/convert_ansi.js b/packages/pretty-format/src/plugins/convert_ansi.js index 9c60fc5369fe..feb65116ed70 100644 --- a/packages/pretty-format/src/plugins/convert_ansi.js +++ b/packages/pretty-format/src/plugins/convert_ansi.js @@ -41,10 +41,10 @@ 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, @@ -52,4 +52,4 @@ const print = ( colors: Colors, ) => print(toHumanReadableAnsi(val)); -module.exports = ({print, test}: Plugin); +export default ({print, test}: Plugin); diff --git a/packages/pretty-format/src/plugins/html_element.js b/packages/pretty-format/src/plugins/html_element.js index 73157b204e1f..9ff149f20986 100644 --- a/packages/pretty-format/src/plugins/html_element.js +++ b/packages/pretty-format/src/plugins/html_element.js @@ -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 ( @@ -93,7 +93,7 @@ function printAttributes( .join(''); } -const print = ( +export const print = ( element: HTMLElement | HTMLText | HTMLComment, print: Print, indent: Indent, @@ -155,4 +155,4 @@ const print = ( return result; }; -module.exports = ({print, test}: Plugin); +export default ({print, test}: Plugin); diff --git a/packages/pretty-format/src/plugins/immutable_list.js b/packages/pretty-format/src/plugins/immutable_list.js index 0cc3b9019e5b..e4d9cd0c41c3 100644 --- a/packages/pretty-format/src/plugins/immutable_list.js +++ b/packages/pretty-format/src/plugins/immutable_list.js @@ -19,9 +19,9 @@ 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, @@ -29,4 +29,4 @@ const print = ( colors: Colors, ) => printImmutable(val, print, indent, opts, colors, 'List', false); -module.exports = ({print, test}: Plugin); +export default ({print, test}: Plugin); diff --git a/packages/pretty-format/src/plugins/immutable_map.js b/packages/pretty-format/src/plugins/immutable_map.js index 0b55744ec388..7a9ebfb85e62 100644 --- a/packages/pretty-format/src/plugins/immutable_map.js +++ b/packages/pretty-format/src/plugins/immutable_map.js @@ -20,10 +20,10 @@ 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, @@ -31,4 +31,4 @@ const print = ( colors: Colors, ) => printImmutable(val, print, indent, opts, colors, 'Map', true); -module.exports = ({print, test}: Plugin); +export default ({print, test}: Plugin); diff --git a/packages/pretty-format/src/plugins/immutable_ordered_map.js b/packages/pretty-format/src/plugins/immutable_ordered_map.js index 7ceb2201bddf..212e0eba5889 100644 --- a/packages/pretty-format/src/plugins/immutable_ordered_map.js +++ b/packages/pretty-format/src/plugins/immutable_ordered_map.js @@ -20,10 +20,10 @@ 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, @@ -31,4 +31,4 @@ const print = ( colors: Colors, ) => printImmutable(val, print, indent, opts, colors, 'OrderedMap', true); -module.exports = ({print, test}: Plugin); +export default ({print, test}: Plugin); diff --git a/packages/pretty-format/src/plugins/immutable_ordered_set.js b/packages/pretty-format/src/plugins/immutable_ordered_set.js index a64be1e26ab5..cddc9d77b991 100644 --- a/packages/pretty-format/src/plugins/immutable_ordered_set.js +++ b/packages/pretty-format/src/plugins/immutable_ordered_set.js @@ -20,10 +20,10 @@ 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, @@ -31,4 +31,4 @@ const print = ( colors: Colors, ) => printImmutable(val, print, indent, opts, colors, 'OrderedSet', false); -module.exports = ({print, test}: Plugin); +export default ({print, test}: Plugin); diff --git a/packages/pretty-format/src/plugins/immutable_plugins.js b/packages/pretty-format/src/plugins/immutable_plugins.js index cd614fffef8d..57dada6ae192 100644 --- a/packages/pretty-format/src/plugins/immutable_plugins.js +++ b/packages/pretty-format/src/plugins/immutable_plugins.js @@ -16,7 +16,7 @@ import ImmutableOrderedSet from './immutable_ordered_set'; import ImmutableOrderedMap from './immutable_ordered_map'; import ImmutableRecord from './immutable_record'; -module.exports = [ +const plugins = [ ImmutableList, ImmutableSet, ImmutableMap, @@ -25,3 +25,6 @@ module.exports = [ ImmutableOrderedMap, ImmutableRecord, ]; + +module.exports = plugins; +export default plugins; diff --git a/packages/pretty-format/src/plugins/immutable_record.js b/packages/pretty-format/src/plugins/immutable_record.js index 15ade038896a..8a4de33e57ed 100644 --- a/packages/pretty-format/src/plugins/immutable_record.js +++ b/packages/pretty-format/src/plugins/immutable_record.js @@ -19,9 +19,10 @@ 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, @@ -29,4 +30,4 @@ const print = ( colors: Colors, ) => printImmutable(val, print, indent, opts, colors, 'Record', true); -module.exports = ({print, test}: Plugin); +export default ({print, test}: Plugin); diff --git a/packages/pretty-format/src/plugins/immutable_set.js b/packages/pretty-format/src/plugins/immutable_set.js index 3ec171c80c57..c5c66d94cc7d 100644 --- a/packages/pretty-format/src/plugins/immutable_set.js +++ b/packages/pretty-format/src/plugins/immutable_set.js @@ -20,10 +20,10 @@ 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, @@ -31,4 +31,4 @@ const print = ( colors: Colors, ) => printImmutable(val, print, indent, opts, colors, 'Set', false); -module.exports = ({print, test}: Plugin); +export default ({print, test}: Plugin); diff --git a/packages/pretty-format/src/plugins/immutable_stack.js b/packages/pretty-format/src/plugins/immutable_stack.js index 5f9a0ef4ad09..00aed6010ce0 100644 --- a/packages/pretty-format/src/plugins/immutable_stack.js +++ b/packages/pretty-format/src/plugins/immutable_stack.js @@ -19,9 +19,9 @@ 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, @@ -29,4 +29,4 @@ const print = ( colors: Colors, ) => printImmutable(val, print, indent, opts, colors, 'Stack', false); -module.exports = ({print, test}: Plugin); +export default ({print, test}: Plugin); diff --git a/packages/pretty-format/src/plugins/lib/escape_html.js b/packages/pretty-format/src/plugins/lib/escape_html.js index 6eb10d6f6049..bd37a76882f9 100644 --- a/packages/pretty-format/src/plugins/lib/escape_html.js +++ b/packages/pretty-format/src/plugins/lib/escape_html.js @@ -8,8 +8,6 @@ * @flow */ -function escapeHTML(str: string): string { +export default function escapeHTML(str: string): string { return str.replace(//g, '>'); } - -module.exports = escapeHTML; diff --git a/packages/pretty-format/src/plugins/lib/print_immutable.js b/packages/pretty-format/src/plugins/lib/print_immutable.js index 0cbe0b412ceb..8d9e5666583d 100644 --- a/packages/pretty-format/src/plugins/lib/print_immutable.js +++ b/packages/pretty-format/src/plugins/lib/print_immutable.js @@ -62,4 +62,4 @@ const printImmutable = ( ); }; -module.exports = printImmutable; +export default printImmutable; diff --git a/packages/pretty-format/src/plugins/react_element.js b/packages/pretty-format/src/plugins/react_element.js index 6f9d22f4155f..d4be69952fa5 100644 --- a/packages/pretty-format/src/plugins/react_element.js +++ b/packages/pretty-format/src/plugins/react_element.js @@ -73,7 +73,7 @@ function printProps(props, print, indent, colors, opts) { .join(''); } -const print = ( +export const print = ( element: React$Element<*>, print: Print, indent: Indent, @@ -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); diff --git a/packages/pretty-format/src/plugins/react_test_component.js b/packages/pretty-format/src/plugins/react_test_component.js index 11d48315d102..622cdd93b3ba 100644 --- a/packages/pretty-format/src/plugins/react_test_component.js +++ b/packages/pretty-format/src/plugins/react_test_component.js @@ -69,7 +69,7 @@ function printProps(props: Object, print, indent, colors, opts) { .join(''); } -const print = ( +export const print = ( instance: ReactTestObject, print: Print, indent: Indent, @@ -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);