Skip to content

Commit

Permalink
Upgrade jasmine and some tutorial testing infrastructure.
Browse files Browse the repository at this point in the history
This upgrades to jasmine 3.1 and also the karma-jasmine-html-reporter.
There are clearer tutorial test failure messages, especially when the
test throws an exception.

Fixed some wording in the contour tutorial.

A small performance improvement was made to the gl.lineFeature.
  • Loading branch information
manthey committed Jun 5, 2018
1 parent 05b534b commit f0e5dae
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 52 deletions.
5 changes: 5 additions & 0 deletions karma-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,11 @@ module.exports = function (config) {
frameworks: [
'jasmine', 'sinon'
],
client: {
jasmine: {
random: false
}
},
webpack: {
cache: true,
devtool: 'inline-source-map',
Expand Down
76 changes: 39 additions & 37 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"istanbul-combine": "^0.3.0",
"istanbul-instrumenter-loader": "^3.0.1",
"jaguarjs-jsdoc": "^1.0.2",
"jasmine-core": "^2.4.1",
"jasmine-core": "^3.1.0",
"jquery": "^3.3",
"js-yaml": "^3.10.0",
"jsdoc": "^3.5",
Expand All @@ -59,7 +59,7 @@
"karma-coverage": "^1.0.0",
"karma-firefox-launcher": "^1.1.0",
"karma-jasmine": "^1.0.2",
"karma-jasmine-html-reporter": "^0.2.0",
"karma-jasmine-html-reporter": "^1.1.0",
"karma-phantomjs-launcher": "^1.0.0",
"karma-sinon": "^1.0.4",
"karma-sourcemap-loader": "^0.3.7",
Expand Down
7 changes: 4 additions & 3 deletions src/gl/lineFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ var gl_lineFeature = function (arg) {
miterLimit = m_this.style.get('miterLimit')(data),
antialiasing = m_this.style.get('antialiasing')(data) || 0,
order = m_this.featureVertices(),
orderLen = order.length,
posBuf, prevBuf, nextBuf, farBuf, flagsBuf, indicesBuf,
fixedFlags = (flagsDebug[m_this.style.get('debug')(data) ? 'debug' : 'normal'] || 0),
strokeWidthBuf, strokeColorBuf, strokeOpacityBuf,
Expand Down Expand Up @@ -458,7 +459,7 @@ var gl_lineFeature = function (arg) {

position = transform.transformCoordinates(
m_this.gcs(), m_this.layer().map().gcs(), position, 3);
len = numSegments * order.length;
len = numSegments * orderLen;
posBuf = util.getGeomBuffer(geom, 'pos', len * 3);
prevBuf = util.getGeomBuffer(geom, 'prev', len * 3);
nextBuf = util.getGeomBuffer(geom, 'next', len * 3);
Expand All @@ -482,7 +483,7 @@ var gl_lineFeature = function (arg) {
numSegments = m_geometry.numSegments;
closed = m_geometry.closed;
lineItemList = m_geometry.lineItemList;
len = numSegments * order.length;
len = numSegments * orderLen;
updateFlags = (
(lineCapVal !== m_geometry.lineCapVal || lineCapVal === undefined) ||
(lineJoinVal !== m_geometry.lineJoinVal || lineJoinVal === undefined) ||
Expand Down Expand Up @@ -548,7 +549,7 @@ var gl_lineFeature = function (arg) {
if (j) {
/* zero out the z position. This can be changed if we handle it in
* the shader. */
for (k = 0; k < order.length; k += 1, dest += 1, dest3 += 3) {
for (k = 0; k < orderLen; k += 1, dest += 1, dest3 += 3) {
v = vert[order[k][0]];
v2 = vert[1 - order[k][0]];
if (!onlyStyle) {
Expand Down
19 changes: 14 additions & 5 deletions tests/tutorials.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ describe('tutorials', function () {
var base$, tests;

base$ = $('iframe#map')[0].contentWindow.jQuery;
/* Never complain if there are no explicit expect statements */
expect().nothing();
/* If a codeblock test requires html video and the current browser
* doesn't support video, skip the test. */
if (!$('iframe#map')[0].contentWindow.HTMLVideoElement && base$('.codeblock[htmlvideo]').length) {
Expand All @@ -51,6 +53,8 @@ describe('tutorials', function () {
var targetWindow = target[0].contentWindow,
tut$ = targetWindow.$,
deferreds = [];
/* Description of the current tutorial and test. */
var desc = $('iframe#map')[0].contentWindow.document.title + ' - ' + test.data('description');
/* Evaluate and wait for each idle function and promises. */
test.data('idlefuncs').forEach(function (idleFunc) {
var defer = tut$.Deferred();
Expand All @@ -66,21 +70,26 @@ describe('tutorials', function () {
/* When all idle functions have resolved, evaluate each test in
* the test list. */
tut$.when.apply(tut$, deferreds).fail(function () {
throw new Error('Idle functions were rejected');
fail(desc + ' -> idle functions were rejected');
}).then(function () {
var subtestDeferreds = [];
test.data('tests').forEach(function (testExp) {
/* The test expression can return a value or a promise. We
* use jQuery's when to generically get the results in a
* resolution function. A rejection is a failure. */
var testResult = targetWindow.eval(testExp);
try {
var testResult = targetWindow.eval(testExp);
} catch (err) {
fail(desc + ' -> raised an error: ' + err);
return;
}
var subtestDefer = tut$.when(testResult).done(function (result) {
/* If the result isn't truthy, make sure our expect has a
* description telling which test block and specific test
* failed. */
expect(result).toBeTruthy(test.data('description') + ' -> ' + testExp);
expect(result).toBeTruthy(desc + ' -> ' + testExp);
}).fail(function () {
expect(false).toBeTruthy(test.data('description') + ' promise failed -> ' + testExp);
fail(desc + ' promise failed -> ' + testExp);
});
subtestDeferreds.push(subtestDefer);
});
Expand Down Expand Up @@ -109,7 +118,7 @@ describe('tutorials', function () {
});
/* Call the first step in the chained tests */
done();
}, 15000);
}, 150000);
});
});
});
1 change: 0 additions & 1 deletion tutorials/common/tutorials.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ function process_block(selector) {
* test's parent window to make debugging easier. */
if (window.parent && window.parent !== window) {
js = 'window.console = window.parent.parent.console;\n' +
'console.log("Testing " + window.parent.document.title);\n' +
js;
}
html = html.substr(0, pos).replace(/\s+$/, '') + '\n<script type="text/javascript">\n' + js + '</script>\n' + html.substr(pos);
Expand Down
8 changes: 4 additions & 4 deletions tutorials/contour/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ block mainTutorial
:markdown-it
# Tutorial - Contour Map
First, let's create our map and add a base map and a feature layer.

+codeblock('javascript', 1).
var map = geo.map({
node: '#map',
Expand All @@ -15,16 +15,16 @@ block mainTutorial
var layer = map.createLayer('feature');

:markdown-it
Then load some data.
The data is grid data describing geospatial point elevation, a record of z value -9999 means there is no land data.
Then load some data.
The data is grid data describing geospatial point elevation, a record of z value -9999 means there is no land data.
Since the data is relatively big, intead of adding inline data, we load asynchronously, and use [promise chain](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises) to chain up the following steps.
+codeblock('javascript', 2, 1).
var promise = Promise.resolve($.ajax({
url: '../../data/oahu.json'
}));

:markdown-it
Once the data is loaded. We create the contour feature with default color range. `min: 0` means only showing data with elevation.
Once the data is loaded, we create the contour feature with default color range. `min: 0` means only showing data with elevation.

+codeblock('javascript', 3, 2, true).
var contour = null;
Expand Down
Binary file modified tutorials/contour/thumb.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f0e5dae

Please sign in to comment.