Skip to content

Commit 99e063a

Browse files
authored
Merge pull request #369 from mandragorn/test-fix
Fixing npm scripts for unit tests
2 parents 8448154 + 6e63aad commit 99e063a

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"test": "npm run test-func && npm run test-import",
1212
"test-func": "karma start",
1313
"watch:test-func": "npm run test-func -- karma.conf.dev.js --debug",
14-
"test-import": "gulp test-import",
14+
"test-import": "gulp test-vendor-globals && gulp test-vendor-commonJs",
1515
"doc": "mkdir docs/js -p && yuidoc",
1616
"doc:dev": "mkdir docs/js -p && yuidoc --server",
1717
"watch-import": "gulp watch-import & npm run doc:dev",

test/spec/import/commonJsImports.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
1-
var commonJsImportTest,
2-
_ = require('underscore');
1+
var commonJsImportTest;
2+
var _ = require('underscore');
33

44
commonJsImportTest = function(moduleToImport, expectedModules) {
55
expectedModules.push(moduleToImport);
66
describe('CommonJS Module import of "' + moduleToImport + '"', function() {
7-
var windowRequire, module, actualModule, moduleIndex;
7+
var module, actualModule, moduleIndex;
88

99
// Each module is browserified separately to validate requiring just that module.
1010
// This loads the browserified module and then tests that it includes all the dependencies that are required for that module.
1111
// e.g. to validate the Events module (which would be brought using require('/modules/Events')) this would load the browserified
1212
// file from testSandbox/browserified/modules/Events.js and create a jsdom environment and expose the require method
1313
// from the window which is then used to verify that all of the dependencies (and only those dependencies) are included.
1414
beforeAll(function(done) {
15+
var jasmineContext = this;
1516
require('./importEnv')('browserified' + moduleToImport).done(function(window) {
16-
windowRequire = window.require;
17+
jasmineContext.windowRequire = window.require;
1718
done();
1819
});
1920
})
2021

2122
for (moduleIndex = 0; moduleIndex < expectedModules.length; moduleIndex++) {
2223
module = expectedModules[moduleIndex];
2324
it('has the expected "' + module + '" dependency.', function() {
24-
expect(windowRequire(this)).toBeDefined();
25+
expect(this.windowRequire(this)).toBeDefined();
2526
}.bind(module));
2627
}
2728

2829
it('does not implement any extra dependencies.', function() {
2930
var existingModule, dependenciesIndex, failed = false, allDependencies = [];
30-
for (existingModule in windowRequire) {
31+
for (existingModule in this.windowRequire) {
3132
if (existingModule !== moduleToImport) {
3233
allDependencies.push(existingModule);
3334
}

test/spec/import/globalImports.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
describe('Global Module imports', function() {
2-
var window, globalIndex,
2+
var globalIndex,
33
// Define the globals layout, each array is a global to verify
44
// and each item in the array is a step on the path from the window object.
55
// The test below will verify that all items defined below exist on the window object.
@@ -35,8 +35,9 @@ describe('Global Module imports', function() {
3535
];
3636

3737
beforeAll(function(done) {
38+
var jasmineContext = this;
3839
require('./importEnv')('testEnv').done(function(pageWindow) {
39-
window = pageWindow;
40+
jasmineContext.window = pageWindow;
4041
done();
4142
});
4243
});
@@ -45,7 +46,7 @@ describe('Global Module imports', function() {
4546
for (globalIndex = 0; globalIndex < globals.length; globalIndex++) {
4647
global = globals[globalIndex];
4748
it('has the expected "' + global.join('.') + '" global.', function(global) {
48-
var globalPartIndex, nextGlobalKey, globalPart = window;
49+
var globalPartIndex, nextGlobalKey, globalPart = this.window;
4950
for (globalPartIndex = 0; globalPartIndex < global.length; globalPartIndex++) {
5051
nextGlobalKey = global[globalPartIndex];
5152
globalPart = globalPart[nextGlobalKey];

test/spec/import/importEnv.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Tests using jsDom are deprecated. Port tests to commonjs and add them to test/karma.
22

3-
var jsdom = require('jsdom'),
4-
Promise = require('promise'),
5-
argv = require('minimist')(process.argv);
3+
var jsdom = require('jsdom');
4+
var Promise = require('promise');
5+
var argv = require('minimist')(process.argv);
66

77
/**
88
* @method [Anonymous]
@@ -36,4 +36,4 @@ module.exports = function(envImport) {
3636
}
3737
});
3838
});
39-
};
39+
};

0 commit comments

Comments
 (0)