Skip to content

Commit

Permalink
(test): ensure a regenatorRuntime import is added
Browse files Browse the repository at this point in the history
- when using transform-runtime with helpers: false, it should import
  from @babel/runtime/regenerator
- either this plugin configured like this or a direct import of
  regenerator in one's own library code is the only way to get it to
  be imported
  - just using a generator will make regenerator code added, but
    without any import (leading to a ReferenceError)
  - TODO: make it easier or automatic to use generators
    - useBuiltIns of preset-env?
  • Loading branch information
agilgur5 committed Mar 25, 2020
1 parent c1cc03a commit ac7d235
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion test/integration/fixtures/build-withBabel/.babelrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
plugins: [
'styled-components'
'styled-components',
['@babel/plugin-transform-runtime', { helpers: false }],
]
}
3 changes: 3 additions & 0 deletions test/integration/fixtures/build-withBabel/src/generator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function* testGenerator() {
return yield 'blah';
}
2 changes: 2 additions & 0 deletions test/integration/fixtures/build-withBabel/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export { Title } from './styled';

export { testGenerator } from './generator';

export const sum = (a: number, b: number) => {
if ('development' === process.env.NODE_ENV) {
console.log('fuck');
Expand Down
7 changes: 7 additions & 0 deletions test/integration/tsdx-build-withBabel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ describe('integration :: tsdx build :: .babelrc.js', () => {
expect(output.code).toBe(1);
});

it('should add an import of regeneratorRuntime', () => {
const output = shell.grep(/@babel\/runtime\/regenerator/, [
'dist/build-withbabel.*.js',
]);
expect(output.code).toBe(0);
});

it('should compile files into a dist directory', () => {
expect(shell.test('-f', 'dist/index.js')).toBeTruthy();
expect(
Expand Down

0 comments on commit ac7d235

Please sign in to comment.