diff --git a/packages/babel-plugin-named-asset-import/index.test.js b/packages/babel-plugin-named-asset-import/index.test.js new file mode 100644 index 00000000000..65ad5513e3e --- /dev/null +++ b/packages/babel-plugin-named-asset-import/index.test.js @@ -0,0 +1,50 @@ +const pluginTester = require('babel-plugin-tester'); +const namedAssetImport = require('./index'); + +pluginTester({ + plugin: namedAssetImport, + pluginOptions: { + loaderMap: { + svg: { + ReactComponent: '@svgr/webpack?-prettier,-svgo![path]', + }, + }, + }, + pluginName: 'named-asset-import', + snapshot: false, + tests: { + defaultImport: { + code: 'import logo from "logo";', + output: 'import logo from "logo";', + }, + namedImport: { + code: 'import { logo } from "logo";', + output: 'import { logo } from "logo";', + }, + namedImportRenamed: { + code: 'import { Url as logo1 } from "logo";', + output: 'import { Url as logo1 } from "logo";', + }, + svgDefaultImport: { + code: 'import logo from "logo.svg";', + output: 'import logo from "logo.svg";', + }, + svgNamedImport: { + code: 'import { logo } from "logo.svg";', + output: 'import { logo } from "logo.svg";', + }, + svgReactComponentNamedImport: { + code: 'import { ReactComponent as logo } from "logo.svg";', + output: + 'import { ReactComponent as logo } from "@svgr/webpack?-prettier,-svgo!logo.svg";', + }, + svgMultipleImport: { + code: + 'import logo, { logoUrl , ReactComponent as Logo } from "logo.svg";', + output: + 'import logo from "logo.svg";\n' + + 'import { logoUrl } from "logo.svg";\n' + + 'import { ReactComponent as Logo } from "@svgr/webpack?-prettier,-svgo!logo.svg";', + }, + }, +}); diff --git a/packages/babel-plugin-named-asset-import/package.json b/packages/babel-plugin-named-asset-import/package.json index 0640abd5675..2ffd327d1b1 100644 --- a/packages/babel-plugin-named-asset-import/package.json +++ b/packages/babel-plugin-named-asset-import/package.json @@ -13,5 +13,12 @@ ], "peerDependencies": { "@babel/core": "^7.1.0" + }, + "devDependencies": { + "babel-plugin-tester": "^5.5.1", + "jest": "^23.6.0" + }, + "scripts": { + "test": "jest" } } diff --git a/tasks/e2e-simple.sh b/tasks/e2e-simple.sh index ce3324ab43f..c2fc89530a1 100755 --- a/tasks/e2e-simple.sh +++ b/tasks/e2e-simple.sh @@ -118,6 +118,10 @@ cd packages/react-dev-utils/ yarn test cd ../.. +cd packages/babel-plugin-named-asset-import/ +yarn test +cd ../.. + cd packages/confusing-browser-globals/ yarn test cd ../..