From 8629649b977587934f5bfb14f36d0ef53bf72547 Mon Sep 17 00:00:00 2001 From: Moti Zilberman Date: Wed, 13 Apr 2016 16:16:55 +0300 Subject: [PATCH 01/12] Add infrastructure for easy direct testing of SVG output (Run bootstrap-tests.js with e.g. babel-node to generate a new fixtures.js) --- __tests__/fixtures.js | 10 +++++ __tests__/graphical-tests.js | 14 +++++++ bootstrap-tests.js | 78 ++++++++++++++++++++++++++++++++++++ package.json | 2 + 4 files changed, 104 insertions(+) create mode 100644 __tests__/fixtures.js create mode 100644 __tests__/graphical-tests.js create mode 100644 bootstrap-tests.js diff --git a/__tests__/fixtures.js b/__tests__/fixtures.js new file mode 100644 index 0000000..dc37dbc --- /dev/null +++ b/__tests__/fixtures.js @@ -0,0 +1,10 @@ +// This file is auto-updated by ../bootstrap-tests.js + +import React from 'react'; +import {Sparklines, SparklinesLine} from '../src/Sparklines'; + +export default { +// AUTO-GENERATED PART STARTS HERE + 'SimpleLine': {jsx: (), svg: ''} +// AUTO-GENERATED PART ENDS HERE +}; \ No newline at end of file diff --git a/__tests__/graphical-tests.js b/__tests__/graphical-tests.js new file mode 100644 index 0000000..c47125c --- /dev/null +++ b/__tests__/graphical-tests.js @@ -0,0 +1,14 @@ +import fixtures from './fixtures'; +import {render} from 'enzyme'; +import { expect } from 'chai'; + +describe('Graphical tests from fixtures.js', function() { + for (let key of Object.keys(fixtures)) { + describe(`${key}`, function() { + it('should render as specified', function() { + const wrapper = render(fixtures[key].jsx); + expect(wrapper.html()).to.eq(fixtures[key].svg); + }); + }); + } +}); diff --git a/bootstrap-tests.js b/bootstrap-tests.js new file mode 100644 index 0000000..57f221b --- /dev/null +++ b/bootstrap-tests.js @@ -0,0 +1,78 @@ +import path from 'path'; +import {render} from 'enzyme'; +import LineByLineReader from 'line-by-line'; +import reactElementToJsx from 'react-element-to-jsx-string'; + +const fixturesFile = path.resolve(__dirname, './__tests__/fixtures.js'); +const dynamicPartStartSignal = '// AUTO-GENERATED PART STARTS HERE'; +const dynamicPartEndSignal = '// AUTO-GENERATED PART ENDS HERE'; + +const fixtures = require(fixturesFile).default; + +// Output control +let outData = ''; +const write = content => { outData += content + '\n'; } +const save = () => console.log(outData); +function writeFixtures() { + for (let key of Object.keys(fixtures)) { + const jsx = fixtures[key].jsx; + const wrapper = render(jsx); + const jsxCode = `(${toOneLine(reactElementToJsx(jsx))})`; + const htmlCode = JSON.stringify(wrapper.html()); + + write(`\t${JSON.stringify(key)}: {jsx: ${jsxCode}, html: ${htmlCode}},`); + } +} +function toOneLine(code) { + return code.replace(/\s*[\r\n]\s*/g, ' ').replace(/\s+/g, ' '); +} + +// Input control +const lr = new LineByLineReader(fixturesFile, {skipEmptyLines: false}); +let inDynamicPart = false, dynamicPartCount = 0, lineCount = 0; + +lr.on('line', line => { + ++lineCount; + if (line === dynamicPartStartSignal) { + if (inDynamicPart) + throw new LineError('Dynamic part opened again'); + ++dynamicPartCount; + if (dynamicPartCount > 1) + throw new LineError('Multiple dynamic parts found'); + inDynamicPart = true; + write(line); + try { + writeFixtures(); + } catch(e) { + throw new LineError(e); + } + } + else if (line === dynamicPartEndSignal) { + if (!inDynamicPart) + throw new LineError('Dynamic part closed again'); + inDynamicPart = false; + write(line); + } + else if (!inDynamicPart) + write(line); +}); + +lr.on('end', () => { + if (inDynamicPart) { + throw new LineError('Dynamic part not closed'); + } + if (!dynamicPartCount) { + throw new LineError('No dynamic part found in file!'); + } + save(); +}); + +lr.on('error', function (err) { + throw new LineError(err); +}); + +class LineError extends Error { + constructor(message) { + super(`${fixturesFile}:${lineCount}: ${message}`); + } +} \ No newline at end of file diff --git a/package.json b/package.json index f01c185..fec8ccb 100644 --- a/package.json +++ b/package.json @@ -43,8 +43,10 @@ "chai": "^3.5.0", "enzyme": "^2.1.0", "jsdom": "^8.1.0", + "line-by-line": "^0.1.4", "mocha": "^2.4.5", "react-addons-test-utils": "^0.14.7", + "react-element-to-jsx-string": "^2.5.0", "webpack": "^2.1.0-beta.4", "webpack-dev-server": "^2.0.0-beta" }, From 1b9c149752037989b0c6d18b14db87e9cc089bcf Mon Sep 17 00:00:00 2001 From: Moti Zilberman Date: Wed, 13 Apr 2016 16:19:25 +0300 Subject: [PATCH 02/12] Write directly to fixture.js at end of bootstrap-tests.js --- bootstrap-tests.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bootstrap-tests.js b/bootstrap-tests.js index 57f221b..2d1b282 100644 --- a/bootstrap-tests.js +++ b/bootstrap-tests.js @@ -2,6 +2,7 @@ import path from 'path'; import {render} from 'enzyme'; import LineByLineReader from 'line-by-line'; import reactElementToJsx from 'react-element-to-jsx-string'; +import {writeFileSync} from 'fs'; const fixturesFile = path.resolve(__dirname, './__tests__/fixtures.js'); const dynamicPartStartSignal = '// AUTO-GENERATED PART STARTS HERE'; @@ -12,7 +13,7 @@ const fixtures = require(fixturesFile).default; // Output control let outData = ''; const write = content => { outData += content + '\n'; } -const save = () => console.log(outData); +const save = () => writeFileSync(fixturesFile, outData); function writeFixtures() { for (let key of Object.keys(fixtures)) { const jsx = fixtures[key].jsx; From e29bcbb59a7d8be7fbe708eac00be7e2d27a7c06 Mon Sep 17 00:00:00 2001 From: Moti Zilberman Date: Wed, 13 Apr 2016 16:34:02 +0300 Subject: [PATCH 03/12] Work around JSX parsing quirk triggered by bootstrap-tests's output --- bootstrap-tests.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bootstrap-tests.js b/bootstrap-tests.js index 2d1b282..946eb01 100644 --- a/bootstrap-tests.js +++ b/bootstrap-tests.js @@ -18,14 +18,14 @@ function writeFixtures() { for (let key of Object.keys(fixtures)) { const jsx = fixtures[key].jsx; const wrapper = render(jsx); - const jsxCode = `(${toOneLine(reactElementToJsx(jsx))})`; + const jsxCode = `(${markupToOneLine(reactElementToJsx(jsx))})`; const htmlCode = JSON.stringify(wrapper.html()); - write(`\t${JSON.stringify(key)}: {jsx: ${jsxCode}, html: ${htmlCode}},`); + write(`\t${JSON.stringify(key)}: {jsx: ${jsxCode}, svg: ${htmlCode}},`); } } -function toOneLine(code) { - return code.replace(/\s*[\r\n]\s*/g, ' ').replace(/\s+/g, ' '); +function markupToOneLine(code) { + return code.replace(/\s*[\r\n]\s*/g, ' ').replace(/\s+/g, ' ').replace(/\s*([<>])\s*/g, '$1'); } // Input control From 2e8ec9cd58c7cf77e8af21747c7d8f7b425a9054 Mon Sep 17 00:00:00 2001 From: Moti Zilberman Date: Wed, 13 Apr 2016 16:34:42 +0300 Subject: [PATCH 04/12] Add an auto-generated, passing, fixtures.js --- __tests__/fixtures.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/__tests__/fixtures.js b/__tests__/fixtures.js index dc37dbc..aa4fd31 100644 --- a/__tests__/fixtures.js +++ b/__tests__/fixtures.js @@ -5,6 +5,6 @@ import {Sparklines, SparklinesLine} from '../src/Sparklines'; export default { // AUTO-GENERATED PART STARTS HERE - 'SimpleLine': {jsx: (), svg: ''} + "SimpleLine": {jsx: (), svg: ""}, // AUTO-GENERATED PART ENDS HERE -}; \ No newline at end of file +}; From e4d164fe301620d7384071b445b40f517e034952 Mon Sep 17 00:00:00 2001 From: Moti Zilberman Date: Wed, 13 Apr 2016 18:12:59 +0300 Subject: [PATCH 05/12] Use hiff to compare SVG output to fixtures Importantly, we normalize property order in the SVG style attribute before comparing, to avoid spurious errors on essentially identical images. A side benefit is nicer error messages on test failures. --- __tests__/compareSvg.js | 23 +++++++++++++++++++++++ __tests__/graphical-tests.js | 21 ++++++++++++--------- package.json | 1 + 3 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 __tests__/compareSvg.js diff --git a/__tests__/compareSvg.js b/__tests__/compareSvg.js new file mode 100644 index 0000000..8a1f7e1 --- /dev/null +++ b/__tests__/compareSvg.js @@ -0,0 +1,23 @@ +import hiff from 'hiff'; + +function normalizeStyle(style) { + style = (style || '').split(';').map(s => s.trim()); + style.sort(); + return style.join(';'); +} + +function normalizeAttrs(...$ns) { + for (let $n of $ns) { + if ($n.attr('style')) + $n.attr('style', normalizeStyle($n.attr('style'))); + } +} + +function comparatorFn($n1, $n2, childChanges) { + normalizeAttrs($n1, $n2); + return hiff.defaultTagComparisonFn($n1, $n2, childChanges); +} + +export default function compareSvg(svg1, svg2, options = {}) { + return hiff.compare(svg1, svg2, Object.assign({}, options, {tagComparison: comparatorFn})); +} diff --git a/__tests__/graphical-tests.js b/__tests__/graphical-tests.js index c47125c..6dd5878 100644 --- a/__tests__/graphical-tests.js +++ b/__tests__/graphical-tests.js @@ -1,14 +1,17 @@ import fixtures from './fixtures'; import {render} from 'enzyme'; import { expect } from 'chai'; +import compareSvg from './compareSvg'; describe('Graphical tests from fixtures.js', function() { - for (let key of Object.keys(fixtures)) { - describe(`${key}`, function() { - it('should render as specified', function() { - const wrapper = render(fixtures[key].jsx); - expect(wrapper.html()).to.eq(fixtures[key].svg); - }); - }); - } -}); + for (let key of Object.keys(fixtures)) { + describe(`${key}`, function() { + it('should render as specified', function() { + const wrapper = render(fixtures[key].jsx); + const result = compareSvg(wrapper.html(), fixtures[key].svg); + const errorMessage = 'SVG output changed:\n' + result.changes.map(change => change.message).join('\n') + '\n'; + expect(result.changes, errorMessage).to.be.empty; + }); + }); + } +}); \ No newline at end of file diff --git a/package.json b/package.json index fec8ccb..6c27b0f 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "babel-runtime": "^6.6.1", "chai": "^3.5.0", "enzyme": "^2.1.0", + "hiff": "^0.3.0", "jsdom": "^8.1.0", "line-by-line": "^0.1.4", "mocha": "^2.4.5", From bf7209ca40e2f34413433ff89bcd8083f8300377 Mon Sep 17 00:00:00 2001 From: Moti Zilberman Date: Wed, 13 Apr 2016 18:13:46 +0300 Subject: [PATCH 06/12] Add informative header to bootstrap-tests.js --- bootstrap-tests.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bootstrap-tests.js b/bootstrap-tests.js index 946eb01..29d5de1 100644 --- a/bootstrap-tests.js +++ b/bootstrap-tests.js @@ -1,3 +1,13 @@ +// bootstrap-tests.js - A tool for updating the test cases in __tests__/fixtures.js +// +// 1) Reads __tests__/fixtures.js and looks for a "dynamic part", which should be a list of fields +// belonging to that file's default export, enclosed in a pair of markers (see "signal" constants +// below). +// 2) Imports the same fixtures file and (re-)renders each ReactElement to a static SVG string. +// 3) On success, overwrites __tests__/fixtures.js with an updated copy. +// +// Run with babel-node or similar. + import path from 'path'; import {render} from 'enzyme'; import LineByLineReader from 'line-by-line'; From e787d2bbc06aece9ccd8f6473b94a0341c225ad6 Mon Sep 17 00:00:00 2001 From: Moti Zilberman Date: Wed, 13 Apr 2016 18:15:04 +0300 Subject: [PATCH 07/12] Add graphical test fixtures based on demo.js --- __tests__/data.json | 67 +++++++++++++++++++++++++++++++++++++++++++ __tests__/fixtures.js | 36 +++++++++++++++++++++-- 2 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 __tests__/data.json diff --git a/__tests__/data.json b/__tests__/data.json new file mode 100644 index 0000000..02de8e4 --- /dev/null +++ b/__tests__/data.json @@ -0,0 +1,67 @@ +{ + "sampleData": [0.26789611283279424, -1.5618808743590797, -0.46848826820269196, -0.02429709108986638, -0.07347501430506465, + 0.938722048681125, -0.02488170176918398, + 0.014511315562131895, -1.0920317808493079, -1.6226651458214956, + 0.6777968350341455, -1.0989601025670448, + 1.402853678778828, -1.7923422052616966, -0.37025235972161835, -0.10254054014867667, + 0.3709902985604339, + 2.5285657626539253, -0.18958673659343403, + 0.8578243085059141, + 1.7395812075504404, + 0.9723534409914075, -0.6799757002898873, + 1.153081489500828, + 1.3851189843556257, + 0.19355625368483506, + 1.262069965103209, -0.8628137671385424, -0.6118030618030503, -0.25257403618789087 + ], + "sampleData100": [-0.2809926205121489, + 0.5993223086924007, + 0.5450586119753267, -0.4794107823559421, -0.18298272472350668, + 0.3219712568468161, + 2.0566174540438324, -1.6442809970641576, + 1.971025186834513, + 0.37237930811331116, -0.4015753275277232, + 1.0601229819271032, -2.0983317267366988, + 0.26835584955818786, -0.2899975217753408, -0.6342464890422705, -0.10975205424415876, + 0.39583180670735013, + 1.4695948548213784, -1.2295606440627673, + 1.0056333434310312, + 1.006402733277956, -1.4092655719724325, + 0.17595701557726026, -0.19396518917878047, -1.4314174397644206, -0.34402041741926476, + 0.6986827111240516, -0.6157663396302129, + 1.0606864486721386, + 1.3537300165741912, -0.9521291296713654, -1.089926042595364, -0.9723342804049446, + 0.2286317959508994, + 0.2613862542298905, + 0.24840731355644413, + 2.08064561830636, + 0.44534855831763426, + 1.5511436162779393, -1.5514313805901196, -0.7497893094776009, + 0.4027674242193654, -0.38986316786208264, -1.2167765233154504, + 0.18879490542570268, -1.5284852088503573, + 0.8789559275619153, -1.2451506359938267, -0.7226040247250638, -0.07157034383583998, + 1.9901707247581082, + 0.22166972734467405, + 0.058080839429433054, -0.6324465858010533, -0.8091687560181702, -1.293296284426419, + 1.8436776591711028, -0.28314101700652944, + 1.358988312176975, -0.1152691343859452, -2.425199332455914, + 0.6696100792204956, + 1.7308347028588733, -0.9997610678433961, -0.10106296722138419, + 0.3157348177184432, -0.34931234065268996, + 0.4662049447935582, + 0.8793589099345607, + 2.069923608446714, + 1.3861543531394107, -0.2705101572065443, + 0.5980871990258989, -0.5871146157743545, -0.9844080263005216, + 0.2972697252124295, -0.6119868603373193, -1.8902200290484288, + 0.6996282188319667, -0.24883654266800448, -0.1156025389007573, + 1.0370156630612894, + 0.9750054921585302, -0.635000984672242, + 0.16076716404020402, + 0.1379262931648021, -0.6838899322825195, + 0.6088591150304701, -0.3408579041001186, -0.08790701313160872, -0.38412257182424137, -1.3319278452946857, + 0.7154759857504911, -2.8727571205730915, -1.3501468729225303, -0.0865770144109483, + 0.505651174224522, -2.2111682240498753, + 2.035381345199811 + ] +} \ No newline at end of file diff --git a/__tests__/fixtures.js b/__tests__/fixtures.js index aa4fd31..f178336 100644 --- a/__tests__/fixtures.js +++ b/__tests__/fixtures.js @@ -1,10 +1,42 @@ // This file is auto-updated by ../bootstrap-tests.js import React from 'react'; -import {Sparklines, SparklinesLine} from '../src/Sparklines'; +import { Sparklines, SparklinesBars, SparklinesLine, SparklinesCurve, SparklinesNormalBand, SparklinesReferenceLine, SparklinesSpots } from '../src/Sparklines'; +import { sampleData, sampleData100 } from './data.json'; export default { // AUTO-GENERATED PART STARTS HERE - "SimpleLine": {jsx: (), svg: ""}, + "Header": {jsx: (), svg: ""}, + "Simple": {jsx: (), svg: ""}, + "SimpleCurve": {jsx: (), svg: ""}, + "Customizable1": {jsx: (), svg: ""}, + "Customizable2": {jsx: (), svg: ""}, + "Customizable3": {jsx: (), svg: ""}, + "Customizable4": {jsx: (), svg: ""}, + "Customizable5": {jsx: (), svg: ""}, + "Customizable6": {jsx: (), svg: ""}, + "Bounds1": {jsx: (), svg: ""}, + "Spots1": {jsx: (), svg: ""}, + "Spots2": {jsx: (), svg: ""}, + "Spots3": {jsx: (), svg: ""}, + "Bars1": {jsx: (), svg: ""}, + "Bars2": {jsx: (), svg: ""}, + "ReferenceLine1": {jsx: (), svg: ""}, + "ReferenceLine2": {jsx: (), svg: ""}, + "ReferenceLine3": {jsx: (), svg: ""}, + "ReferenceLine4": {jsx: (), svg: ""}, + "ReferenceLine5": {jsx: (), svg: ""}, + "ReferenceLine6": {jsx: (), svg: ""}, + "NormalBand1": {jsx: (), svg: ""}, + "NormalBand2": {jsx: (), svg: ""}, + "RealWorld1": {jsx: (), svg: ""}, + "RealWorld2": {jsx: (), svg: ""}, + "RealWorld3": {jsx: (), svg: ""}, + "RealWorld4": {jsx: (), svg: ""}, + "RealWorld5": {jsx: (), svg: ""}, + "RealWorld6": {jsx: (), svg: ""}, + "RealWorld7": {jsx: (), svg: ""}, + "RealWorld8": {jsx: (), svg: ""}, + "RealWorld9": {jsx: (), svg: ""}, // AUTO-GENERATED PART ENDS HERE }; From 598caaf052bac1bb9ce3cfd996c2bd1e288f8ef7 Mon Sep 17 00:00:00 2001 From: Moti Zilberman Date: Wed, 13 Apr 2016 18:16:25 +0300 Subject: [PATCH 08/12] Detect references to sampleData etc when generating test fixtures & replace with var name --- bootstrap-tests.js | 19 +++++++++++++++++-- package.json | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/bootstrap-tests.js b/bootstrap-tests.js index 29d5de1..abf98e1 100644 --- a/bootstrap-tests.js +++ b/bootstrap-tests.js @@ -13,6 +13,8 @@ import {render} from 'enzyme'; import LineByLineReader from 'line-by-line'; import reactElementToJsx from 'react-element-to-jsx-string'; import {writeFileSync} from 'fs'; +import replaceAll from 'replaceall'; +import React from 'react'; const fixturesFile = path.resolve(__dirname, './__tests__/fixtures.js'); const dynamicPartStartSignal = '// AUTO-GENERATED PART STARTS HERE'; @@ -20,6 +22,17 @@ const dynamicPartEndSignal = '// AUTO-GENERATED PART ENDS HERE'; const fixtures = require(fixturesFile).default; +// Handle recurring data constants +import {sampleData, sampleData100} from './__tests__/data.json'; +const recognizedDataConstants = { + sampleData, sampleData100 +}; +const recognizedDataStrings = {}; +for (let dataKey of Object.keys(recognizedDataConstants)) { + recognizedDataStrings[dataKey] = markupToOneLine(reactElementToJsx(
) + .replace(/[^{]*\{|\}[^}]*/g, '')); +} + // Output control let outData = ''; const write = content => { outData += content + '\n'; } @@ -28,9 +41,11 @@ function writeFixtures() { for (let key of Object.keys(fixtures)) { const jsx = fixtures[key].jsx; const wrapper = render(jsx); - const jsxCode = `(${markupToOneLine(reactElementToJsx(jsx))})`; + let jsxCode = `(${markupToOneLine(reactElementToJsx(jsx))})`; const htmlCode = JSON.stringify(wrapper.html()); - + for (let dataKey of Object.keys(recognizedDataStrings)) { + jsxCode = replaceAll(recognizedDataStrings[dataKey], dataKey, jsxCode); + } write(`\t${JSON.stringify(key)}: {jsx: ${jsxCode}, svg: ${htmlCode}},`); } } diff --git a/package.json b/package.json index 6c27b0f..0e94da1 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "mocha": "^2.4.5", "react-addons-test-utils": "^0.14.7", "react-element-to-jsx-string": "^2.5.0", + "replaceall": "^0.1.6", "webpack": "^2.1.0-beta.4", "webpack-dev-server": "^2.0.0-beta" }, From 1d6eb06c09eece002a28752a3d9af4376b778305 Mon Sep 17 00:00:00 2001 From: Moti Zilberman Date: Wed, 13 Apr 2016 18:22:27 +0300 Subject: [PATCH 09/12] Add test:bootstrap npm script -> bootstrap-tests.js --- bootstrap-tests.js | 2 +- package.json | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bootstrap-tests.js b/bootstrap-tests.js index abf98e1..10cd82a 100644 --- a/bootstrap-tests.js +++ b/bootstrap-tests.js @@ -6,7 +6,7 @@ // 2) Imports the same fixtures file and (re-)renders each ReactElement to a static SVG string. // 3) On success, overwrites __tests__/fixtures.js with an updated copy. // -// Run with babel-node or similar. +// Run with babel-node or using "npm run test:bootstrap". import path from 'path'; import {render} from 'enzyme'; diff --git a/package.json b/package.json index 0e94da1..1855faa 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "test": "mocha --compilers js:babel-core/register __tests__", "test:watch": "mocha --compilers js:babel-core/register --watch __tests__", "compile": "webpack", - "prepublish": "npm run compile" + "prepublish": "npm run compile", + "test:bootstrap": "node -r babel-core/register bootstrap-tests.js" }, "repository": { "type": "git", From a530df1f93b1f2e619e65f5cf93a7f017da9a59c Mon Sep 17 00:00:00 2001 From: Moti Zilberman Date: Wed, 13 Apr 2016 18:42:10 +0300 Subject: [PATCH 10/12] Peg react-element-to-jsx-string version to exactly 2.5.0 bootstrap-tests.js relies on the particulars of this module's string formatting behavior, so let's be defensive here. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1855faa..ccff7b2 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "line-by-line": "^0.1.4", "mocha": "^2.4.5", "react-addons-test-utils": "^0.14.7", - "react-element-to-jsx-string": "^2.5.0", + "react-element-to-jsx-string": "=2.5.0", "replaceall": "^0.1.6", "webpack": "^2.1.0-beta.4", "webpack-dev-server": "^2.0.0-beta" From 5c63238d3f231ebbeeffa52fc702c09d18ae92ce Mon Sep 17 00:00:00 2001 From: Moti Zilberman Date: Wed, 13 Apr 2016 19:01:58 +0300 Subject: [PATCH 11/12] Configure travis to use npm@3 and node@{0.12, 4, 5} This remove the unused dependency on jsdom (enzyme's `mount`), which requires node@>=4. --- .travis.yml | 3 +++ __tests__/Sparklines.js | 4 ---- package.json | 3 ++- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5b1fd1c..4cc1689 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,8 @@ language: node_js +before_install: npm install -g npm@3 script: travis_retry npm test node_js: - '0.12' +- '4' +- '5' sudo: false diff --git a/__tests__/Sparklines.js b/__tests__/Sparklines.js index 6324124..1b2e173 100644 --- a/__tests__/Sparklines.js +++ b/__tests__/Sparklines.js @@ -3,10 +3,6 @@ import ReactDOM from 'react-dom'; import { shallow } from 'enzyme'; import { expect } from 'chai'; import { Sparklines } from '../src/Sparklines'; -import jsdom from 'jsdom' - -global.document = jsdom.jsdom(''); -global.window = document.parentWindow; describe('Sparklines', () => { it('does not throw without any parameters', () => { diff --git a/package.json b/package.json index f01c185..a98ede9 100644 --- a/package.json +++ b/package.json @@ -42,9 +42,10 @@ "babel-runtime": "^6.6.1", "chai": "^3.5.0", "enzyme": "^2.1.0", - "jsdom": "^8.1.0", "mocha": "^2.4.5", "react-addons-test-utils": "^0.14.7", + "react": "^0.14.7", + "react-dom": "^0.14.7", "webpack": "^2.1.0-beta.4", "webpack-dev-server": "^2.0.0-beta" }, From ee13bf274e2554e211381413fea04f51686a9a57 Mon Sep 17 00:00:00 2001 From: Moti Zilberman Date: Wed, 13 Apr 2016 20:14:29 +0300 Subject: [PATCH 12/12] Add transform-object-assign to .babelrc -> support Node 0.12 --- .babelrc | 3 +++ package.json | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.babelrc b/.babelrc index e9d2f4d..5436124 100644 --- a/.babelrc +++ b/.babelrc @@ -4,5 +4,8 @@ "es2015", "stage-1" ], + "plugins": [ + "transform-object-assign" + ], "sourceMaps": true, } \ No newline at end of file diff --git a/package.json b/package.json index 182c836..ff26803 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "babel": "^6.5.2", "babel-core": "^6.7.2", "babel-loader": "^6.2.4", + "babel-plugin-transform-object-assign": "^6.5.0", "babel-preset-es2015": "^6.6.0", "babel-preset-react": "^6.5.0", "babel-preset-stage-1": "^6.5.0", @@ -46,10 +47,10 @@ "hiff": "^0.3.0", "line-by-line": "^0.1.4", "mocha": "^2.4.5", - "react-addons-test-utils": "^0.14.7", "react": "^0.14.7", - "react-element-to-jsx-string": "=2.5.0", + "react-addons-test-utils": "^0.14.7", "react-dom": "^0.14.7", + "react-element-to-jsx-string": "=2.5.0", "replaceall": "^0.1.6", "webpack": "^2.1.0-beta.4", "webpack-dev-server": "^2.0.0-beta"