/
regression-extract.js
87 lines (81 loc) · 2.54 KB
/
regression-extract.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import fs from 'fs';
import path from 'path';
import stream from 'stream';
import util from 'util';
import zlib from 'zlib';
import fetch from 'node-fetch';
import tarStream from 'tar-stream';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const pipeline = util.promisify(stream.pipeline);
const exclude = [
// animated
'svg/filters-light-04-f.svg',
'svg/filters-composite-05-f.svg',
// messed gradients
'svg/pservers-grad-18-b.svg',
// removing wrapping <g> breaks :first-child pseudo-class
'svg/styling-pres-04-f.svg',
// rect is converted to path which matches wrong styles
'svg/styling-css-08-f.svg',
// complex selectors are messed because of converting shapes to paths
'svg/struct-use-10-f.svg',
'svg/struct-use-11-f.svg',
'svg/styling-css-01-b.svg',
'svg/styling-css-04-f.svg',
// strange artifact breaks inconsistently breaks regression tests
'svg/filters-conv-05-f.svg',
];
/**
* @param {string} url
* @param {string} baseDir
* @param {RegExp} include
*/
const extractTarGz = async (url, baseDir, include) => {
const extract = tarStream.extract();
extract.on('entry', async (header, stream, next) => {
const name = header.name;
try {
if (include == null || include.test(name)) {
if (
name.endsWith('.svg') &&
!exclude.includes(name) &&
!name.startsWith('svg/animate-')
) {
const file = path.join(baseDir, name);
await fs.promises.mkdir(path.dirname(file), { recursive: true });
await pipeline(stream, fs.createWriteStream(file));
} else if (name.endsWith('.svgz')) {
// .svgz -> .svg
const file = path.join(baseDir, 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, zlib.createGunzip(), extract);
};
(async () => {
try {
console.info('Downloading W3C SVG 1.1 Test Suite and extracting 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);
}
})();