summaryrefslogtreecommitdiffstats
path: root/addon-sdk/source/test/addons/toolkit-require-reload
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /addon-sdk/source/test/addons/toolkit-require-reload
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'addon-sdk/source/test/addons/toolkit-require-reload')
-rw-r--r--addon-sdk/source/test/addons/toolkit-require-reload/main.js77
-rw-r--r--addon-sdk/source/test/addons/toolkit-require-reload/package.json5
2 files changed, 82 insertions, 0 deletions
diff --git a/addon-sdk/source/test/addons/toolkit-require-reload/main.js b/addon-sdk/source/test/addons/toolkit-require-reload/main.js
new file mode 100644
index 000000000..5f5827f97
--- /dev/null
+++ b/addon-sdk/source/test/addons/toolkit-require-reload/main.js
@@ -0,0 +1,77 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+"use strict";
+
+const { Cu } = require("chrome");
+
+const toolkit = require("toolkit/require");
+
+const {tmpdir} = require("node/os");
+const {join} = require("sdk/fs/path");
+const {writeFile, unlink} = require("sdk/io/fs");
+const {fromFilename} = require("sdk/url");
+
+const makeCallback = (resolve, reject) => (error, result) => {
+ if (error) reject(error);
+ else resolve(result);
+};
+
+const remove = path => new Promise((resolve, reject) =>
+ unlink(path, makeCallback(resolve, reject)));
+
+const write = (...params) => new Promise((resolve, reject) =>
+ writeFile(...params, makeCallback(resolve, reject)));
+
+exports.testReload = function*(assert) {
+ const modulePath = join(tmpdir(), "toolkit-require-reload.js");
+ const moduleURI = fromFilename(modulePath);
+
+ yield write(modulePath, `exports.version = () => 1;`);
+
+ const v1 = toolkit.require(moduleURI);
+
+ assert.equal(v1.version(), 1, "module exports version");
+
+ yield write(modulePath, `exports.version = () => 2;`);
+
+ assert.equal(v1, toolkit.require(moduleURI),
+ "require does not reload modules");
+
+ const v2 = toolkit.require(moduleURI, {reload: true});
+ assert.equal(v2.version(), 2, "module was updated");
+
+ yield remove(modulePath);
+};
+
+exports.testReloadAll = function*(assert) {
+ const parentPath = join(tmpdir(), "toolkit-require-reload-parent.js");
+ const childPath = join(tmpdir(), "toolkit-require-reload-child.js");
+
+ const parentURI = fromFilename(parentPath);
+ const childURI = fromFilename(childPath);
+
+ yield write(childPath, `exports.name = () => "child"`);
+ yield write(parentPath, `const child = require("./toolkit-require-reload-child");
+ exports.greet = () => "Hello " + child.name();`);
+
+ const parent1 = toolkit.require(parentURI);
+ assert.equal(parent1.greet(), "Hello child");
+
+ yield write(childPath, `exports.name = () => "father"`);
+ yield write(parentPath, `const child = require("./toolkit-require-reload-child");
+ exports.greet = () => "Hello " + child.name() + "!";`);
+
+ const parent2 = toolkit.require(parentURI, {reload: true});
+ assert.equal(parent2.greet(), "Hello child!",
+ "only parent changes were picked up");
+
+ const parent3 = toolkit.require(parentURI, {reload: true, all: true});
+ assert.equal(parent3.greet(), "Hello father!",
+ "all changes were picked up");
+
+ yield remove(childPath);
+ yield remove(parentPath);
+};
+
+exports.main = _ => require("sdk/test/runner").runTestsFromModule(module);
diff --git a/addon-sdk/source/test/addons/toolkit-require-reload/package.json b/addon-sdk/source/test/addons/toolkit-require-reload/package.json
new file mode 100644
index 000000000..25e885340
--- /dev/null
+++ b/addon-sdk/source/test/addons/toolkit-require-reload/package.json
@@ -0,0 +1,5 @@
+{
+ "id": "@toolkit-require-reload",
+ "version": "0.0.1",
+ "main": "main.js"
+}