Skip to content
Permalink
Browse files

Add support for web worker global (rollup#50)

  • Loading branch information...
calvinmetcalf committed Mar 14, 2016
1 parent 3b22781 commit 66d12cf91a627152d6d7631d4df66b7a53c87af0
Showing with 17 additions and 5 deletions.
  1. +1 −1 src/index.js
  2. +16 −4 test/test.js
@@ -230,7 +230,7 @@ export default function commonjs ( options = {} ) {
var intros = [];

if ( bundleUsesGlobal ) {
intros.push( `var __commonjs_global = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : this;` );
intros.push( `var __commonjs_global = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}` );
}

if ( bundleRequiresWrappers ) {
@@ -126,12 +126,24 @@ describe( 'rollup-plugin-commonjs', () => {
format: 'cjs'
});

let window = {};
let mockWindow = {};
let mockGlobal = {};
let mockSelf = {};

const fn = new Function ( 'window', 'module', generated.code );
fn( window, {} );
const fn = new Function ( 'module', 'window', 'global', 'self', generated.code );

fn( {}, mockWindow, mockGlobal, mockSelf);
assert.equal( mockWindow.foo, 'bar', generated.code );
assert.equal( mockGlobal.foo, undefined, generated.code );
assert.equal( mockSelf.foo, undefined, generated.code );

fn( {}, undefined, mockGlobal, mockSelf );
assert.equal( mockGlobal.foo, 'bar', generated.code );
assert.equal( mockSelf.foo, undefined, generated.code );

fn( {}, undefined, undefined, mockSelf );
assert.equal( mockSelf.foo, 'bar', generated.code );

assert.equal( window.foo, 'bar', generated.code );
});
});

0 comments on commit 66d12cf

Please sign in to comment.
You can’t perform that action at this time.