From e78928a0e3a6c80503576ecb2bd66ed400aef2a0 Mon Sep 17 00:00:00 2001 From: Nima Date: Fri, 26 Oct 2018 16:02:57 +1300 Subject: [PATCH 1/7] add tests for named-asset-imports plugin --- .../babel-plugin-named-asset-import/.babelrc | 3 ++ .../.npmignore | 2 + .../index.spec.js | 38 +++++++++++++++++++ .../package.json | 11 ++++++ 4 files changed, 54 insertions(+) create mode 100644 packages/babel-plugin-named-asset-import/.babelrc create mode 100644 packages/babel-plugin-named-asset-import/.npmignore create mode 100644 packages/babel-plugin-named-asset-import/index.spec.js diff --git a/packages/babel-plugin-named-asset-import/.babelrc b/packages/babel-plugin-named-asset-import/.babelrc new file mode 100644 index 00000000000..8aa924d7c6c --- /dev/null +++ b/packages/babel-plugin-named-asset-import/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["@babel/preset-env"] +} \ No newline at end of file diff --git a/packages/babel-plugin-named-asset-import/.npmignore b/packages/babel-plugin-named-asset-import/.npmignore new file mode 100644 index 00000000000..7fb6d1e4358 --- /dev/null +++ b/packages/babel-plugin-named-asset-import/.npmignore @@ -0,0 +1,2 @@ +*.spec.js +.babelrc diff --git a/packages/babel-plugin-named-asset-import/index.spec.js b/packages/babel-plugin-named-asset-import/index.spec.js new file mode 100644 index 00000000000..c55ec6da9ad --- /dev/null +++ b/packages/babel-plugin-named-asset-import/index.spec.js @@ -0,0 +1,38 @@ +import pluginTester from 'babel-plugin-tester'; +import namedAssetImport from './index'; + +pluginTester({ + plugin: namedAssetImport, + pluginOptions: { + loaderMap: { + svg: { + ReactComponent: '@svgr/webpack?-prettier,-svgo![path]', + }, + }, + }, + pluginName: 'named-asset-import', + snapshot: false, + tests: { + defaultImport: { + code: 'import foo from "foo";', + output: 'import foo from "foo";', + }, + namedImport: { + code: 'import { foo } from "foo";', + output: 'import { foo } from "foo";', + }, + namedImportRenamed: { + code: 'import { foo as foo1 } from "foo.svg";', + output: 'import { foo as foo1 } from "foo.svg";', + }, + svgNamedImport: { + code: 'import { Url as foo1 } from "foo.svg";', + output: 'import { Url as foo1 } from "foo.svg";', + }, + svgReactComponentNamedImport: { + code: 'import { ReactComponent as foo1 } from "foo.svg";', + output: + 'import { ReactComponent as foo1 } from "@svgr/webpack?-prettier,-svgo!foo.svg";', + }, + }, +}); diff --git a/packages/babel-plugin-named-asset-import/package.json b/packages/babel-plugin-named-asset-import/package.json index 0640abd5675..88ce9908b20 100644 --- a/packages/babel-plugin-named-asset-import/package.json +++ b/packages/babel-plugin-named-asset-import/package.json @@ -13,5 +13,16 @@ ], "peerDependencies": { "@babel/core": "^7.1.0" + }, + "devDependencies": { + "@babel/preset-env": "^7.1.0", + "babel-core": "^7.0.0-bridge.0", + "babel-jest": "^23.6.0", + "babel-plugin-tester": "^5.5.1", + "jest": "^23.6.0", + "regenerator-runtime": "^0.12.1" + }, + "scripts": { + "test": "jest" } } From fc8b25b1a93d1dfdcbae3e32eb74738b79ede266 Mon Sep 17 00:00:00 2001 From: Nima Date: Mon, 29 Oct 2018 12:18:10 +1300 Subject: [PATCH 2/7] add ticketFormats store/saga --- .../index.spec.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/babel-plugin-named-asset-import/index.spec.js b/packages/babel-plugin-named-asset-import/index.spec.js index c55ec6da9ad..7ffc3ce52e8 100644 --- a/packages/babel-plugin-named-asset-import/index.spec.js +++ b/packages/babel-plugin-named-asset-import/index.spec.js @@ -34,5 +34,27 @@ pluginTester({ output: 'import { ReactComponent as foo1 } from "@svgr/webpack?-prettier,-svgo!foo.svg";', }, + + defaultExport: { + code: 'export * from "foo";', + output: 'export * from "foo";', + }, + namedExport: { + code: 'export { foo } from "foo";', + output: 'export { foo } from "foo";', + }, + namedExportRenamed: { + code: 'export { foo as foo1 } from "foo.svg";', + output: 'export { foo as foo1 } from "foo.svg";', + }, + svgNamedExport: { + code: 'export { Url as foo1 } from "foo.svg";', + output: 'export { Url as foo1 } from "foo.svg";', + }, + svgReactComponentNamedExport: { + code: 'export { ReactComponent as foo1 } from "foo.svg";', + output: + 'export { ReactComponent as foo1 } from "@svgr/webpack?-prettier,-svgo!foo.svg";', + }, }, }); From 3af34d539a0de072354dc15d2fcf4a111dd570ca Mon Sep 17 00:00:00 2001 From: Nima Date: Wed, 31 Oct 2018 19:28:37 +1300 Subject: [PATCH 3/7] change import to require on test file to avoid using babel when running tests --- packages/babel-plugin-named-asset-import/index.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/babel-plugin-named-asset-import/index.spec.js b/packages/babel-plugin-named-asset-import/index.spec.js index 7ffc3ce52e8..efb03a07250 100644 --- a/packages/babel-plugin-named-asset-import/index.spec.js +++ b/packages/babel-plugin-named-asset-import/index.spec.js @@ -1,5 +1,5 @@ -import pluginTester from 'babel-plugin-tester'; -import namedAssetImport from './index'; +const pluginTester = require('babel-plugin-tester'); +const namedAssetImport = require('./index'); pluginTester({ plugin: namedAssetImport, From 7f89098ffe97bf282b54092365ff503b4537da53 Mon Sep 17 00:00:00 2001 From: Nima Date: Wed, 31 Oct 2018 19:31:37 +1300 Subject: [PATCH 4/7] remove all babel dependencies as not needed more for running tests --- packages/babel-plugin-named-asset-import/.babelrc | 3 --- packages/babel-plugin-named-asset-import/package.json | 6 +----- 2 files changed, 1 insertion(+), 8 deletions(-) delete mode 100644 packages/babel-plugin-named-asset-import/.babelrc diff --git a/packages/babel-plugin-named-asset-import/.babelrc b/packages/babel-plugin-named-asset-import/.babelrc deleted file mode 100644 index 8aa924d7c6c..00000000000 --- a/packages/babel-plugin-named-asset-import/.babelrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "presets": ["@babel/preset-env"] -} \ No newline at end of file diff --git a/packages/babel-plugin-named-asset-import/package.json b/packages/babel-plugin-named-asset-import/package.json index 88ce9908b20..2ffd327d1b1 100644 --- a/packages/babel-plugin-named-asset-import/package.json +++ b/packages/babel-plugin-named-asset-import/package.json @@ -15,12 +15,8 @@ "@babel/core": "^7.1.0" }, "devDependencies": { - "@babel/preset-env": "^7.1.0", - "babel-core": "^7.0.0-bridge.0", - "babel-jest": "^23.6.0", "babel-plugin-tester": "^5.5.1", - "jest": "^23.6.0", - "regenerator-runtime": "^0.12.1" + "jest": "^23.6.0" }, "scripts": { "test": "jest" From 148d8281b302e31340e9c0f006b8e87d1f7851af Mon Sep 17 00:00:00 2001 From: Nima Date: Wed, 31 Oct 2018 19:53:46 +1300 Subject: [PATCH 5/7] update tests and rename file to index.test.js --- .../index.spec.js | 60 ------------------- .../index.test.js | 50 ++++++++++++++++ 2 files changed, 50 insertions(+), 60 deletions(-) delete mode 100644 packages/babel-plugin-named-asset-import/index.spec.js create mode 100644 packages/babel-plugin-named-asset-import/index.test.js diff --git a/packages/babel-plugin-named-asset-import/index.spec.js b/packages/babel-plugin-named-asset-import/index.spec.js deleted file mode 100644 index efb03a07250..00000000000 --- a/packages/babel-plugin-named-asset-import/index.spec.js +++ /dev/null @@ -1,60 +0,0 @@ -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 foo from "foo";', - output: 'import foo from "foo";', - }, - namedImport: { - code: 'import { foo } from "foo";', - output: 'import { foo } from "foo";', - }, - namedImportRenamed: { - code: 'import { foo as foo1 } from "foo.svg";', - output: 'import { foo as foo1 } from "foo.svg";', - }, - svgNamedImport: { - code: 'import { Url as foo1 } from "foo.svg";', - output: 'import { Url as foo1 } from "foo.svg";', - }, - svgReactComponentNamedImport: { - code: 'import { ReactComponent as foo1 } from "foo.svg";', - output: - 'import { ReactComponent as foo1 } from "@svgr/webpack?-prettier,-svgo!foo.svg";', - }, - - defaultExport: { - code: 'export * from "foo";', - output: 'export * from "foo";', - }, - namedExport: { - code: 'export { foo } from "foo";', - output: 'export { foo } from "foo";', - }, - namedExportRenamed: { - code: 'export { foo as foo1 } from "foo.svg";', - output: 'export { foo as foo1 } from "foo.svg";', - }, - svgNamedExport: { - code: 'export { Url as foo1 } from "foo.svg";', - output: 'export { Url as foo1 } from "foo.svg";', - }, - svgReactComponentNamedExport: { - code: 'export { ReactComponent as foo1 } from "foo.svg";', - output: - 'export { ReactComponent as foo1 } from "@svgr/webpack?-prettier,-svgo!foo.svg";', - }, - }, -}); 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";', + }, + }, +}); From d6c7d36adb07b85b3c6f7002408bc9e802ad1dda Mon Sep 17 00:00:00 2001 From: Nima Date: Wed, 31 Oct 2018 20:04:11 +1300 Subject: [PATCH 6/7] remove npmignore as it is whitelisted in package.json --- packages/babel-plugin-named-asset-import/.npmignore | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 packages/babel-plugin-named-asset-import/.npmignore diff --git a/packages/babel-plugin-named-asset-import/.npmignore b/packages/babel-plugin-named-asset-import/.npmignore deleted file mode 100644 index 7fb6d1e4358..00000000000 --- a/packages/babel-plugin-named-asset-import/.npmignore +++ /dev/null @@ -1,2 +0,0 @@ -*.spec.js -.babelrc From e2c4115d9f8aef56be8ddb42a8ba0f6ae0f06611 Mon Sep 17 00:00:00 2001 From: Nima Date: Thu, 1 Nov 2018 08:50:09 +1300 Subject: [PATCH 7/7] add babel-plugin-named-asset-import tests to e2e --- tasks/e2e-simple.sh | 4 ++++ 1 file changed, 4 insertions(+) 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 ../..