diff --git a/package.json b/package.json index b91db48ca253..c52ff646e01b 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "flow-bin": "^0.39.0", "glob": "^7.1.1", "graceful-fs": "^4.1.11", + "immutable": "^3.8.1", "istanbul-api": "^1.1.0", "istanbul-lib-coverage": "^1.0.0", "jasmine-reporters": "^2.2.0", @@ -30,8 +31,7 @@ "react-test-renderer": "^15.4.1", "rimraf": "^2.5.4", "strip-ansi": "^3.0.1", - "typescript": "^2.1.4", - "immutable": "^3.8.1" + "typescript": "^2.1.4" }, "scripts": { "build-clean": "rm -rf ./packages/*/build", diff --git a/packages/pretty-format/src/__tests__/ImmutablePlugins-test.js b/packages/pretty-format/src/__tests__/ImmutablePlugins-test.js index 04dcbf02fff7..0d9f0fc8b7a2 100644 --- a/packages/pretty-format/src/__tests__/ImmutablePlugins-test.js +++ b/packages/pretty-format/src/__tests__/ImmutablePlugins-test.js @@ -63,7 +63,7 @@ describe('Immutable.OrderedSet plugin', () => { it('supports multiple string elements {min: false}', () => { assertImmutableObject( Immutable.OrderedSet(['jhon', 'mike', 'cristian']), - 'Immutable.OrderedSet [\n "jhon",\n "mike",\n "cristian",\n]' + 'Immutable.OrderedSet [\n "jhon",\n "mike",\n "cristian"\n]' ); }); @@ -78,7 +78,7 @@ describe('Immutable.OrderedSet plugin', () => { it('supports multiple integer elements {min: false}', () => { assertImmutableObject( Immutable.OrderedSet([1, 2, 3]), - 'Immutable.OrderedSet [\n 1,\n 2,\n 3,\n]' + 'Immutable.OrderedSet [\n 1,\n 2,\n 3\n]' ); }); @@ -93,7 +93,7 @@ describe('Immutable.OrderedSet plugin', () => { it('supports object elements {min: false}', () => { assertImmutableObject( Immutable.OrderedSet([{a: 1, b: 2, c: 3}]), - 'Immutable.OrderedSet [\n Object {\n \"a\": 1,\n \"b\": 2,\n \"c\": 3,\n },\n]' + 'Immutable.OrderedSet [\n Object {\n \"a\": 1,\n \"b\": 2,\n \"c\": 3,\n }\n]' ); }); @@ -110,7 +110,7 @@ describe('Immutable.OrderedSet plugin', () => { const reactComponent = React.createElement('Mouse', null, 'Hello World'); assertImmutableObject( Immutable.OrderedSet([reactComponent, reactComponent]), - 'Immutable.OrderedSet [\n \n Hello World\n ,\n]' + 'Immutable.OrderedSet [\n \n Hello World\n \n]' ); }); }); @@ -151,7 +151,7 @@ describe('Immutable.List plugin', () => { it('supports multiple string elements {min: false}', () => { assertImmutableObject( Immutable.List(['jhon', 'mike', 'cristian']), - 'Immutable.List [\n "jhon",\n "mike",\n "cristian",\n]' + 'Immutable.List [\n "jhon",\n "mike",\n "cristian"\n]' ); }); @@ -166,7 +166,7 @@ describe('Immutable.List plugin', () => { it('supports multiple integer elements {min: false}', () => { assertImmutableObject( Immutable.List([1, 2, 3]), - 'Immutable.List [\n 1,\n 2,\n 3,\n]' + 'Immutable.List [\n 1,\n 2,\n 3\n]' ); }); @@ -181,7 +181,7 @@ describe('Immutable.List plugin', () => { it('supports object elements {min: false}', () => { assertImmutableObject( Immutable.List([{a: 1, b: 2, c: 3}]), - 'Immutable.List [\n Object {\n \"a\": 1,\n \"b\": 2,\n \"c\": 3,\n },\n]' + 'Immutable.List [\n Object {\n \"a\": 1,\n \"b\": 2,\n \"c\": 3,\n }\n]' ); }); @@ -198,7 +198,7 @@ describe('Immutable.List plugin', () => { const reactComponent = React.createElement('Mouse', null, 'Hello World'); assertImmutableObject( Immutable.List([reactComponent, reactComponent]), - 'Immutable.List [\n \n Hello World\n ,\n \n Hello World\n ,\n]' + 'Immutable.List [\n \n Hello World\n ,\n \n Hello World\n \n]' ); }); }); @@ -239,7 +239,7 @@ describe('Immutable.Stack plugin', () => { it('supports multiple string elements {min: false}', () => { assertImmutableObject( Immutable.Stack(['jhon', 'mike', 'cristian']), - 'Immutable.Stack [\n "jhon",\n "mike",\n "cristian",\n]' + 'Immutable.Stack [\n "jhon",\n "mike",\n "cristian"\n]' ); }); @@ -254,7 +254,7 @@ describe('Immutable.Stack plugin', () => { it('supports multiple integer elements {min: false}', () => { assertImmutableObject( Immutable.Stack([1, 2, 3]), - 'Immutable.Stack [\n 1,\n 2,\n 3,\n]' + 'Immutable.Stack [\n 1,\n 2,\n 3\n]' ); }); @@ -269,7 +269,7 @@ describe('Immutable.Stack plugin', () => { it('supports object elements {min: false}', () => { assertImmutableObject( Immutable.Stack([{a: 1, b: 2, c: 3}]), - 'Immutable.Stack [\n Object {\n \"a\": 1,\n \"b\": 2,\n \"c\": 3,\n },\n]' + 'Immutable.Stack [\n Object {\n \"a\": 1,\n \"b\": 2,\n \"c\": 3,\n }\n]' ); }); @@ -286,7 +286,7 @@ describe('Immutable.Stack plugin', () => { const reactComponent = React.createElement('Mouse', null, 'Hello World'); assertImmutableObject( Immutable.Stack([reactComponent, reactComponent]), - 'Immutable.Stack [\n \n Hello World\n ,\n \n Hello World\n ,\n]' + 'Immutable.Stack [\n \n Hello World\n ,\n \n Hello World\n \n]' ); }); }); @@ -327,7 +327,7 @@ describe('Immutable.Set plugin', () => { it('supports multiple string elements {min: false}', () => { assertImmutableObject( Immutable.Set(['jhon', 'mike', 'cristian']), - 'Immutable.Set [\n "jhon",\n "mike",\n "cristian",\n]' + 'Immutable.Set [\n "jhon",\n "mike",\n "cristian"\n]' ); }); @@ -342,7 +342,7 @@ describe('Immutable.Set plugin', () => { it('supports multiple integer elements {min: false}', () => { assertImmutableObject( Immutable.Set([1, 2, 3]), - 'Immutable.Set [\n 1,\n 2,\n 3,\n]' + 'Immutable.Set [\n 1,\n 2,\n 3\n]' ); }); @@ -357,7 +357,7 @@ describe('Immutable.Set plugin', () => { it('supports object elements {min: false}', () => { assertImmutableObject( Immutable.Set([{a: 1, b: 2, c: 3}]), - 'Immutable.Set [\n Object {\n \"a\": 1,\n \"b\": 2,\n \"c\": 3,\n },\n]' + 'Immutable.Set [\n Object {\n \"a\": 1,\n \"b\": 2,\n \"c\": 3,\n }\n]' ); }); @@ -374,7 +374,7 @@ describe('Immutable.Set plugin', () => { const reactComponent = React.createElement('Mouse', null, 'Hello World'); assertImmutableObject( Immutable.Set([reactComponent, reactComponent]), - 'Immutable.Set [\n \n Hello World\n ,\n]' + 'Immutable.Set [\n \n Hello World\n \n]' ); }); }); @@ -407,7 +407,7 @@ describe('Immutable.Map plugin', () => { it('supports an object with multiple keys {min: false}', () => { assertImmutableObject( Immutable.Map({a: 1, b: 2, c: 3}), - 'Immutable.Map {\n a: 1,\n b: 2,\n c: 3,\n}' + 'Immutable.Map {\n a: 1,\n b: 2,\n c: 3\n}' ); }); @@ -422,7 +422,7 @@ describe('Immutable.Map plugin', () => { it('supports object elements {min: false}', () => { assertImmutableObject( Immutable.Map({key: {a: 1, b: 2, c: 3}}), - 'Immutable.Map {\n key: Object {\n \"a\": 1,\n \"b\": 2,\n \"c\": 3,\n },\n}' + 'Immutable.Map {\n key: Object {\n \"a\": 1,\n \"b\": 2,\n \"c\": 3,\n }\n}' ); }); @@ -439,7 +439,7 @@ describe('Immutable.Map plugin', () => { const reactComponent = React.createElement('Mouse', null, 'Hello World'); assertImmutableObject( Immutable.Map({a: reactComponent, b: reactComponent}), - 'Immutable.Map {\n a: \n Hello World\n ,\n b: \n Hello World\n ,\n}' + 'Immutable.Map {\n a: \n Hello World\n ,\n b: \n Hello World\n \n}' ); }); }); @@ -472,7 +472,7 @@ describe('Immutable.OrderedMap plugin', () => { it('supports an object with multiple keys {min: false}', () => { assertImmutableObject( Immutable.OrderedMap({a: 1, b: 2, c: 3}), - 'Immutable.OrderedMap {\n a: 1,\n b: 2,\n c: 3,\n}' + 'Immutable.OrderedMap {\n a: 1,\n b: 2,\n c: 3\n}' ); }); @@ -487,7 +487,7 @@ describe('Immutable.OrderedMap plugin', () => { it('supports object elements {min: false}', () => { assertImmutableObject( Immutable.OrderedMap({key: {a: 1, b: 2, c: 3}}), - 'Immutable.OrderedMap {\n key: Object {\n \"a\": 1,\n \"b\": 2,\n \"c\": 3,\n },\n}' + 'Immutable.OrderedMap {\n key: Object {\n \"a\": 1,\n \"b\": 2,\n \"c\": 3,\n }\n}' ); }); @@ -504,7 +504,7 @@ describe('Immutable.OrderedMap plugin', () => { const reactComponent = React.createElement('Mouse', null, 'Hello World'); assertImmutableObject( Immutable.OrderedMap({a: reactComponent, b: reactComponent}), - 'Immutable.OrderedMap {\n a: \n Hello World\n ,\n b: \n Hello World\n ,\n}' + 'Immutable.OrderedMap {\n a: \n Hello World\n ,\n b: \n Hello World\n \n}' ); }); }); diff --git a/packages/pretty-format/src/plugins/ImmutableList.js b/packages/pretty-format/src/plugins/ImmutableList.js index 654d1a7a783b..69854ceb4a6a 100644 --- a/packages/pretty-format/src/plugins/ImmutableList.js +++ b/packages/pretty-format/src/plugins/ImmutableList.js @@ -16,7 +16,9 @@ const isList = (maybeList: Object) => { return !!(maybeList && maybeList[IS_LIST_SENTINEL]); }; -const printImmutableList = ( +const test = (object: Object) => object && isList(object); + +const print = ( val: Object, print: Function, indent: Function, @@ -26,7 +28,4 @@ const printImmutableList = ( return printImmutable(val, print, indent, opts, colors, 'List', false); }; -module.exports = { - print: printImmutableList, - test: (object: Object) => object && isList(object), -}; +module.exports = {print, test}; diff --git a/packages/pretty-format/src/plugins/ImmutableMap.js b/packages/pretty-format/src/plugins/ImmutableMap.js index 798d2706b8ed..092b0b630b75 100644 --- a/packages/pretty-format/src/plugins/ImmutableMap.js +++ b/packages/pretty-format/src/plugins/ImmutableMap.js @@ -16,7 +16,9 @@ const isMap = (maybeMap: Object) => { return !!(maybeMap && maybeMap[IS_MAP_SENTINEL]); }; -const printImmutableMap = ( +const test = (object: Object) => object && isMap(object); + +const print = ( val: Object, print: Function, indent: Function, @@ -26,7 +28,4 @@ const printImmutableMap = ( return printImmutable(val, print, indent, opts, colors, 'Map', true); }; -module.exports = { - print: printImmutableMap, - test: (object: Object) => object && isMap(object), -}; +module.exports = {print, test}; diff --git a/packages/pretty-format/src/plugins/ImmutableOrderedMap.js b/packages/pretty-format/src/plugins/ImmutableOrderedMap.js index a94e87abf5c3..6f01ee9cc23f 100644 --- a/packages/pretty-format/src/plugins/ImmutableOrderedMap.js +++ b/packages/pretty-format/src/plugins/ImmutableOrderedMap.js @@ -25,7 +25,9 @@ const isOrderedMap = (maybeOrderedMap: Object) => { return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap); }; -const printImmutableOrderedMap = ( +const test = (object: Object) => object && isOrderedMap(object); + +const print = ( val: Object, print: Function, indent: Function, @@ -35,7 +37,4 @@ const printImmutableOrderedMap = ( return printImmutable(val, print, indent, opts, colors, 'OrderedMap', true); }; -module.exports = { - print: printImmutableOrderedMap, - test: (object: Object) => object && isOrderedMap(object), -}; +module.exports = {print, test}; diff --git a/packages/pretty-format/src/plugins/ImmutableOrderedSet.js b/packages/pretty-format/src/plugins/ImmutableOrderedSet.js index 87117f5d23e2..3b158bc85ef7 100644 --- a/packages/pretty-format/src/plugins/ImmutableOrderedSet.js +++ b/packages/pretty-format/src/plugins/ImmutableOrderedSet.js @@ -25,7 +25,9 @@ const isOrderedSet = (maybeOrderedSet: Object) => { return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet); }; -const printImmutableOrderedSet = ( +const test = (object: Object) => object && isOrderedSet(object); + +const print = ( val: Object, print: Function, indent: Function, @@ -35,7 +37,4 @@ const printImmutableOrderedSet = ( return printImmutable(val, print, indent, opts, colors, 'OrderedSet', false); }; -module.exports = { - print: printImmutableOrderedSet, - test: (object: Object) => object && isOrderedSet(object), -}; +module.exports = {print, test}; diff --git a/packages/pretty-format/src/plugins/ImmutableSet.js b/packages/pretty-format/src/plugins/ImmutableSet.js index c23a72650003..f9222c83ae63 100644 --- a/packages/pretty-format/src/plugins/ImmutableSet.js +++ b/packages/pretty-format/src/plugins/ImmutableSet.js @@ -16,7 +16,9 @@ const isSet = (maybeSet: Object) => { return !!(maybeSet && maybeSet[IS_SET_SENTINEL]); }; -const printImmutableSet = ( +const test = (object: Object) => object && isSet(object); + +const print = ( val: Object, print: Function, indent: Function, @@ -26,7 +28,4 @@ const printImmutableSet = ( return printImmutable(val, print, indent, opts, colors, 'Set', false); }; -module.exports = { - print: printImmutableSet, - test: (object: Object) => object && isSet(object), -}; +module.exports = {print, test}; diff --git a/packages/pretty-format/src/plugins/ImmutableStack.js b/packages/pretty-format/src/plugins/ImmutableStack.js index 0897007757a0..be13c944fc2e 100644 --- a/packages/pretty-format/src/plugins/ImmutableStack.js +++ b/packages/pretty-format/src/plugins/ImmutableStack.js @@ -16,7 +16,9 @@ const isStack = (maybeStack: Object) => { return !!(maybeStack && maybeStack[IS_STACK_SENTINEL]); }; -const printImmutableStack = ( +const test = (object: Object) => object && isStack(object); + +const print = ( val: Object, print: Function, indent: Function, @@ -26,7 +28,4 @@ const printImmutableStack = ( return printImmutable(val, print, indent, opts, colors, 'Stack', false); }; -module.exports = { - print: printImmutableStack, - test: (object: Object) => object && isStack(object), -}; +module.exports = {print, test}; diff --git a/packages/pretty-format/src/plugins/printImmutable.js b/packages/pretty-format/src/plugins/printImmutable.js index 42d9754cb329..67cb22e0e45e 100644 --- a/packages/pretty-format/src/plugins/printImmutable.js +++ b/packages/pretty-format/src/plugins/printImmutable.js @@ -25,28 +25,21 @@ const printImmutable = ( immutableDataStructureName: string, isMap: boolean, ) : string => { - let result = IMMUTABLE_NAMESPACE + immutableDataStructureName; const openTag = isMap ? '{' : '['; const closeTag = isMap ? '}' : ']'; - - if (val.isEmpty()) { - return result + SPACE + openTag + closeTag; - } + let result = IMMUTABLE_NAMESPACE + immutableDataStructureName + + SPACE + openTag + opts.edgeSpacing; - result += SPACE + openTag + opts.edgeSpacing; + const immutableArray = []; val.forEach((item: any, key: any) => { - result += indent( - addKey(isMap, key) + print(item, print, indent, opts, colors) - ) + ',' + opts.spacing; + immutableArray.push( + indent(addKey(isMap, key) + print(item, print, indent, opts, colors)) + ); }); - if (opts.min) { - //remove last comma and last spacing - return result.slice(0, -2) + opts.edgeSpacing + closeTag; - } else { - //remove last spacing - return result.slice(0, -1) + opts.edgeSpacing + closeTag; - } + result += immutableArray.join(',' + opts.spacing); + + return result + opts.edgeSpacing + closeTag; }; module.exports = printImmutable;