-
-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathshim-exports-define-window.js
63 lines (50 loc) · 1.94 KB
/
shim-exports-define-window.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use strict';
/*jshint asi: true */
var browserify_version = require('./utils/browserify-version');
var browserify = require('browserify')
, test = require('tap').test
, vm = require('vm')
, proxyquire = require('proxyquire')
;
var file = require.resolve('./fixtures/shims/lib-with-exports-define-global-problem.js');
var entry = require.resolve('./fixtures/entry-requires-lib-with-global-problem.js');
// More explanation about the issue reproduced by this test inside the fixture itself
function runBundle(fullPaths, cb) {
function resolveShims (file_, msgs, cb) {
var res = file_ === file
? { exports: 'eve' }
: null;
setTimeout(cb.bind(null, null, { shim: res }), 0)
}
var shim = proxyquire('../../', {
'./lib/resolve-shims': resolveShims
})
browserify(entry, { fullPaths: fullPaths })
.transform(shim)
.bundle(function (err, src) {
if (err) return cb(err);
var ctx = { window: { name: 'the window' }, console: console };
ctx.self = ctx.window;
var require_ = vm.runInNewContext(src, ctx)
cb(null, require_);
})
}
test('when a module only attaches to the window after checking for module.exports and define and we browserify it', function (t) {
runBundle(false, function (err, require_) {
if (err) { t.fail(err); return t.end() }
var exp = require_(1);
t.equal(exp.attachedEve, 'loves adam', 'attaches it to window')
t.equal(exp.exportedEve, 'loves adam', 'exports it as well')
t.end()
})
})
if (browserify_version >= 5)
test('when a module only attaches to the window after checking for module.exports and define and we browserify it, using fullPaths', function (t) {
runBundle(true, function (err, require_) {
if (err) { t.fail(err); return t.end() }
var exp = require_(entry);
t.equal(exp.attachedEve, 'loves adam', 'attaches it to window')
t.equal(exp.exportedEve, 'loves adam', 'exports it as well')
t.end()
})
})