Skip to content

Commit

Permalink
Update test suite
Browse files Browse the repository at this point in the history
Updated to
mapbox/mapbox-gl-test-suite@9ab19437e6a5272f1d
fd7aaf12a7b5bbec208895
  • Loading branch information
Lucas Wojciechowski committed Jan 9, 2017
1 parent 3e6c0f6 commit 0f6b49f
Show file tree
Hide file tree
Showing 30 changed files with 323 additions and 156 deletions.
Binary file added test/integration/image/marker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 35 additions & 37 deletions test/integration/lib/harness.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
'use strict';

/* eslint-disable no-process-exit */

const fs = require('fs');
const path = require('path');
const queue = require('d3-queue').queue;
const colors = require('colors/safe');
const handlebars = require('handlebars');
var fs = require('fs');
var path = require('path');
var queue = require('d3-queue').queue;
var colors = require('colors/safe');
var handlebars = require('handlebars');

module.exports = function (directory, implementation, options, run) {
const q = queue(1);
const server = require('./server')();
var q = queue(1);
var server = require('./server')();

const tests = options.tests || [];
var tests = options.tests || [];

function shouldRunTest(group, test) {
if (tests.length === 0)
return true;

const id = `${group}/${test}`;
var id = group + '/' + test;

for (let i = 0; i < tests.length; i++) {
const k = id.indexOf(tests[i]);
for (var i = 0; i < tests.length; i++) {
var k = id.indexOf(tests[i]);
if (k === 0 || id[k - 1] === '-' || id[k - 1] === '/')
return true;
}
Expand All @@ -31,23 +29,23 @@ module.exports = function (directory, implementation, options, run) {

q.defer(server.listen);

fs.readdirSync(directory).forEach((group) => {
if (group === 'index.html' || group === 'results.html.tmpl' || group[0] === '.')
fs.readdirSync(directory).forEach(function (group) {
if (group === 'index.html' || group == 'results.html.tmpl' || group[0] === '.')
return;

fs.readdirSync(path.join(directory, group)).forEach((test) => {
fs.readdirSync(path.join(directory, group)).forEach(function (test) {
if (!shouldRunTest(group, test))
return;

if (!fs.lstatSync(path.join(directory, group, test)).isDirectory() ||
!fs.lstatSync(path.join(directory, group, test, 'style.json')).isFile())
return;

const style = require(path.join(directory, group, test, 'style.json'));
var style = require(path.join(directory, group, test, 'style.json'));

server.localizeURLs(style);

const params = Object.assign({
var params = Object.assign({
group: group,
test: test,
width: 512,
Expand All @@ -57,14 +55,14 @@ module.exports = function (directory, implementation, options, run) {
}, style.metadata && style.metadata.test);

if (implementation === 'native' && process.env.BUILDTYPE === 'Release' && params.group === 'debug') {
console.log(colors.gray(`* skipped ${params.group} ${params.test}`));
console.log(colors.gray('* skipped ' + params.group + ' ' + params.test));
return;
}

const skipped = params.skipped && params.skipped[implementation];
var skipped = params.skipped && params.skipped[implementation]
if (skipped) {
console.log(colors.gray(`* skipped ${params.group} ${params.test
} (${skipped})`));
console.log(colors.gray('* skipped ' + params.group + ' ' + params.test +
' (' + skipped + ')'));
return;
}

Expand All @@ -78,22 +76,22 @@ module.exports = function (directory, implementation, options, run) {

params.ignored = params.ignored && implementation in params.ignored;

q.defer((callback) => {
run(style, params, (err) => {
q.defer(function (callback) {
run(style, params, function(err) {
if (err) return callback(err);

if (params.ignored && !params.ok) {
params.color = '#9E9E9E';
console.log(colors.white(`* ignore ${params.group} ${params.test}`));
console.log(colors.white('* ignore ' + params.group + ' ' + params.test));
} else if (params.ignored) {
params.color = '#E8A408';
console.log(colors.yellow(`* ignore ${params.group} ${params.test}`));
console.log(colors.yellow('* ignore ' + params.group + ' ' + params.test));
} else if (!params.ok) {
params.color = 'red';
console.log(colors.red(`* failed ${params.group} ${params.test}`));
console.log(colors.red('* failed ' + params.group + ' ' + params.test));
} else {
params.color = 'green';
console.log(colors.green(`* passed ${params.group} ${params.test}`));
console.log(colors.green('* passed ' + params.group + ' ' + params.test));
}

callback(null, params);
Expand All @@ -104,26 +102,26 @@ module.exports = function (directory, implementation, options, run) {

q.defer(server.close);

q.awaitAll((err, results) => {
q.awaitAll(function (err, results) {
if (err) {
console.error(err);
setTimeout(() => { process.exit(-1); }, 0);
setTimeout(function () { process.exit(-1); }, 0);
return;
}

results = results.slice(1, -1);

if (process.env.UPDATE) {
console.log(`Updated ${results.length} tests.`);
console.log('Updated ' + results.length + ' tests.');
process.exit(0);
}

let passedCount = 0,
var passedCount = 0,
ignoreCount = 0,
ignorePassCount = 0,
failedCount = 0;

results.forEach((params) => {
results.forEach(function (params) {
if (params.ignored && !params.ok) {
ignoreCount++;
} else if (params.ignored) {
Expand All @@ -135,7 +133,7 @@ module.exports = function (directory, implementation, options, run) {
}
});

const totalCount = passedCount + ignorePassCount + ignoreCount + failedCount;
var totalCount = passedCount + ignorePassCount + ignoreCount + failedCount;

if (passedCount > 0) {
console.log(colors.green('%d passed (%s%)'),
Expand All @@ -157,10 +155,10 @@ module.exports = function (directory, implementation, options, run) {
failedCount, (100 * failedCount / totalCount).toFixed(1));
}

const template = handlebars.compile(fs.readFileSync(path.join(directory, 'results.html.tmpl'), 'utf8'));
const p = path.join(directory, 'index.html');
var template = handlebars.compile(fs.readFileSync(path.join(directory, 'results.html.tmpl'), 'utf8'));
var p = path.join(directory, 'index.html');
fs.writeFileSync(p, template({results: results}));
console.log(`Results at: ${p}`);
console.log('Results at: ' + p);

process.exit(failedCount === 0 ? 0 : 1);
});
Expand Down
77 changes: 38 additions & 39 deletions test/integration/lib/query.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
'use strict';

const path = require('path');
const harness = require('./harness');
const diff = require('diff');
const PNG = require('pngjs').PNG;
const fs = require('fs');
var path = require('path');
var harness = require('./harness');
var diff = require('diff');
var PNG = require('pngjs').PNG;
var fs = require('fs');

function deepEqual(a, b) {
if (typeof a !== typeof b)
Expand All @@ -14,17 +12,17 @@ function deepEqual(a, b) {
if (a === null || typeof a !== 'object')
return a === b;

const ka = Object.keys(a);
const kb = Object.keys(b);
var ka = Object.keys(a);
var kb = Object.keys(b);

if (ka.length !== kb.length)
if (ka.length != kb.length)
return false;

ka.sort();
kb.sort();

for (let i = 0; i < ka.length; i++)
if (ka[i] !== kb[i] || !deepEqual(a[ka[i]], b[ka[i]]))
for (var i = 0; i < ka.length; i++)
if (ka[i] != kb[i] || !deepEqual(a[ka[i]], b[ka[i]]))
return false;

return true;
Expand All @@ -42,30 +40,30 @@ function deepEqual(a, b) {
* @returns {undefined} terminates the process when testing is complete
*/
exports.run = function (implementation, options, query) {
const directory = path.join(__dirname, '../query-tests');
harness(directory, implementation, options, (style, params, done) => {
query(style, params, (err, data, results) => {
var directory = path.join(__dirname, '../query-tests');
harness(directory, implementation, options, function(style, params, done) {
query(style, params, function(err, data, results) {
if (err) return done(err);

const dir = path.join(directory, params.group, params.test);
var dir = path.join(directory, params.group, params.test);

if (process.env.UPDATE) {
fs.writeFile(path.join(dir, 'expected.json'), JSON.stringify(results, null, 2), done);
return;
}

const expected = require(path.join(dir, 'expected.json'));
var expected = require(path.join(dir, 'expected.json'));
params.ok = deepEqual(results, expected);

if (!params.ok) {
const msg = diff.diffJson(expected, results)
.map((hunk) => {
var msg = diff.diffJson(expected, results)
.map(function (hunk) {
if (hunk.added) {
return `+ ${hunk.value}`;
return '+ ' + hunk.value;
} else if (hunk.removed) {
return `- ${hunk.value}`;
return '- ' + hunk.value;
} else {
return ` ${hunk.value}`;
return ' ' + hunk.value;
}
})
.join('');
Expand All @@ -74,32 +72,33 @@ exports.run = function (implementation, options, query) {
console.log(msg);
}

const width = params.width * params.pixelRatio;
const height = params.height * params.pixelRatio;
var width = params.width * params.pixelRatio;
var height = params.height * params.pixelRatio;
var x, y;

const color = [255, 0, 0, 255];
var color = [255, 0, 0, 255];

function scaleByPixelRatio(x) {
return x * params.pixelRatio;
}

if (!Array.isArray(params.queryGeometry[0])) {
const p = params.queryGeometry.map(scaleByPixelRatio);
const d = 30;
var p = params.queryGeometry.map(scaleByPixelRatio);
var d = 30;
drawAxisAlignedLine([p[0] - d, p[1]], [p[0] + d, p[1]], data, width, height, color);
drawAxisAlignedLine([p[0], p[1] - d], [p[0], p[1] + d], data, width, height, color);
} else {
const a = params.queryGeometry[0].map(scaleByPixelRatio);
const b = params.queryGeometry[1].map(scaleByPixelRatio);
var a = params.queryGeometry[0].map(scaleByPixelRatio);
var b = params.queryGeometry[1].map(scaleByPixelRatio);
drawAxisAlignedLine([a[0], a[1]], [a[0], b[1]], data, width, height, color);
drawAxisAlignedLine([a[0], b[1]], [b[0], b[1]], data, width, height, color);
drawAxisAlignedLine([b[0], b[1]], [b[0], a[1]], data, width, height, color);
drawAxisAlignedLine([b[0], a[1]], [a[0], a[1]], data, width, height, color);
}

const actual = path.join(dir, 'actual.png');
var actual = path.join(dir, 'actual.png');

const png = new PNG({
var png = new PNG({
width: params.width * params.pixelRatio,
height: params.height * params.pixelRatio
});
Expand All @@ -108,7 +107,7 @@ exports.run = function (implementation, options, query) {

png.pack()
.pipe(fs.createWriteStream(actual))
.on('finish', () => {
.on('finish', function() {
params.actual = fs.readFileSync(actual).toString('base64');
done();
});
Expand All @@ -117,22 +116,22 @@ exports.run = function (implementation, options, query) {
};

function drawAxisAlignedLine(a, b, pixels, width, height, color) {
const fromX = clamp(Math.min(a[0], b[0]), 0, width);
const toX = clamp(Math.max(a[0], b[0]), 0, width);
const fromY = clamp(Math.min(a[1], b[1]), 0, height);
const toY = clamp(Math.max(a[1], b[1]), 0, height);
var fromX = clamp(Math.min(a[0], b[0]), 0, width);
var toX = clamp(Math.max(a[0], b[0]), 0, width);
var fromY = clamp(Math.min(a[1], b[1]), 0, height);
var toY = clamp(Math.max(a[1], b[1]), 0, height);

let index;
var index;
if (fromX === toX) {
for (let y = fromY; y <= toY; y++) {
for (var y = fromY; y <= toY; y++) {
index = getIndex(fromX, y);
pixels[index + 0] = color[0];
pixels[index + 1] = color[1];
pixels[index + 2] = color[2];
pixels[index + 3] = color[3];
}
} else {
for (let x = fromX; x <= toX; x++) {
for (var x = fromX; x <= toX; x++) {
index = getIndex(x, fromY);
pixels[index + 0] = color[0];
pixels[index + 1] = color[1];
Expand Down
Loading

0 comments on commit 0f6b49f

Please sign in to comment.