Skip to content

Commit

Permalink
Add es5 build of pretty-format (#4075)
Browse files Browse the repository at this point in the history
  • Loading branch information
skovhus authored and cpojer committed Jul 20, 2017
1 parent 5938079 commit c784bfa
Show file tree
Hide file tree
Showing 18 changed files with 55 additions and 47 deletions.
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);
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);

0 comments on commit c784bfa

Please sign in to comment.