Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tests for named-asset-imports plugin #5575

Merged
merged 8 commits into from
Oct 31, 2018
50 changes: 50 additions & 0 deletions packages/babel-plugin-named-asset-import/index.test.js
Original file line number Diff line number Diff line change
@@ -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";',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason these don't include the file name? Why not import logo from 'logo.svg';?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first 3 tests are testing cases when file extension does NOT match to plugin config (.svg in here),
and rest can cover tests when imported file extension matches to config

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

svgDefaultImport covers default import of logo.svg

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";',
},
},
});
7 changes: 7 additions & 0 deletions packages/babel-plugin-named-asset-import/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,12 @@
],
"peerDependencies": {
"@babel/core": "^7.1.0"
},
"devDependencies": {
"babel-plugin-tester": "^5.5.1",
"jest": "^23.6.0"
},
"scripts": {
"test": "jest"
}
}
4 changes: 4 additions & 0 deletions tasks/e2e-simple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ cd packages/react-dev-utils/
yarn test
cd ../..

cd packages/babel-plugin-named-asset-import/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Timer tests run as part of e2e

yarn test
cd ../..

cd packages/confusing-browser-globals/
yarn test
cd ../..
Expand Down