This repository has been archived by the owner on Jan 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
require-test.js
60 lines (46 loc) · 1.55 KB
/
require-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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// ==========================================================================
// Project: Spade - CommonJS Runtime
// Copyright: ©2010 Strobe Inc. All rights reserved.
// License: Licened under MIT license (see __preamble__.js)
// ==========================================================================
/*globals spade raises */
(function() {
var t = {},
Spade = spade.Spade;
// ..........................................................
// BASIC REQUIRE
//
module('spade: basic require', {
setup: function() {
t.spade = new Spade();
},
teardown: function() {
delete t.spade;
}
});
test('register then require a module', function() {
var spade = t.spade;
spade.register('foo/bar', function(require, exports) {
exports.foo = 'bar';
});
var exp = spade.require('foo/bar');
equal(exp.foo, 'bar', 'exports.foo == bar - means require succeeded');
});
test('register a string factory then require', function() {
var spade = t.spade;
spade.register('foo/bar', "exports.foo = 'bar';");
var exp = spade.require('foo/bar');
equal(exp.foo, 'bar', 'exports.foo == bar - means require succeeded');
});
test('require a non-existant module will throw an exception', function() {
var spade = t.spade;
raises(function() {
spade.require('imaginary/foo');
}, 'Module imaginary/foo not found');
});
test('require a module that was just registered symbolically. This is for compatibility with non-module items', function() {
var spade = t.spade;
spade.register('not/a-module');
ok(spade.require('not/a-module'));
});
})();