michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: "use strict"; michael@0: michael@0: exports["test local vs sdk module"] = function (assert) { michael@0: assert.notEqual(require("memory"), michael@0: require("sdk/deprecated/memory"), michael@0: "Local module takes the priority over sdk modules"); michael@0: assert.ok(require("memory").local, michael@0: "this module is really the local one"); michael@0: } michael@0: michael@0: exports["test 3rd party vs sdk module"] = function (assert) { michael@0: // We are testing with a 3rd party package called `tabs` with 3 modules michael@0: // main, page-mod and third-party michael@0: michael@0: // the only way to require 3rd party package modules are to use absolute paths michael@0: // require("tabs/main"), require("tabs/page-mod"), michael@0: // require("tabs/third-party") and also require("tabs") which will refer michael@0: // to tabs's main package module. michael@0: michael@0: // So require(page-mod) shouldn't map the 3rd party michael@0: assert.equal(require("page-mod"), michael@0: require("sdk/page-mod"), michael@0: "Third party modules don't overload sdk modules"); michael@0: assert.ok(require("page-mod").PageMod, michael@0: "page-mod module is really the sdk one"); michael@0: michael@0: assert.equal(require("tabs/page-mod").id, "page-mod", michael@0: "tabs/page-mod is the 3rd party"); michael@0: michael@0: // But require(tabs) will map to 3rd party main module michael@0: // *and* overload the sdk module michael@0: // and also any local module with the same name michael@0: assert.equal(require("tabs").id, "tabs-main", michael@0: "Third party main module overload sdk modules"); michael@0: assert.equal(require("tabs"), michael@0: require("tabs/main"), michael@0: "require(tabs) maps to require(tabs/main)"); michael@0: // So that you have to use relative path to ensure getting the local module michael@0: assert.equal(require("./tabs").id, michael@0: "local-tabs", michael@0: "require(./tabs) maps to the local module"); michael@0: michael@0: // It should still be possible to require sdk module with absolute path michael@0: assert.ok(require("sdk/tabs").open, michael@0: "We can bypass this overloading with absolute path to sdk modules"); michael@0: assert.equal(require("sdk/tabs"), michael@0: require("addon-kit/tabs"), michael@0: "Old and new layout both work"); michael@0: } michael@0: michael@0: // /!\ Always use distinct module for each test. michael@0: // Otherwise, the linker can correctly parse and allow the first usage of it michael@0: // but still silently fail on the second. michael@0: michael@0: exports.testRelativeRequire = function (assert) { michael@0: assert.equal(require('./same-folder').id, 'same-folder'); michael@0: } michael@0: michael@0: exports.testRelativeSubFolderRequire = function (assert) { michael@0: assert.equal(require('./sub-folder/module').id, 'sub-folder'); michael@0: } michael@0: michael@0: exports.testMultipleRequirePerLine = function (assert) { michael@0: var a=require('./multiple/a'),b=require('./multiple/b'); michael@0: assert.equal(a.id, 'a'); michael@0: assert.equal(b.id, 'b'); michael@0: } michael@0: michael@0: exports.testSDKRequire = function (assert) { michael@0: assert.deepEqual(Object.keys(require('sdk/page-worker')), ['Page']); michael@0: assert.equal(require('page-worker'), require('sdk/page-worker')); michael@0: } michael@0: michael@0: require("sdk/test/runner").runTestsFromModule(module);