From 9764fbfbd0294a4e736f1bf21517f88c57ff1f29 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Thu, 19 Mar 2020 02:42:22 -0400 Subject: [PATCH] (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? --- test/integration/fixtures/build-withBabel/.babelrc.js | 3 ++- test/integration/fixtures/build-withBabel/src/generator.ts | 3 +++ test/integration/fixtures/build-withBabel/src/index.ts | 2 ++ test/integration/tsdx-build-withBabel.test.js | 7 +++++++ 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 test/integration/fixtures/build-withBabel/src/generator.ts diff --git a/test/integration/fixtures/build-withBabel/.babelrc.js b/test/integration/fixtures/build-withBabel/.babelrc.js index 21782b135..05e08f2e8 100644 --- a/test/integration/fixtures/build-withBabel/.babelrc.js +++ b/test/integration/fixtures/build-withBabel/.babelrc.js @@ -1,5 +1,6 @@ module.exports = { plugins: [ - 'styled-components' + 'styled-components', + ['@babel/plugin-transform-runtime', { helpers: false }], ] } diff --git a/test/integration/fixtures/build-withBabel/src/generator.ts b/test/integration/fixtures/build-withBabel/src/generator.ts new file mode 100644 index 000000000..aedb252e5 --- /dev/null +++ b/test/integration/fixtures/build-withBabel/src/generator.ts @@ -0,0 +1,3 @@ +export function* testGenerator() { + return yield 'blah'; +} diff --git a/test/integration/fixtures/build-withBabel/src/index.ts b/test/integration/fixtures/build-withBabel/src/index.ts index f0887b014..345066424 100644 --- a/test/integration/fixtures/build-withBabel/src/index.ts +++ b/test/integration/fixtures/build-withBabel/src/index.ts @@ -1,5 +1,7 @@ import './styled.tsx'; +export { testGenerator } from './generator'; + export const sum = (a: number, b: number) => { if ('development' === process.env.NODE_ENV) { console.log('fuck'); diff --git a/test/integration/tsdx-build-withBabel.test.js b/test/integration/tsdx-build-withBabel.test.js index 45c70227b..72b93a1aa 100644 --- a/test/integration/tsdx-build-withBabel.test.js +++ b/test/integration/tsdx-build-withBabel.test.js @@ -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(