diff --git a/test/function/define-is-undefined/foo.js b/test/function/define-is-undefined/foo.js new file mode 100644 index 0000000..f1417a1 --- /dev/null +++ b/test/function/define-is-undefined/foo.js @@ -0,0 +1,9 @@ +(function (global, factory) { + typeof define === 'function' && define.amd ? define(factory) : + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + (global.foo = factory()); +}(this, (function () { 'use strict'; + + return 42; + +}))); diff --git a/test/function/define-is-undefined/main.js b/test/function/define-is-undefined/main.js new file mode 100644 index 0000000..c01e9a1 --- /dev/null +++ b/test/function/define-is-undefined/main.js @@ -0,0 +1,3 @@ +import foo from './foo.js'; + +assert.equal( foo, 42 ); diff --git a/test/test.js b/test/test.js index fb7ea17..d22c1af 100644 --- a/test/test.js +++ b/test/test.js @@ -345,5 +345,19 @@ describe( 'rollup-plugin-commonjs', () => { ] }).then( executeBundle ); }); + + it( 'rewrites top-level defines', () => { + return rollup({ + entry: 'samples/define-is-undefined/main.js', + plugins: [ commonjs() ] + }) + .then( bundle => { + executeBundle( bundle, { + define () { + throw new Error( 'nope' ); + } + }); + }); + }); }); });