This repository was archived by the owner on Jul 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 185
/
Copy path2-loader-api.js
86 lines (67 loc) · 2.38 KB
/
2-loader-api.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import assert from 'assert';
import { Loader, ModuleNamespace } from '../core/loader-polyfill.js';
import RegisterLoader from '../core/register-loader.js';
import { pathToFileUrl } from '../core/common.js';
describe('Loader Polyfill API', function () {
var loader = new Loader();
it('Should be an instance of itself', function () {
assert(loader instanceof Loader);
});
it('Should support the full registry API', function () {
assert(loader.registry);
loader.registry.set('asdf', new ModuleNamespace({ asdf: 'asdf' }));
assert(loader.registry.has('asdf'));
var m = loader.registry.get('asdf');
assert(m);
assert(m instanceof ModuleNamespace);
assert.equal(m.asdf, 'asdf');
for (var k of loader.registry.keys())
assert.equal(k, 'asdf');
for (var v of loader.registry.values())
assert.equal(v.asdf, 'asdf');
for (var v of loader.registry.entries()) {
assert.equal(v[0], 'asdf');
assert.equal(v[1].asdf, 'asdf');
}
for (var v of loader.registry) {
assert.equal(v[0], 'asdf');
assert.equal(v[1].asdf, 'asdf');
}
assert.equal(loader.registry.delete('asdf'), true);
assert.equal(loader.registry.has('asdf'), false);
});
it('Should support Module construction, evaluation and mutation', function () {
//var evaluated = false;
var mutator = { a: 'asdf' };
var module = new ModuleNamespace(mutator);/*, function() {
evaluated = true;
mutator.a = 'b';
});*/
assert.equal(module.a, 'asdf');
//Module.evaluate(module);
//assert(evaluated);
mutator.a = 'b';
assert.equal(module.a, 'b');
});
it('Should throw if instantiate hook doesnt instantiate', function () {
loader[loader.constructor.resolve] = function (x) {
return x;
};
return loader.import('x')
.catch(function (e) {
assert.equal(e.toString().indexOf('Error: Module instantiation did not return a valid namespace object.'), 0);
});
});
});
describe('Register Loader API', function () {
var loader = new RegisterLoader();
loader[RegisterLoader.resolve] = function (x) {
return x;
};
it('Should throw if instantiate doesnt instantiate', function () {
return loader.import('x')
.catch(function (e) {
assert.equal(e.toString().indexOf('Error: Module instantiation did not call an anonymous or correctly named System.register.'), 0);
});
});
});