Skip to content

Commit

Permalink
Merge pull request #369 from mandragorn/test-fix
Browse files Browse the repository at this point in the history
Fixing npm scripts for unit tests
  • Loading branch information
mandragorn authored Jan 23, 2018
2 parents 8448154 + 6e63aad commit 99e063a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 7 additions & 6 deletions test/spec/import/commonJsImports.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
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.
// e.g. to validate the Events module (which would be brought using require('/modules/Events')) this would load the browserified
// 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();
});
})

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);
}
Expand Down
7 changes: 4 additions & 3 deletions test/spec/import/globalImports.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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();
});
});
Expand All @@ -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];
Expand Down
8 changes: 4 additions & 4 deletions test/spec/import/importEnv.js
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -36,4 +36,4 @@ module.exports = function(envImport) {
}
});
});
};
};

0 comments on commit 99e063a

Please sign in to comment.