From ee391e4818fc5f67f41e856cce285fd3c756cf8c Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Fri, 27 Mar 2020 00:41:54 -0400 Subject: [PATCH] (test): ensure Babel presets are merged and applied - regression test as there was previously a bug where only plugins were merged and presets would only be merged if your preset list included preset-env - this is the first test that adds any sort of preset - couldn't find a small preset that would be easy to test against, so made a tiny one locally that just does a simple replace with babel-plugin-replace-identifiers --- package.json | 1 + test/integration/fixtures/build-withBabel/.babelrc.js | 4 ++++ .../fixtures/build-withBabel/test-babel-preset.js | 4 ++++ test/integration/tsdx-build-withBabel.test.js | 9 +++++++++ yarn.lock | 5 +++++ 5 files changed, 23 insertions(+) create mode 100644 test/integration/fixtures/build-withBabel/test-babel-preset.js diff --git a/package.json b/package.json index cd56e952d..d731ada44 100644 --- a/package.json +++ b/package.json @@ -113,6 +113,7 @@ "@types/semver": "^7.1.0", "@types/styled-components": "^5.0.1", "autoprefixer": "^9.7.4", + "babel-plugin-replace-identifiers": "^0.1.1", "cssnano": "^4.1.10", "doctoc": "^1.4.0", "husky": "^4.2.2", diff --git a/test/integration/fixtures/build-withBabel/.babelrc.js b/test/integration/fixtures/build-withBabel/.babelrc.js index 05e08f2e8..06ede96cd 100644 --- a/test/integration/fixtures/build-withBabel/.babelrc.js +++ b/test/integration/fixtures/build-withBabel/.babelrc.js @@ -1,4 +1,8 @@ module.exports = { + presets: [ + // ensure Babel presets are merged and applied + './test-babel-preset' + ], plugins: [ 'styled-components', ['@babel/plugin-transform-runtime', { helpers: false }], diff --git a/test/integration/fixtures/build-withBabel/test-babel-preset.js b/test/integration/fixtures/build-withBabel/test-babel-preset.js new file mode 100644 index 000000000..e319c4f06 --- /dev/null +++ b/test/integration/fixtures/build-withBabel/test-babel-preset.js @@ -0,0 +1,4 @@ +// a simple babel preset to ensure presets are merged and applied +module.exports = () => ({ + plugins: [['replace-identifiers', { sum: 'replacedSum' }]], +}); diff --git a/test/integration/tsdx-build-withBabel.test.js b/test/integration/tsdx-build-withBabel.test.js index 518baff6a..cb2b3b59c 100644 --- a/test/integration/tsdx-build-withBabel.test.js +++ b/test/integration/tsdx-build-withBabel.test.js @@ -44,6 +44,15 @@ describe('integration :: tsdx build :: .babelrc.js', () => { expect(matched).toBeTruthy(); }); + it('should merge and apply presets', () => { + const output = execWithCache('node ../dist/index.js build'); + expect(output.code).toBe(0); + + // ensures replace-identifiers was used + const matched = grep(/replacedSum/, ['dist/build-withbabel.*.js']); + expect(matched).toBeTruthy(); + }); + it('should compile files into a dist directory', () => { const output = execWithCache('node ../dist/index.js build'); diff --git a/yarn.lock b/yarn.lock index 75115c3e8..97db7a4d8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1838,6 +1838,11 @@ babel-plugin-macros@^2.6.1: cosmiconfig "^6.0.0" resolve "^1.12.0" +babel-plugin-replace-identifiers@^0.1.1: + version "0.1.1" + resolved "https://registry.yarnpkg.com/babel-plugin-replace-identifiers/-/babel-plugin-replace-identifiers-0.1.1.tgz#38819617d814ab0e4b35cfa373e40758b359f68f" + integrity sha1-OIGWF9gUqw5LNc+jc+QHWLNZ9o8= + "babel-plugin-styled-components@>= 1": version "1.10.7" resolved "https://registry.yarnpkg.com/babel-plugin-styled-components/-/babel-plugin-styled-components-1.10.7.tgz#3494e77914e9989b33cc2d7b3b29527a949d635c"