Skip to content

Commit 1356486

Browse files
committed
(test): ensure a regenatorRuntime import is added
- 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?
1 parent 0c60110 commit 1356486

4 files changed

Lines changed: 14 additions & 1 deletion

File tree

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module.exports = {
22
plugins: [
3-
'styled-components'
3+
'styled-components',
4+
['@babel/plugin-transform-runtime', { helpers: false }],
45
]
56
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function* testGenerator() {
2+
return yield 'blah';
3+
}

test/integration/fixtures/build-withBabel/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import './styled.tsx';
22

3+
export { testGenerator } from './generator';
4+
35
export const sum = (a: number, b: number) => {
46
if ('development' === process.env.NODE_ENV) {
57
console.log('fuck');

test/integration/tsdx-build-withBabel.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ describe('integration :: tsdx build :: .babelrc.js', () => {
3232
expect(output.code).toBe(1);
3333
});
3434

35+
it('should add an import of regeneratorRuntime', () => {
36+
const output = shell.grep(/@babel\/runtime\/regenerator/, [
37+
'dist/build-withbabel.*.js',
38+
]);
39+
expect(output.code).toBe(0);
40+
});
41+
3542
it('should compile files into a dist directory', () => {
3643
expect(shell.test('-f', 'dist/index.js')).toBeTruthy();
3744
expect(

0 commit comments

Comments
 (0)