Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0b5b574

Browse files
committed
simplify API for image-exporter run wrapper
1 parent 3fb88b5 commit 0b5b574

File tree

4 files changed

+19
-22
lines changed

4 files changed

+19
-22
lines changed

test/image/assets/run.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@ var imageExporter = require('image-exporter');
22
var path = require('path');
33
var constants = require('../../../tasks/util/constants');
44

5-
function run(input, argv, write) {
5+
function run(mockList, input, argv, write) {
66
argv = argv || {};
77

8+
if(!Array.isArray(mockList) || mockList.length === 0) {
9+
throw new Error('Empty mockList list');
10+
}
811
if(!Array.isArray(input) || input.length === 0) {
912
throw new Error('Empty input list');
1013
}
14+
if(mockList.length !== input.length) {
15+
throw new Error('mockList and input must have same length');
16+
}
1117

1218
var app = imageExporter.run({
1319
input: input,
14-
write: write,
20+
write: function(info, _, done) { write(info, done); },
1521
parallelLimit: argv.queue ? 1 : argv['parallel-limit'],
1622
debug: argv.debug,
1723
component: {
@@ -28,12 +34,12 @@ function run(input, argv, write) {
2834
var failed = [];
2935

3036
app.on('after-export', function(info) {
31-
var mockName = getMockName(info);
37+
var mockName = mockList[info.itemIndex];
3238
console.log('ok ' + mockName);
3339
});
3440

3541
app.on('export-error', function(info) {
36-
var mockName = getMockName(info);
42+
var mockName = mockList[info.itemIndex];
3743

3844
var msg = 'not ok (' + info.code + '): ' + mockName + ' - ' + info.msg;
3945
if(info.error) msg += ' ' + info.error;
@@ -54,13 +60,6 @@ function run(input, argv, write) {
5460
}
5561
});
5662

57-
function getMockName(info) {
58-
var item = input[info.itemIndex];
59-
var mockPath = item.figure ? item.figure : item;
60-
var mockName = path.parse(mockPath).name;
61-
return mockName;
62-
}
63-
6463
return app;
6564
}
6665

test/image/compare_pixels_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ if(argv._.indexOf('gl2d_*') !== -1) {
7878

7979
var input = mockList.map(function(m) { return getImagePaths(m).mock; });
8080

81-
run(input, argv, function write(info, _, done) {
81+
run(mockList, input, argv, function write(info, done) {
8282
var mockName = mockList[info.itemIndex];
8383
var paths = getImagePaths(mockName);
8484
var imgData = info.body;

test/image/export_test.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ var argv = require('minimist')(process.argv.slice(2), {
1616
}
1717
});
1818

19-
// image-exporter cannot generate pdf & eps at the same time for some reason
20-
argv['parallel-limit'] = 1;
21-
2219
// no 'png' as it is tested in `compare_pixels_test.js`
2320
var FORMATS = ['jpeg', 'webp', 'svg', 'pdf', 'eps'];
2421

@@ -65,13 +62,14 @@ if(argv.help) {
6562
process.exit(0);
6663
}
6764

68-
var mockList = argv._.length > 0 ? getMockList(argv._) : DEFAULT_LIST;
65+
var _mockList = argv._.length > 0 ? getMockList(argv._) : DEFAULT_LIST;
66+
var mockList = [];
6967
var input = [];
7068

71-
mockList.forEach(function(mockName) {
69+
_mockList.forEach(function(mockName) {
7270
FORMATS.forEach(function(format) {
71+
mockList.push(mockName + '.' + format)
7372
input.push({
74-
fid: mockName,
7573
figure: getImagePaths(mockName).mock,
7674
format: format,
7775
width: WIDTH,
@@ -80,8 +78,8 @@ mockList.forEach(function(mockName) {
8078
});
8179
});
8280

83-
run(input, argv, function write(info, _, done) {
84-
var mockName = input[info.itemIndex].fid;
81+
run(mockList, input, argv, function write(info, done) {
82+
var mockName = mockList[info.itemIndex];
8583
var format = info.format;
8684
var paths = getImagePaths(mockName, format);
8785

@@ -95,7 +93,7 @@ run(input, argv, function write(info, _, done) {
9593
didExport = stats.size > MIN_SIZE;
9694
} else {
9795
var dims = sizeOf(paths.test);
98-
didExport = (dims.width === 200) && (dims.height === HEIGHT);
96+
didExport = (dims.width === WIDTH) && (dims.height === HEIGHT);
9997
}
10098

10199
done(didExport ? '' : format);

test/image/make_baseline.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ if(argv.help) {
4949
var mockList = getMockList(argv._);
5050
var input = mockList.map(function(m) { return getImagePaths(m).mock; });
5151

52-
run(input, argv, function write(info, _, done) {
52+
run(mockList, input, argv, function write(info, done) {
5353
var mockName = mockList[info.itemIndex];
5454
var imgData = info.body;
5555
var paths = getImagePaths(mockName);

0 commit comments

Comments
 (0)