Skip to content

Commit

Permalink
(test): ensure Babel presets are merged and applied
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
agilgur5 committed Mar 27, 2020
1 parent 9f559fa commit ee391e4
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions 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 }],
Expand Down
@@ -0,0 +1,4 @@
// a simple babel preset to ensure presets are merged and applied
module.exports = () => ({
plugins: [['replace-identifiers', { sum: 'replacedSum' }]],
});
9 changes: 9 additions & 0 deletions test/integration/tsdx-build-withBabel.test.js
Expand Up @@ -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');

Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Expand Up @@ -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"
Expand Down

0 comments on commit ee391e4

Please sign in to comment.