Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f7c388d

Browse filesBrowse files
committed
go back to 'gm' to compare images
1 parent fcdb9b9 commit f7c388d
Copy full SHA for f7c388d

File tree

5 files changed

+71
-59
lines changed
Filter options

5 files changed

+71
-59
lines changed

‎package-lock.json

Copy file name to clipboardExpand all lines: package-lock.json
+37-16Lines changed: 37 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

Copy file name to clipboardExpand all lines: package.json
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
"fs-extra": "^2.0.0",
127127
"fuse.js": "^3.2.0",
128128
"glob": "^7.0.0",
129+
"gm": "^1.23.1",
129130
"gzip-size": "^4.1.0",
130131
"image-size": "^0.6.2",
131132
"into-stream": "^3.1.0",
@@ -147,13 +148,10 @@
147148
"npm-link-check": "^2.0.0",
148149
"open": "0.0.5",
149150
"orca": "github:plotly/orca#single-entry",
150-
"pixelmatch": "^4.0.2",
151-
"pngjs": "^3.3.3",
152151
"prepend-file": "^1.3.1",
153152
"prettysize": "1.1.0",
154153
"read-last-lines": "^1.1.0",
155154
"requirejs": "^2.3.1",
156-
"run-parallel": "^1.1.9",
157155
"run-series": "^1.1.4",
158156
"through2": "^2.0.3",
159157
"true-case-path": "^1.0.2",

‎tasks/util/constants.js

Copy file name to clipboardExpand all lines: tasks/util/constants.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ module.exports = {
7979
mapboxAccessToken: 'pk.eyJ1IjoiZXRwaW5hcmQiLCJhIjoiY2luMHIzdHE0MGFxNXVubTRxczZ2YmUxaCJ9.hwWZful0U2CQxit4ItNsiQ',
8080
pathToCredentials: path.join(pathToBuild, 'credentials.json'),
8181

82-
testContainerImage: 'quay.io/plotly/image-exporter:single-entry',
82+
testContainerImage: 'quay.io/plotly/image-exporter:graphicsmagick',
8383
testContainerName: process.env.PLOTLYJS_TEST_CONTAINER_NAME || 'orcabed',
8484
testContainerHome: '/var/www/image-exporter/plotly.js',
8585

‎test/image/assets/run.js

Copy file name to clipboardExpand all lines: test/image/assets/run.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ function run(mockList, input, argv, write) {
4040
app.on('export-error', function(info) {
4141
var mockName = mockList[info.itemIndex];
4242

43-
var msg = 'not ok ' + mockName + ' - ' + info.msg;
44-
if(info.error) msg += ' ' + info.error;
43+
var msg = 'not ok ' + mockName;
44+
if(info.error) msg += ' - ' + info.error;
4545

4646
console.warn(msg);
4747
failed.push(msg);

‎test/image/compare_pixels_test.js

Copy file name to clipboardExpand all lines: test/image/compare_pixels_test.js
+30-37Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
var fs = require('fs');
2-
var PNG = require('pngjs').PNG;
3-
var pixelmatch = require('pixelmatch');
4-
var parallel = require('run-parallel');
2+
var gm = require('gm');
53

64
var run = require('./assets/run');
75
var getMockList = require('./assets/get_mock_list');
86
var getImagePaths = require('./assets/get_image_paths');
7+
var common = require('../../tasks/util/common');
98

109
var argv = require('minimist')(process.argv.slice(2), {
1110
'boolean': ['queue', 'help', 'debug'],
@@ -14,7 +13,7 @@ var argv = require('minimist')(process.argv.slice(2), {
1413
help: ['h', 'info']
1514
},
1615
'default': {
17-
threshold: 0.1,
16+
threshold: 0.001,
1817
'parallel-limit': 4
1918
}
2019
});
@@ -65,7 +64,7 @@ if(argv._.indexOf('gl2d_*') !== -1) {
6564
if(!argv.queue) {
6665
console.log('WARN: Running gl2d image tests in batch may lead to unwanted results\n');
6766
}
68-
console.log('\nSorting gl2d mocks to avoid gl-shader conflicts');
67+
console.log('Sorting gl2d mocks to avoid gl-shader conflicts');
6968
sortGl2dMockList(mockList);
7069
console.log('');
7170
}
@@ -77,41 +76,35 @@ run(mockList, input, argv, function write(info, done) {
7776
var paths = getImagePaths(mockName);
7877
var imgData = info.body;
7978

80-
if(!fs.existsSync(paths.baseline)) {
81-
return done('baseline image for ' + mockName + ' does not exist');
79+
if(!common.doesFileExist(paths.baseline)) {
80+
return done(mockName + ': baseline image for does not exist');
8281
}
8382

84-
parallel([
85-
function(cb) {
86-
var img = fs.createReadStream(paths.baseline).pipe(new PNG());
87-
img.on('parsed', function() { return cb(null, img); });
88-
img.on('error', function(err) { return cb(err); });
89-
},
90-
function(cb) { (new PNG()).parse(imgData, cb); },
91-
function(cb) { fs.writeFile(paths.test, imgData, cb); },
92-
], function(err, results) {
93-
if(err) done(err);
94-
95-
var baseline = results[0];
96-
var width = baseline.width;
97-
var height = baseline.height;
98-
var test = results[1];
99-
var diff = new PNG({width: width, height: height});
100-
101-
var numDiffPixels = pixelmatch(
102-
baseline.data, test.data, diff.data,
103-
width, height,
104-
{threshold: argv.threshold}
105-
);
106-
107-
if(numDiffPixels) {
108-
var diffStream = fs.createWriteStream(paths.diff).on('finish', function() {
109-
done('(' + numDiffPixels + ' pixels differ with threshold ' + argv.threshold + ')');
110-
});
111-
diff.pack().pipe(diffStream);
112-
} else {
113-
done();
83+
fs.writeFile(paths.test, imgData, function(err) {
84+
if(err) {
85+
return done(mockName + ': error during test image generation');
11486
}
87+
88+
gm.compare(paths.test, paths.baseline, {
89+
file: paths.diff,
90+
highlightColor: 'purple',
91+
tolerance: argv.threshold
92+
}, function(err, isEqual, equality) {
93+
if(err) {
94+
return done(mockName + ': gm compare error');
95+
}
96+
97+
if(isEqual) {
98+
fs.unlink(paths.diff, function(err) {
99+
if(err) {
100+
return done(mockName + ': unlink error');
101+
}
102+
done();
103+
});
104+
} else {
105+
done('differs by ' + (equality / argv.threshold).toPrecision(4) + ' times the threshold');
106+
}
107+
});
115108
});
116109
});
117110

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.