Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80727 views
1
'use strict';
2
3
var assert = require('assert')
4
var umd = require('../')
5
var src = umd('sentinel-prime', 'return "sentinel"')
6
var namespacedSrc = umd('sentinel.prime', 'return "sentinel"')
7
var multiNamespaces = umd('a.b.c.d.e', 'return "sentinel"')
8
9
describe('with CommonJS', function () {
10
it('uses module.exports', function () {
11
var module = {exports: {}}
12
Function('module,exports', src)(module,module.exports)
13
assert(module.exports === 'sentinel')
14
})
15
})
16
describe('with amd', function () {
17
it('uses define', function () {
18
var defed
19
function define(d, fn) {
20
assert.deepEqual(d, [], 'You must pass an empty array of dependencies to amd to prevent dependency scanning.');
21
defed = fn()
22
}
23
define.amd = true
24
Function('define', src)(define)
25
assert(defed === 'sentinel')
26
})
27
})
28
describe('in the absense of a module system', function () {
29
it('uses window', function () {
30
var glob = {}
31
Function('window', src)(glob)
32
assert(glob.sentinelPrime === 'sentinel')
33
})
34
it('uses global', function () {
35
var glob = {}
36
Function('global,window', src)(glob)
37
assert(glob.sentinelPrime === 'sentinel')
38
})
39
it('uses self', function () {
40
var glob = {}
41
Function('self,window,global', src)(glob)
42
assert(glob.sentinelPrime === 'sentinel')
43
})
44
it('creates the proper namespaces', function() {
45
var glob = {}
46
Function('window', namespacedSrc)(glob)
47
assert(glob.sentinel.prime === 'sentinel')
48
})
49
it('creates proper multiple namespaces', function() {
50
var glob = {}
51
Function('window', multiNamespaces)(glob)
52
assert(glob.a.b.c.d.e === 'sentinel')
53
})
54
55
})
56
57