diff --git a/package.json b/package.json index 6d559427..04fe9b78 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "test": "npm run test-func && npm run test-import", "test-func": "karma start", "watch:test-func": "npm run test-func -- karma.conf.dev.js --debug", - "test-import": "gulp test-import", + "test-import": "gulp test-vendor-globals && gulp test-vendor-commonJs", "doc": "mkdir docs/js -p && yuidoc", "doc:dev": "mkdir docs/js -p && yuidoc --server", "watch-import": "gulp watch-import & npm run doc:dev", diff --git a/test/spec/import/commonJsImports.js b/test/spec/import/commonJsImports.js index 92d3fc95..fe46cef8 100644 --- a/test/spec/import/commonJsImports.js +++ b/test/spec/import/commonJsImports.js @@ -1,10 +1,10 @@ -var commonJsImportTest, - _ = require('underscore'); +var commonJsImportTest; +var _ = require('underscore'); commonJsImportTest = function(moduleToImport, expectedModules) { expectedModules.push(moduleToImport); describe('CommonJS Module import of "' + moduleToImport + '"', function() { - var windowRequire, module, actualModule, moduleIndex; + var module, actualModule, moduleIndex; // Each module is browserified separately to validate requiring just that module. // This loads the browserified module and then tests that it includes all the dependencies that are required for that module. @@ -12,8 +12,9 @@ commonJsImportTest = function(moduleToImport, expectedModules) { // file from testSandbox/browserified/modules/Events.js and create a jsdom environment and expose the require method // from the window which is then used to verify that all of the dependencies (and only those dependencies) are included. beforeAll(function(done) { + var jasmineContext = this; require('./importEnv')('browserified' + moduleToImport).done(function(window) { - windowRequire = window.require; + jasmineContext.windowRequire = window.require; done(); }); }) @@ -21,13 +22,13 @@ commonJsImportTest = function(moduleToImport, expectedModules) { for (moduleIndex = 0; moduleIndex < expectedModules.length; moduleIndex++) { module = expectedModules[moduleIndex]; it('has the expected "' + module + '" dependency.', function() { - expect(windowRequire(this)).toBeDefined(); + expect(this.windowRequire(this)).toBeDefined(); }.bind(module)); } it('does not implement any extra dependencies.', function() { var existingModule, dependenciesIndex, failed = false, allDependencies = []; - for (existingModule in windowRequire) { + for (existingModule in this.windowRequire) { if (existingModule !== moduleToImport) { allDependencies.push(existingModule); } diff --git a/test/spec/import/globalImports.js b/test/spec/import/globalImports.js index 3276a189..d6e22448 100644 --- a/test/spec/import/globalImports.js +++ b/test/spec/import/globalImports.js @@ -1,5 +1,5 @@ describe('Global Module imports', function() { - var window, globalIndex, + var globalIndex, // Define the globals layout, each array is a global to verify // and each item in the array is a step on the path from the window object. // The test below will verify that all items defined below exist on the window object. @@ -35,8 +35,9 @@ describe('Global Module imports', function() { ]; beforeAll(function(done) { + var jasmineContext = this; require('./importEnv')('testEnv').done(function(pageWindow) { - window = pageWindow; + jasmineContext.window = pageWindow; done(); }); }); @@ -45,7 +46,7 @@ describe('Global Module imports', function() { for (globalIndex = 0; globalIndex < globals.length; globalIndex++) { global = globals[globalIndex]; it('has the expected "' + global.join('.') + '" global.', function(global) { - var globalPartIndex, nextGlobalKey, globalPart = window; + var globalPartIndex, nextGlobalKey, globalPart = this.window; for (globalPartIndex = 0; globalPartIndex < global.length; globalPartIndex++) { nextGlobalKey = global[globalPartIndex]; globalPart = globalPart[nextGlobalKey]; diff --git a/test/spec/import/importEnv.js b/test/spec/import/importEnv.js index e33fc398..95eab50d 100644 --- a/test/spec/import/importEnv.js +++ b/test/spec/import/importEnv.js @@ -1,8 +1,8 @@ // Tests using jsDom are deprecated. Port tests to commonjs and add them to test/karma. -var jsdom = require('jsdom'), - Promise = require('promise'), - argv = require('minimist')(process.argv); +var jsdom = require('jsdom'); +var Promise = require('promise'); +var argv = require('minimist')(process.argv); /** * @method [Anonymous] @@ -36,4 +36,4 @@ module.exports = function(envImport) { } }); }); -}; \ No newline at end of file +};