From 96ce05f4007e8022b0ba1a5a00982954f3ac3081 Mon Sep 17 00:00:00 2001 From: Eitan Peer Date: Thu, 25 May 2017 13:36:01 +0300 Subject: [PATCH 1/2] Use static string when checking Transfomration type Fixes https://github.com/cloudinary/cloudinary-react/issues/13 --- .gitignore | 4 ++- package.json | 1 + .../CloudinaryComponent.js | 2 +- .../Transformation/Transformation.js | 2 ++ test/ProdTest.js | 32 +++++++++++++++++++ webpack.config.test.js | 6 ++++ 6 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 test/ProdTest.js create mode 100644 webpack.config.test.js diff --git a/.gitignore b/.gitignore index ee2dc1d..cef43d2 100644 --- a/.gitignore +++ b/.gitignore @@ -41,4 +41,6 @@ lib/ dist/ *-compiled.js* storybook-static/ -.storybook/ \ No newline at end of file +.storybook/ + +test-prod/ \ No newline at end of file diff --git a/package.json b/package.json index 0a89e1a..9697a3e 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "Present Cloudinary images and videos using React components", "main": "lib/index.js", "scripts": { + "pretest": "node_modules/.bin/webpack --config webpack.config.test.js -p", "test": "node_modules/.bin/mocha test/.setup.js --recursive test", "compile": "node_modules/.bin/babel src -d lib && cd src && find . -name package.json -exec cp --parents '{}' ../lib \\; -print", "dist": "node_modules/.bin/webpack", diff --git a/src/components/CloudinaryComponent/CloudinaryComponent.js b/src/components/CloudinaryComponent/CloudinaryComponent.js index e45d771..b4086ea 100644 --- a/src/components/CloudinaryComponent/CloudinaryComponent.js +++ b/src/components/CloudinaryComponent/CloudinaryComponent.js @@ -26,7 +26,7 @@ class CloudinaryComponent extends Component { if(children === undefined || children === null) return null; let mapped = React.Children.map(children, child =>{ let options = {}; - if (child.type && child.type.name === "Transformation"){ + if (child.type && child.type._displayName === "Transformation"){ options = CloudinaryComponent.normalizeOptions(child.props, child.context); } let childOptions = this.getChildTransformations(child.props.children); diff --git a/src/components/Transformation/Transformation.js b/src/components/Transformation/Transformation.js index 994b470..d39bcc2 100644 --- a/src/components/Transformation/Transformation.js +++ b/src/components/Transformation/Transformation.js @@ -5,6 +5,8 @@ import CloudinaryComponent from '../CloudinaryComponent'; * Define a transformation that is applied to the parent tag. */ class Transformation extends CloudinaryComponent { + static _displayName = "Transformation"; + constructor(props) { super(props); } diff --git a/test/ProdTest.js b/test/ProdTest.js new file mode 100644 index 0000000..36029ec --- /dev/null +++ b/test/ProdTest.js @@ -0,0 +1,32 @@ +import React from 'react'; +import ReactDOMServer from 'react-dom/server'; +import * as cloudinary from 'cloudinary-core'; +import * as cloudinaryReact from '../test-prod/cloudinary-react.js'; +import { expect } from 'chai'; + +describe('Image', () => { + beforeEach(() => { + + }); + it('Loads the production SDK', function() { + let Image = cloudinaryReact.Image; + expect(Image).to.be.ok; + }); + it('Renders an image', function() { + let Image = cloudinaryReact.Image; + const img = ReactDOMServer.renderToString( + + + ); + expect(img).to.contain('src="http://res.cloudinary.com/demo/image/upload/sample"'); + }); + it('Renders an image with a transformation', function() { + let Image = cloudinaryReact.Image; + const img = ReactDOMServer.renderToString( + + + + ); + expect(img).to.contain('src="http://res.cloudinary.com/demo/image/upload/c_scale,w_200/sample"'); + }); +}); \ No newline at end of file diff --git a/webpack.config.test.js b/webpack.config.test.js new file mode 100644 index 0000000..ebe57b2 --- /dev/null +++ b/webpack.config.test.js @@ -0,0 +1,6 @@ +// Override Webpack configurations for running tests over the production Webpack build +const config = require('./webpack.config'); +config.output.path = 'test-prod'; +config.externals['cloudinary-core'] = 'cloudinary-core'; + +module.exports = config; \ No newline at end of file From 945ea488d666ddbef4b56fd648164e3de5c65ea1 Mon Sep 17 00:00:00 2001 From: Eitan Peer Date: Thu, 25 May 2017 14:41:29 +0300 Subject: [PATCH 2/2] Update react external for test --- webpack.config.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/webpack.config.test.js b/webpack.config.test.js index ebe57b2..f43e937 100644 --- a/webpack.config.test.js +++ b/webpack.config.test.js @@ -2,5 +2,6 @@ const config = require('./webpack.config'); config.output.path = 'test-prod'; config.externals['cloudinary-core'] = 'cloudinary-core'; +config.externals['react'] = 'react'; module.exports = config; \ No newline at end of file