|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 'use strict'; |
|
6 |
|
7 const { Loader, Require, unload, override } = require('sdk/loader/cuddlefish'); |
|
8 const packaging = require('@loader/options'); |
|
9 |
|
10 exports['test loader'] = function(assert) { |
|
11 var prints = []; |
|
12 function print(message) { |
|
13 prints.push(message); |
|
14 } |
|
15 |
|
16 let loader = Loader(override(packaging, { |
|
17 globals: { |
|
18 print: print, |
|
19 foo: 1 |
|
20 } |
|
21 })); |
|
22 let require = Require(loader, module); |
|
23 |
|
24 var fixture = require('./loader/fixture'); |
|
25 |
|
26 assert.equal(fixture.foo, 1, 'custom globals must work.'); |
|
27 assert.equal(fixture.bar, 2, 'exports are set'); |
|
28 |
|
29 assert.equal(prints[0], 'testing', 'global print must be injected.'); |
|
30 |
|
31 var unloadsCalled = ''; |
|
32 |
|
33 require("sdk/system/unload").when(function(reason) { |
|
34 assert.equal(reason, 'test', 'unload reason is passed'); |
|
35 unloadsCalled += 'a'; |
|
36 }); |
|
37 require('sdk/system/unload.js').when(function() { |
|
38 unloadsCalled += 'b'; |
|
39 }); |
|
40 |
|
41 unload(loader, 'test'); |
|
42 |
|
43 assert.equal(unloadsCalled, 'ba', |
|
44 'loader.unload() must call listeners in LIFO order.'); |
|
45 }; |
|
46 |
|
47 require('test').run(exports); |