mirror of
https://github.com/svg/svgo.git
synced 2025-07-29 20:21:14 +03:00
Split regression extracter and runner (#1451)
A lot of new sources of regression tests may come and it's important to make debug simpler. Now regression-extract.js downloads and write svg files into test/regression-fixtures. regression.js run each svg in this folder. Mismatched svg diff is written into test/regression-diffs.
This commit is contained in:
57
test/regression-extract.js
Normal file
57
test/regression-extract.js
Normal file
@ -0,0 +1,57 @@
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const util = require('util');
|
||||
const zlib = require('zlib');
|
||||
const stream = require('stream');
|
||||
const fetch = require('node-fetch');
|
||||
const tarStream = require('tar-stream');
|
||||
|
||||
const pipeline = util.promisify(stream.pipeline);
|
||||
|
||||
const extractTarGz = async (url, baseDir, include) => {
|
||||
const extract = tarStream.extract();
|
||||
extract.on('entry', async (header, stream, next) => {
|
||||
try {
|
||||
if (include == null || include.test(header.name)) {
|
||||
if (header.name.endsWith('.svg')) {
|
||||
const file = path.join(baseDir, header.name);
|
||||
await fs.promises.mkdir(path.dirname(file), { recursive: true });
|
||||
await pipeline(stream, fs.createWriteStream(file));
|
||||
}
|
||||
if (header.name.endsWith('.svgz')) {
|
||||
// .svgz -> .svg
|
||||
const file = path.join(baseDir, header.name.slice(0, -1));
|
||||
await fs.promises.mkdir(path.dirname(file), { recursive: true });
|
||||
await pipeline(
|
||||
stream,
|
||||
zlib.createGunzip(),
|
||||
fs.createWriteStream(file)
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
}
|
||||
stream.resume();
|
||||
next();
|
||||
});
|
||||
const response = await fetch(url);
|
||||
await pipeline(response.body, extract);
|
||||
};
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
console.info('Download W3C SVG 1.1 Test Suite and extract svg files');
|
||||
await extractTarGz(
|
||||
'https://www.w3.org/Graphics/SVG/Test/20110816/archives/W3C_SVG_11_TestSuite.tar.gz',
|
||||
path.join(__dirname, 'regression-fixtures', 'w3c-svg-11-test-suite'),
|
||||
/^svg\//
|
||||
);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
}
|
||||
})();
|
Reference in New Issue
Block a user