/
test.js
40 lines (34 loc) · 824 Bytes
/
test.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
var mod = require('mod')
mod.use(function(_module) {
_module('foo', function() {
return function() {
return 'hello world'
}
})
})
mod.use(function(_module, _require) {
var foo = _require('foo')
console.assert(foo() === 'hello world')
console.log('mod.use works!!')
})
// Attach it globally (or locally)
var _global = {}
mod.attach({
require: 'require',
define: 'module',
global: _global
})
_global.module('bar', function() {
var foo = _global.require('foo')
var res = foo()
console.assert(res === 'hello world')
console.log('mod.attach works!!')
})
mod.require('bar')
// nodejs testability
mod.nodejs(true)
var util = mod.require('util')
console.assert(typeof util.isArray === 'function')
console.log('mod.nodejs works!!')
console.log('Everything seems to work!!')
console.log('')