Refactor the server script to serve dist, website, and _build.
This also consolidates the `tests` and `testing` directories under the
`tests` directory, moving the test runners to `tests\runners`.
MODIFY
CMakeLists.txt
CMakeLists.txt
@@ -41,7 +41,7 @@ function(add_geojs_test test_name)
set_property(TEST "notes-report" APPEND PROPERTY DEPENDS "${test_name}")
endfunction()
-configure_file(${CMAKE_CURRENT_SOURCE_DIR}/testing/test-runners/geojs_test_runner.py.in
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/runners/geojs_test_runner.py.in
${CMAKE_CURRENT_BINARY_DIR}/test/geojs_test_runner.py
)
@@ -163,7 +163,7 @@ if(WEBGLHEADLESS_TESTS)
set_property(TEST "headed" APPEND PROPERTY DEPENDS "build_examples")
configure_file(
- "${CMAKE_CURRENT_SOURCE_DIR}/testing/test-runners/baseline_images.py"
+ "${CMAKE_CURRENT_SOURCE_DIR}/tests/runners/baseline_images.py"
"${CMAKE_CURRENT_BINARY_DIR}/test/baseline_images.py"
COPYONLY
)

MODIFY
docs/conf.py
docs/conf.py
@@ -26,7 +26,7 @@ from glob import glob
# documentation root, use os.path.abspath to make it absolute, like shown here.
basepath = os.path.dirname(os.path.abspath(__file__))
toppath = os.path.join(basepath, '..')
-for fname in glob(os.path.join(toppath, 'testing', 'test-runners', '*.py*')):
+for fname in glob(os.path.join(toppath, 'tests', 'runners', '*.py*')):
basename = os.path.split(fname)[-1].replace('.in', '')
with open(fname, 'r') as f:
with open(os.path.join(basepath, basename), 'w') as g:

MODIFY
package-lock.json
package-lock.json
"integrity": "sha1-R2iMuZu2gE8OBtPnY7HDLlfY5rY=",
"dev": true
},
+ "batch": {
+ "version": "0.6.1",
+ "resolved": "https://registry.npmjs.org/batch/-/batch-0.6.1.tgz",
+ "integrity": "sha1-3DQxT05nkxgJP8dgJyUl+UvyXBY=",
+ "dev": true
+ },
"bcrypt-pbkdf": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz",
"integrity": "sha512-Ga8c8NjAAp46Br4+0oZ2WxJCwIzwP60Gq1YPgU+39PiTVxyed/iKE/zyZI6+UlVYH5Q4PaQdHhcegIFPZTUfoQ==",
"dev": true
},
+ "serve-index": {
+ "version": "1.9.1",
+ "resolved": "https://registry.npmjs.org/serve-index/-/serve-index-1.9.1.tgz",
+ "integrity": "sha1-03aNabHn2C5c4FD/9bRTvqEqkjk=",
+ "dev": true,
+ "requires": {
+ "accepts": "1.3.5",
+ "batch": "0.6.1",
+ "debug": "2.6.9",
+ "escape-html": "1.0.3",
+ "http-errors": "1.6.3",
+ "mime-types": "2.1.18",
+ "parseurl": "1.3.2"
+ }
+ },
"serve-static": {
"version": "1.13.2",
"resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.13.2.tgz",

MODIFY
package.json
package.json
"pug-loader": "^2.4.0",
"raw-body": "^2.1.6",
"resemblejs": "^2.9.0",
+ "serve-index": "^1.9.1",
"sinon": "^1.17.3",
"string-replace-webpack-plugin": "^0.1.3",
"style-loader": "^0.21.0",
"codecov": "codecov",
"combine-coverage": "istanbul-combine -d dist/cobertura -r cobertura 'dist/coverage/json/**/coverage-final.json'",
"examples": "webpack-dev-server --config webpack-examples.config.js --host ${HOST-127.0.0.1} --port ${PORT-8082} --content-base dist/",
- "start-test": "node examples/build.js; forever start ./testing/test-runners/server.js",
- "stop-test": "forever stop ./testing/test-runners/server.js",
+ "start-test": "node examples/build.js; forever start ./tests/runners/server.js",
+ "stop-test": "forever stop ./tests/runners/server.js",
"docs": "jsdoc --pedantic -d dist/apidocs -r src -c jsdoc.conf.json",
"website": "cd website && npx hexo server",
"setup-website": "cd website && npm install",

DELETE
testing/test-runners/server.js
-/* global require, module */
-'use strict';
-
-var express = require('express'),
- bodyParser = require('body-parser'),
- xml = require('xmlbuilder'),
- fs = require('fs'),
- app = express(),
- cov = {},
- notes = {};
-
-/**
- * Combine coverage results.
- */
-function combine(files) {
- var f, l;
- for (f in files) {
- if (files.hasOwnProperty(f)) {
- if (!cov.hasOwnProperty(f)) {
- cov[f] = {};
- }
-
- for (l in files[f]) {
- if (files[f].hasOwnProperty(l)) {
- if (!cov[f].hasOwnProperty(l)) {
- cov[f][l] = 0;
- }
- cov[f][l] += files[f][l];
- }
- }
- }
- }
-}
-
-/**
- * Get total coverage statistics
- */
-function calc_stats() {
- var f, l, stats;
-
- stats = {
- totalSloc: 0,
- totalHits: 0,
- files: {}
- };
- for (f in cov) {
- if (cov.hasOwnProperty(f)) {
- var sloc = 0, hits = 0;
-
- for (l in cov[f]) {
- if (cov[f].hasOwnProperty(l)) {
- sloc += 1;
- hits += cov[f][l] && 1;
-
- }
- }
-
- stats.totalSloc += sloc;
- stats.totalHits += hits;
- stats.files[f] = {
- sloc: sloc,
- hits: hits
- };
- }
- }
- return stats;
-}
-
-/**
- * Convert to cobertura xml format
- */
-function cobertura() {
- var stats, totalPct, root, pkg, clss, cls, f, l, ln, lineRate;
-
- function _percent(num, den) {
- if (den <= 0) {
- return 1;
- } else {
- return num / den;
- }
- }
-
- stats = calc_stats();
- totalPct = _percent(stats.totalHits, stats.totalSloc);
-
- root = xml.create('coverage');
- root.a({
- 'branch-rate': 0,
- 'line-rate': totalPct,
- 'version': 3.6,
- 'timestamp': (new Date() / 1000).toFixed()
- });
-
- pkg = root.ele('packages').ele('package');
- pkg.a({
- 'branch-rate': 0,
- 'complexity': 0,
- 'line-rate': totalPct,
- 'name': ''
- });
-
- clss = pkg.ele('classes');
- for (f in cov) {
- if (cov.hasOwnProperty(f)) {
- lineRate = _percent(stats.files[f].hits, stats.files[f].sloc);
- cls = clss.ele('class');
- cls.a({
- 'branch-rate': 0,
- 'complexity': 0,
- 'line-rate': lineRate,
- 'filename': f.replace(/^src\/vgl/, 'vgl/src'),
- 'name': f
- });
-
- ln = cls.ele('lines');
- for (l in cov[f]) {
- if (cov[f].hasOwnProperty(l)) {
- ln.ele('line').a({
- number: l,
- hits: cov[f][l]
- });
- }
- }
- }
- }
-
- return root.toString();
-}
-
-app.use(bodyParser.json());
-app.use(express.static('dist'));
-
-app.put('/coverage', function (req, res, next) {
- combine(req.body.files);
- res.send('{}');
- next();
-});
-
-app.delete('/coverage', function (req, res, next) {
- cov = {};
- res.send('{}');
- next();
-});
-
-app.get('/coverage', function (req, res, next) {
- res.send(cobertura());
- next();
-});
-
-app.post('/coverage', function (req, res, next) {
- fs.writeFile(req.query.path, cobertura());
- res.send('{}');
- next();
-});
-
-app.delete('/notes', function (req, res, next) {
- notes = {};
- res.send('{}');
- next();
-});
-
-app.put('/notes', function (req, res, next) {
- notes[req.query.key] = req.body;
- res.send('{}');
- next();
-});
-
-app.post('/notes', function (req, res, next) {
- fs.writeFile(req.query.path, JSON.stringify(notes));
- next();
-});
-
-app.listen(30100, function () {
- console.log('Server listening on 30100');
-});
-
-module.exports = app;

RENAME
testing/test-runners/baseline_images.py
tests/runners/baseline_images.py
RENAME
testing/test-runners/geojs_test_runner.py.in
tests/runners/geojs_test_runner.py.in
ADD
tests/runners/server.js
+/* global require, module */
+'use strict';
+
+var serveIndex;
+try {
+ serveIndex = require('serve-index');
+} catch (err) { }
+var express = require('express'),
+ app = express(),
+ help = false,
+ skip = 2,
+ port = 30100,
+ build = false,
+ dist = false,
+ website = false;
+
+process.argv.forEach(function (val, idx) {
+ if (skip) {
+ skip -= 1;
+ return;
+ }
+ if (val === '--build' || val === '-b') {
+ build = true;
+ } else if (val === '--dist' || val === '-d') {
+ dist = true;
+ } else if ((val === '--port' || val === '-p') && idx + 1 < process.argv.length) {
+ port = parseInt(process.argv[idx + 1], 10);
+ skip = 1;
+ } else if (val.substr(0, 7) === '--port=') {
+ port = parseInt(val.substr(7), 10);
+ } else if (val === '--website' || val === '--web' || val === '-w') {
+ website = true;
+ } else {
+ help = true;
+ }
+});
+
+if (help) {
+ console.error('Serve the dist, website, and _build directories. Options:\n' +
+ '--build : serve _build directory as build/\n' +
+ '--dist : serve distribution directory (default)\n' +
+ '--port (port) : default 30100\n' +
+ '--website : serve website directory (if this and dist are specified,\n' +
+ ' dist is located as dist/)\n');
+ process.exit(1);
+}
+
+if (!website) {
+ if (!build || dist) {
+ app.use(express.static('dist'));
+ }
+} else {
+ if (dist) {
+ app.use('/dist', express.static('dist'));
+ }
+ app.use(express.static('website/public'));
+}
+if (build) {
+ if (serveIndex) {
+ app.use('/build', express.static('_build'), serveIndex('_build', {icons: true, view: 'details'}));
+ } else {
+ app.use('/build', express.static('_build'));
+ }
+}
+
+app.listen(port, function () {
+ console.log('Server listening on ' + port);
+});
+
+module.exports = app;

Refactor the server script to serve dist, website, and _build.

This also consolidates the `tests` and `testing` directories under the
`tests` directory, moving the test runners to `tests\runners`.