Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get ES6 unit tests and coverage running #8199

Merged
merged 1 commit into from
Sep 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Source/Core/TaskProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ import RuntimeError from './RuntimeError.js';
if (defined(TaskProcessor._loaderConfig)) {
bootstrapMessage.loaderConfig = TaskProcessor._loaderConfig;
} else {
bootstrapMessage.loaderConfig.paths = {
'Workers': buildModuleUrl('Workers/Build')
};
bootstrapMessage.loaderConfig.baseUrl = buildModuleUrl.getCesiumBaseUrl().url;
}

Expand Down Expand Up @@ -334,7 +337,7 @@ import RuntimeError from './RuntimeError.js';
TaskProcessor.taskCompletedEvent = taskCompletedEvent;

// exposed for testing purposes
TaskProcessor._defaultWorkerModulePrefix = 'Workers/Build/';
TaskProcessor._defaultWorkerModulePrefix = 'Workers/';
TaskProcessor._workerModulePrefix = TaskProcessor._defaultWorkerModulePrefix;
TaskProcessor._loaderConfig = undefined;
TaskProcessor._canTransferArrayBuffer = undefined;
Expand Down
2 changes: 1 addition & 1 deletion Source/Workers/createGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import createTaskProcessorWorker from './createTaskProcessorWorker.js';
} else {
// Use AMD-style require.
// in web workers, require is synchronous
require(['./' + moduleName], function(f) {
require(['Workers/' + moduleName], function(f) {
module = f;
moduleCache[module] = f;
});
Expand Down
6 changes: 5 additions & 1 deletion Specs/Core/sampleTerrainMostDetailedSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { sampleTerrainMostDetailed } from '../../Source/Cesium.js';

describe('Core/sampleTerrainMostDetailed', function() {

var worldTerrain = createWorldTerrain();
var worldTerrain;
beforeAll(function() {
worldTerrain = createWorldTerrain();
return worldTerrain.readyPromise;
});

it('queries heights', function() {
var positions = [
Expand Down
6 changes: 5 additions & 1 deletion Specs/Core/sampleTerrainSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { sampleTerrain } from '../../Source/Cesium.js';

describe('Core/sampleTerrain', function() {

var worldTerrain = createWorldTerrain();
var worldTerrain;
beforeAll(function() {
worldTerrain = createWorldTerrain();
return worldTerrain.readyPromise;
});

it('queries heights', function() {
var positions = [
Expand Down
4 changes: 1 addition & 3 deletions Specs/SpecRunner.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@

<script src="../ThirdParty/jasmine-2.2.0/jasmine.js"></script>
<script src="../ThirdParty/jasmine-2.2.0/jasmine-html.js"></script>

<script type="text/javascript" src="SpecList.js"></script>
<script type="text/javascript" data-main="spec-main" src="../ThirdParty/requirejs-2.1.20/require.js"></script>
<script type="module" src="spec-main.js"></script>
</head>

<body>
Expand Down
92 changes: 19 additions & 73 deletions Specs/karma-main.js
Original file line number Diff line number Diff line change
@@ -1,73 +1,19 @@
(function() {
/*global __karma__,require*/
'use strict';

var included = '';
var excluded = '';
var webglValidation = false;
var webglStub = false;
var release = false;

if(__karma__.config.args){
included = __karma__.config.args[0];
excluded = __karma__.config.args[1];
webglValidation = __karma__.config.args[2];
webglStub = __karma__.config.args[3];
release = __karma__.config.args[4];
}

var toRequire = ['Cesium'];

if (release) {
require.config({
baseUrl : '/base/Build/Cesium',
waitSeconds : 0
});
toRequire.push('../Stubs/paths');
} else {
require.config({
baseUrl : '/base/Source',
waitSeconds : 0
});
}

require(toRequire, function (Cesium, paths) {
if (release) {
paths.Specs = '../../Specs';
paths.Source = '../../Source';
paths.Stubs = '../Stubs';

require.config({
paths: paths,
shim: {
'Cesium': {
exports: 'Cesium'
}
}
});
} else {
require.config({
paths: {
'Specs': '../Specs',
'Source' : '.'
}
});
}

require([
'Specs/customizeJasmine'
], function(
customizeJasmine) {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
customizeJasmine(jasmine.getEnv(), included, excluded, webglValidation, webglStub, release);

var specFiles = Object.keys(__karma__.files).filter(function(file) {
return /Spec\.js$/.test(file);
});

require(specFiles, function() {
__karma__.start();
});
});
});
})();
/*global __karma__*/
import customizeJasmine from './customizeJasmine.js';

var included = '';
var excluded = '';
var webglValidation = false;
var webglStub = false;
var release = false;

if (__karma__.config.args) {
included = __karma__.config.args[0];
excluded = __karma__.config.args[1];
webglValidation = __karma__.config.args[2];
webglStub = __karma__.config.args[3];
release = __karma__.config.args[4];
}

jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
customizeJasmine(jasmine.getEnv(), included, excluded, webglValidation, webglStub, release);
15 changes: 10 additions & 5 deletions Specs/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = function(config) {

// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks : ['jasmine', 'requirejs', 'detectBrowsers'],
frameworks : ['jasmine', 'detectBrowsers'],

client: {
captureConsole: false,
Expand All @@ -27,17 +27,22 @@ module.exports = function(config) {

// list of files / patterns to load in the browser
files : [
'Specs/karma-main.js',
{pattern : 'Source/**', included : false},
{pattern : 'Specs/**', included : false}
{ pattern: 'Specs/karma-main.js', included: true, type: 'module' },
{ pattern: 'Source/**', included: false, type: 'module' },
{ pattern: 'Specs/**', included: true, type: 'module' }
],

proxies : {
'/Data' : '/base/Specs/Data'
},

// list of files to exclude
exclude : [],
exclude: [
'Specs/TestWorkers/**',
'Specs/SpecList.js',
'Specs/SpecRunner.js',
'Specs/spec-main.js'
],

// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
Expand Down
83 changes: 20 additions & 63 deletions Specs/spec-main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
This is a version of Jasmine's boot.js modified to work with specs defined with AMD. The original comments from boot.js follow.
This is a version of Jasmine's boot.js modified to work with specs defined with ES6. The original comments from boot.js follow.

Starting with version 2.0, this file "boots" Jasmine, performing all of the necessary initialization before executing the loaded environment and all of a project's specs. This file should be loaded after `jasmine.js` and `jasmine_html.js`, but before any project source files or spec files are loaded. Thus this file can also be used to customize Jasmine for a project.

Expand All @@ -10,66 +10,25 @@
[jasmine-gem]: http://github.com/pivotal/jasmine-gem
*/

/*global require*/
import * as Cesium from '../Source/Cesium.js';
import addDefaultMatchers from './addDefaultMatchers.js';
import equalsMethodEqualityTester from './equalsMethodEqualityTester.js';

(function() {
'use strict';
// set this for uniform test resolution across devices
window.devicePixelRatio = 1;

// set this for uniform test resolution across devices
window.devicePixelRatio = 1;

function getQueryParameter(name) {
var match = new RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}

var built = getQueryParameter('built');
var release = getQueryParameter('release');

var toRequire = ['Cesium'];

if (built) {
require.config({
waitSeconds: 30,
baseUrl: getQueryParameter('baseUrl') || '../Build/Cesium',
paths: {
'Stubs': '../Stubs',
'Specs': '../../Specs',
'Source' : '../../Source'
},
shim: {
'Cesium': {
exports: 'Cesium'
}
}
});

toRequire.push('./Stubs/paths');
} else {
require.config({
waitSeconds: 30,
baseUrl: getQueryParameter('baseUrl') || '../Source',
paths: {
'Specs': '../Specs',
'Source' : '.'
}
});
}
function getQueryParameter(name) {
var match = new RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}

require(toRequire, function(
Cesium,
paths) {
var built = getQueryParameter('built');
var release = getQueryParameter('release');

/*global jasmineRequire,jasmine,exports,specs*/

var when = Cesium.when;

if (typeof paths !== 'undefined') {
require.config({
paths : paths
});
}

/**
* ## Require &amp; Instantiate
*
Expand Down Expand Up @@ -346,17 +305,15 @@
*
* Load the modules via AMD, and then run all of the loaded specs. This includes initializing the `HtmlReporter` instance and then executing the loaded Jasmine environment.
*/
var modules = ['Specs/addDefaultMatchers', 'Specs/equalsMethodEqualityTester'].concat(specs);
require(modules, function(addDefaultMatchers, equalsMethodEqualityTester) {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;

htmlReporter.initialize();
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;

var release = getQueryParameter('release');
env.beforeEach(function() { addDefaultMatchers(!release).call(env); });
env.beforeEach(function() { env.addCustomEqualityTester(equalsMethodEqualityTester); });
htmlReporter.initialize();

var release = getQueryParameter('release');
env.beforeEach(function() { addDefaultMatchers(!release).call(env); });
env.beforeEach(function() { env.addCustomEqualityTester(equalsMethodEqualityTester); });

import('./SpecList.js').then(function() {
env.execute();
});
});
})();
})
30 changes: 16 additions & 14 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -732,13 +732,16 @@ gulp.task('coverage', function(done) {
suppressSkipped: true
},
preprocessors: {
'Source/Core/**/*.js': ['coverage'],
'Source/DataSources/**/*.js': ['coverage'],
'Source/Renderer/**/*.js': ['coverage'],
'Source/Scene/**/*.js': ['coverage'],
'Source/Shaders/**/*.js': ['coverage'],
'Source/Widgets/**/*.js': ['coverage'],
'Source/Workers/**/*.js': ['coverage']
'Source/Core/**/*.js': ['karma-coverage-istanbul-instrumenter'],
'Source/DataSources/**/*.js': ['karma-coverage-istanbul-instrumenter'],
'Source/Renderer/**/*.js': ['karma-coverage-istanbul-instrumenter'],
'Source/Scene/**/*.js': ['karma-coverage-istanbul-instrumenter'],
'Source/Shaders/**/*.js': ['karma-coverage-istanbul-instrumenter'],
'Source/Widgets/**/*.js': ['karma-coverage-istanbul-instrumenter'],
'Source/Workers/**/*.js': ['karma-coverage-istanbul-instrumenter']
},
coverageIstanbulInstrumenter: {
esModules: true
},
reporters: ['spec', 'coverage'],
coverageReporter: {
Expand Down Expand Up @@ -789,9 +792,9 @@ gulp.task('test', function(done) {
}

var files = [
'Specs/karma-main.js',
{pattern : 'Source/**', included : false},
{pattern : 'Specs/**', included : false}
{ pattern: 'Specs/karma-main.js', included: true, type: 'module' },
{ pattern: 'Source/**', included: false, type: 'module' },
{ pattern: 'Specs/**', included: true, type: 'module' }
];

if (release) {
Expand Down Expand Up @@ -1317,14 +1320,13 @@ function createCesiumJs() {
}

function createSpecList() {
var specFiles = globby.sync(['Specs/**/*.js', '!Specs/*.js']);
var specs = [];
var specFiles = globby.sync(['Specs/**/*Spec.js']);

var contents = '';
specFiles.forEach(function(file) {
specs.push("'" + filePathToModuleId(file) + "'");
contents += "import './" + filePathToModuleId(file).replace('Specs/', '') + ".js';\n";
});

var contents = '/*eslint-disable no-unused-vars*/\n/*eslint-disable no-implicit-globals*/\nvar specs = [' + specs.join(',') + '];\n';
fs.writeFileSync(path.join('Specs', 'SpecList.js'), contents);
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@
"karma": "^4.0.0",
"karma-chrome-launcher": "^3.1.0",
"karma-coverage": "^2.0.1",
"karma-coverage-istanbul-instrumenter": "^1.0.1",
"karma-detect-browsers": "^2.2.3",
"karma-edge-launcher": "^0.4.2",
"karma-firefox-launcher": "^1.0.0",
"karma-ie-launcher": "^1.0.0",
"karma-jasmine": "^2.0.0",
"karma-longest-reporter": "^1.1.0",
"karma-requirejs": "^1.1.0",
"karma-safari-launcher": "^1.0.0",
"karma-spec-reporter": "^0.0.32",
"merge-stream": "^2.0.0",
Expand Down