diff options
Diffstat (limited to 'tools/addon-sdk-1.4/packages/api-utils/tests/test-self.js')
-rw-r--r-- | tools/addon-sdk-1.4/packages/api-utils/tests/test-self.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tools/addon-sdk-1.4/packages/api-utils/tests/test-self.js b/tools/addon-sdk-1.4/packages/api-utils/tests/test-self.js new file mode 100644 index 0000000..3cc6df5 --- /dev/null +++ b/tools/addon-sdk-1.4/packages/api-utils/tests/test-self.js @@ -0,0 +1,29 @@ +exports.testSelf = function(test) { + var self = require("self"); + // We can't assert anything about the ID inside the unit test right now, + // because the ID we get depends upon how the test was invoked. The idea + // is that it is supposed to come from the main top-level package's + // package.json file, from the "id" key. + test.assertEqual(typeof(self.id), "string", "self.id is a string"); + test.assert(self.id.length > 0); + + var source = self.data.load("test-content-symbiont.js"); + test.assert(source.match(/test-content-symbiont/), "self.data.load() works"); + + // Likewise, we can't assert anything about the full URL, because that + // depends on self.id . We can only assert that it ends in the right + // thing. + var url = self.data.url("test-content-symbiont.js"); + test.assertEqual(typeof(url), "string", "self.data.url('x') returns string"); + test.assertEqual(/\/test-content-symbiont\.js$/.test(url), true); + + // Make sure 'undefined' is not in url when no string is provided. + url = self.data.url(); + test.assertEqual(typeof(url), "string", "self.data.url() returns string"); + test.assertEqual(/\/undefined$/.test(url), false); + + // When tests are run on just the api-utils package, self.name is + // api-utils. When they're run as 'cfx testall', self.name is testpkgs. + test.assert((self.name == "api-utils") || (self.name == "testpkgs"), + "self.name is api-utils or testpkgs"); +}; |