8000 rewrite much of test-image scripts for orca · plotly/plotly.js@93009aa · GitHub
[go: up one dir, main page]

Skip to content

Commit 93009aa

Browse files
committed
rewrite much of test-image scripts for orca
1 parent f7bda74 commit 93009aa

15 files changed

+902
-536
lines changed

package-lock.json

Lines changed: 475 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
"check-node-version": "^3.2.0",
121121
"deep-equal": "^1.0.1",
122122
"ecstatic": "^3.2.0",
123+
"electron": "1.8.4",
123124
"eslint": "^4.18.0",
124125
"falafel": "^2.0.0",
125126
"fs-extra": "^2.0.0",
@@ -145,10 +146,14 @@
145146
"node-sass": "^4.7.2",
146147
"npm-link-check": "^2.0.0",
147148
"open": "0.0.5",
149+
"orca": "github:plotly/orca#single-entry",
150+
"pixelmatch": "^4.0.2",
151+
"pngjs": "^3.3.3",
148152
"prepend-file": "^1.3.1",
149153
"prettysize": "1.1.0",
150154
"read-last-lines": "^1.1.0",
151155
"requirejs": "^2.3.1",
156+
"run-parallel": "^1.1.9",
152157
"run-series": "^1.1.4",
153158
"through2": "^2.0.3",
154159
"true-case-path": "^1.0.2",

tasks/baseline.js

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
1-
var constants = require('./util/constants');
2-
var common = require('./util/common');
3-
var containerCommands = require('./util/container_commands');
4-
5-
var msg = [
6-
'Generating baseline image(s) using build/plotly.js from',
7-
common.getTimeLastModified(constants.pathToPlotlyBuild),
8-
'\n'
9-
].join(' ');
10-
11-
var cmd = containerCommands.getRunCmd(
12-
process.env.CIRCLECI,
13-
'node test/image/make_baseline.js ' + process.argv.slice(2).join(' ')
14-
);
15-
16-
console.log(msg);
17-
common.execCmd(cmd);
1+
require('./util/common').testImageWrapper({
2+
msg: 'baseline generation',
3+
script: 'make_baseline.js',
4+
args: process.argv.slice(2)
5+
});

tasks/docker.js

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,64 @@
11
var constants = require('./util/constants');
22
var common = require('./util/common');
3-
var containerCommands = require('./util/container_commands');
43

5-
var isCI = process.env.CIRCLECI;
64
var arg = process.argv[2];
5+
var img = constants.testContainerImage;
6+
var name = constants.testContainerName;
7+
var home = constants.testContainerHome;
78

8-
var msg, cmd, cb, errorCb;
9+
var msg;
10+
var cmd;
11+
var errorCb;
912

1013
switch(arg) {
11-
1214
case 'pull':
1315
msg = 'Pulling latest docker image';
14-
cmd = 'docker pull ' + constants.testContainerImage;
16+
cmd = 'docker pull ' + img;
1517
break;
1618

1719
case 'run':
18-
msg = 'Booting up ' + constants.testContainerName + ' docker container';
19-
cmd = containerCommands.dockerRun;
20+
msg = 'Booting up ' + name + ' docker container';
21+
22+
cmd = [
23+
'docker run -di',
24+
'--name', name,
25+
'--volume', constants.pathToRoot + ':' + home,
26+
// set shared memory size as a workaround
27+
// - https://github.com/plotly/orca/pull/50
28+
// - https://bugs.chromium.org/p/chromium/issues/detail?id=736452
29+
// - https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md#tips
30+
'--shm-size=2g',
31+
'--volume /dev/shm:/dev/shm',
32+
// save files as local owner
33+
'--user `id --user`',
34+
// override container entry point
35+
'--entrypoint /bin/bash',
36+
img
37+
].join(' ');
2038

2139
// if docker-run fails, try docker-start.
2240
errorCb = function(err) {
23-
if(err) common.execCmd('docker start ' + constants.testContainerName);
41+
if(err) common.execCmd('docker start ' + name);
2442
};
2543

2644
break;
2745

28-
case 'setup':
29-
msg = 'Setting up ' + constants.testContainerName + ' docker container for testing';
30-
cmd = containerCommands.getRunCmd(isCI, containerCommands.setup);
31-
break;
32-
3346
case 'stop':
34-
msg = 'Stopping ' + constants.testContainerName + ' docker container';
35-
cmd = 'docker stop ' + constants.testContainerName;
47+
msg = 'Stopping ' + name + ' docker container';
48+
cmd = 'docker stop ' + name;
3649
break;
3750

51+
case 'rm':
3852
case 'remove':
39-
msg = 'Removing ' + constants.testContainerName + ' docker container';
40-
cmd = 'docker rm ' + constants.testContainerName;
53+
msg = 'Removing ' + name + ' docker container';
54+
cmd = 'docker rm ' + name;
4155
break;
4256

4357
default:
44-
console.log('Usage: pull, run, setup, stop, remove');
58+
console.log('Usage: pull, run, stop, remove');
4559
process.exit(0);
4660
break;
4761
}
4862

4963
console.log(msg);
50-
common.execCmd(cmd, cb, errorCb);
64+
common.execCmd(cmd, null, errorCb);

tasks/test_export.js

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
1-
var constants = require('./util/constants');
2-
var common = require('./util/common');
3-
var containerCommands = require('./util/container_commands');
4-
5-
var msg = [
6-
'Running image export tests using build/plotly.js from',
7-
common.getTimeLastModified(constants.pathToPlotlyBuild),
8-
'\n'
9-
].join(' ');
10-
11-
var cmd = containerCommands.getRunCmd(
12-
process.env.CIRCLECI,
13-
'node test/image/export_test.js ' + process.argv.slice(2).join(' ')
14-
);
15-
16-
console.log(msg);
17-
common.execCmd(cmd);
1+
require('./util/common').testImageWrapper({
2+
msg: 'image export test',
3+
script: 'export_test.js',
4+
args: process.argv.slice(2)
5+
});

tasks/test_image.js

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
1-
var constants = require('./util/constants');
2-
var common = require('./util/common');
3-
var containerCommands = require('./util/container_commands');
4-
5-
var msg = [
6-
'Running image comparison tests using build/plotly.js from',
7-
common.getTimeLastModified(constants.pathToPlotlyBuild),
8-
'\n'
9-
].join(' ');
10-
11-
var cmd = containerCommands.getRunCmd(
12-
process.env.CIRCLECI,
13-
'node test/image/compare_pixels_test.js ' + process.argv.slice(2).join(' ')
14-
);
15-
16-
console.log(msg);
17-
common.execCmd(cmd);
1+
require('./util/common').testImageWrapper({
2+
msg: 'image comparison test',
3+
script: 'compare_pixels_test.js',
4+
args: process.argv.slice(2)
5+
});

tasks/util/common.js

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
var fs = require('fs');
2+
var path = require('path');
23
var exec = require('child_process').exec;
4+
var execSync = require('child_process').execSync;
5+
var constants = require('./constants');
36

47
exports.execCmd = function(cmd, cb, errorCb) {
58
cb = cb ? cb : function() {};
@@ -22,8 +25,7 @@ exports.writeFile = function(filePath, content, cb) {
2225
exports.doesDirExist = function(dirPath) {
2326
try {
2427
if(fs.statSync(dirPath).isDirectory()) return true;
25-
}
26-
catch(e) {
28+
} catch(e) {
2729
return false;
2830
}
2931

@@ -33,8 +35,7 @@ exports.doesDirExist = function(dirPath) {
3335
exports.doesFileExist = function(filePath) {
3436
try {
3537
if(fs.statSync(filePath).isFile()) return true;
36-
}
37-
catch(e) {
38+
} catch(e) {
3839
return false;
3940
}
4041

@@ -53,8 +54,8 @@ exports.getTimeLastModified = function(filePath) {
5354
throw new Error(filePath + ' does not exist');
5455
}
5556

56-
var stats = fs.statSync(filePath),
57-
formattedTime = exports.formatTime(stats.mtime);
57+
var stats = fs.statSync(filePath);
58+
var formattedTime = exports.formatTime(stats.mtime);
5859

5960
return formattedTime;
6061
};
@@ -66,3 +67,55 @@ exports.touch = function(filePath) {
6667
exports.throwOnError = function(err) {
6768
if(err) throw err;
6869
};
70+
71+
exports.testImageWrapper = function(opts) {
72+
var isCI = process.env.CIRCLECI;
73+
var useLocalElectron = process.env.LOCAL_ELECTRON;
74+
var args = opts.args.join(' ');
75+
76+
var msg = [
77+
'Running ' + opts.msg + ' using build/plotly.js from',
78+
exports.getTimeLastModified(constants.pathToPlotlyBuild),
79+
'\n'
80+
].join(' ');
81+
82+
var pathToElectron;
83+
var pathToScript;
84+
var cmd;
85+
86+
if(useLocalElectron) {
87+
try {
88+
// N.B. this is what require('electron') in a node context
89+
pathToElectron = require('electron');
90+
} catch(e) {
91+
throw new Error('electron not installed locally');
92+
}
93+
94+
pathToScript = path.join(constants.pathToImageTest, opts.script);
95+
cmd = [pathToElectron, pathToScript, args].join(' ');
96+
} else {
97+
pathToElectron = path.join(constants.testContainerHome, '..', 'node_modules', '.bin', 'electron');
98+
pathToScript = path.join(constants.testContainerHome, 'test', 'image', opts.script);
99+
100+
var baseCmd = [
101+
'xvfb-run --auto-servernum',
102+
'--server-args \'-screen 0, 1024x768x24\'',
103+
pathToElectron, pathToScript, args
104+
].join(' ');
105+
106+
if(isCI) {
107+
cmd = baseCmd;
108+
} else {
109+
cmd = [
110+
'docker exec -i', constants.testContainerName,
111+
'/bin/bash -c',
112+
'"' + baseCmd + '"'
113+
].join(' ');
114+
}
115+
}
116+
117+
console.log(msg);
118+
if(process.env.DEBUG) console.log('\n' + cmd);
119+
120+
execSync(cmd, {stdio: [0, 1, 2]});
121+
};

tasks/util/constants.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ module.exports = {
5151
pathToTopojsonDist: path.join(pathToDist, 'topojson/'),
5252
pathToPlotlyGeoAssetsSrc: path.join(pathToSrc, 'assets/geo_assets.js'),
5353
pathToPlotlyGeoAssetsDist: path.join(pathToDist, 'plotly-geo-assets.js'),
54+
pathToMathJax: path.join(pathToDist, 'extras', 'mathjax', 'MathJax.js'),
5455

5556
pathToFontSVG: path.join(pathToSrc, 'fonts/ploticon/ploticon.svg'),
5657
pathToFontSVGBuild: path.join(pathToBuild, 'ploticon.js'),
@@ -78,11 +79,9 @@ module.exports = {
7879
mapboxAccessToken: 'pk.eyJ1IjoiZXRwaW5hcmQiLCJhIjoiY2luMHIzdHE0MGFxNXVubTRxczZ2YmUxaCJ9.hwWZful0U2CQxit4ItNsiQ',
7980
pathToCredentials: path.join(pathToBuild, 'credentials.json'),
8081

81-
testContainerImage: 'plotly/testbed:latest',
82-
testContainerName: process.env.PLOTLYJS_TEST_CONTAINER_NAME || 'imagetest',
83-
testContainerPort: '9010',
84-
testContainerUrl: 'http://localhost:9010/',
85-
testContainerHome: '/var/www/streambed/image_server/plotly.js',
82+
testContainerImage: 'quay.io/plotly/image-exporter:single-entry',
83+
testContainerName: process.env.PLOTLYJS_TEST_CONTAINER_NAME || 'orcabed',
84+
testContainerHome: '/var/www/image-exporter/plotly.js',
8685

8786
uglifyOptions: {
8887
mangle: true,

tasks/util/container_commands.js

Lines changed: 0 additions & 66 deletions
This file was deleted.

test/image/assets/get_image_paths.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
var path = require('path');
22
var constants = require('../../../tasks/util/constants');
3-
43
var DEFAULT_FORMAT = 'png';
54

6-
75
/**
86< 48DA /td>
* Return paths to baseline, test-image and diff images for a given mock name.
97
*
108
* @param {string} mockName
119
* @param {string} format
1210
* @return {object}
13-
* baseline
14-
* test
15-
* diff
11+
* mock
12+
* baseline
13+
* test
14+
* diff
1615
*/
1716
module.exports = function getImagePaths(mockName, format) {
1817
format = format || DEFAULT_FORMAT;
1918

2019
return {
20+
mock: join(constants.pathToTestImageMocks, mockName, 'json'),
2121
baseline: join(constants.pathToTestImageBaselines, mockName, format),
2222
test: join(constants.pathToTestImages, mockName, format),
2323
diff: join(constants.pathToTestImagesDiff, 'diff-' + mockName, format)

0 commit comments

Comments
 (0)
0