Skip to content

Commit

Permalink
sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
SethFalco committed Dec 23, 2023
1 parent 16c6977 commit 64e64e0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 46 deletions.
59 changes: 38 additions & 21 deletions test/regression-extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,48 @@ const tarStream = require('tar-stream');

const pipeline = util.promisify(stream.pipeline);

/**
* Files to skip regression testing for due to parsing issues.
*/
const exclude = [
// parser doesn't work with this
'svgs/oxygen-icons-5.113.0/scalable/apps/kalarm.svg',
// animated
'w3c-svg-11-test-suite/svg/filters-light-04-f.svg',
'svgs/W3C_SVG_11_TestSuite/svg/filters-composite-05-f.svg',
// messed gradients
'svgs/W3C_SVG_11_TestSuite/svg/pservers-grad-18-b.svg',
// removing wrapping <g> breaks :first-child pseudo-class
'svgs/W3C_SVG_11_TestSuite/svg/styling-pres-04-f.svg',
// rect is converted to path which matches wrong styles
'svgs/W3C_SVG_11_TestSuite/svg/styling-css-08-f.svg',
// complex selectors are messed because of converting shapes to paths
'svgs/W3C_SVG_11_TestSuite/svg/struct-use-10-f.svg',
'svgs/W3C_SVG_11_TestSuite/svg/struct-use-11-f.svg',
'svgs/W3C_SVG_11_TestSuite/svg/styling-css-01-b.svg',
'svgs/W3C_SVG_11_TestSuite/svg/styling-css-04-f.svg',
// strange artifact breaks inconsistently breaks regression tests
'svgs/W3C_SVG_11_TestSuite/svg/filters-conv-05-f.svg',
];

/**
* @param {string} url
* @param {string} baseDir
* @param {RegExp} include
*/
const extractTarGz = async (url, baseDir, include) => {
const extractTarGz = async (url, baseDir) => {
const extract = tarStream.extract();
extract.on('entry', async (header, stream, next) => {
const name = header.name;

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));
} else 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),
);
}
if (
name.endsWith('.svg') &&
!exclude.includes(name) &&
!name.startsWith('svgs/W3C_SVG_11_TestSuite/svg/animate-')
) {
const file = path.join(baseDir, header.name);
await fs.promises.mkdir(path.dirname(file), { recursive: true });
await pipeline(stream, fs.createWriteStream(file));
}
} catch (error) {
console.error(error);
Expand All @@ -48,11 +66,10 @@ const extractTarGz = async (url, baseDir, include) => {

(async () => {
try {
console.info('Download W3C SVG 1.1 Test Suite and extract svg files');
console.info('Download SVGO Test Suite and extracting 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\//,
'https://sethfalco.github.io/svgo-test-suite/svgo-test-suite.tar.gz',
path.join(__dirname, 'regression-fixtures'),
);
} catch (error) {
console.error(error);
Expand Down
30 changes: 5 additions & 25 deletions test/regression.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,16 @@ const pixelmatch = require('pixelmatch');
const { optimize } = require('../lib/svgo.js');

const runTests = async ({ list }) => {
let skipped = 0;
let mismatched = 0;
let passed = 0;
list.reverse();
console.info('Start browser...');
/**
* @param {Object} page
* @param {string} name
* @returns {Promise}
*/
const processFile = async (page, name) => {
if (
// animated
name.startsWith('w3c-svg-11-test-suite/svg/animate-') ||
name === 'w3c-svg-11-test-suite/svg/filters-light-04-f.svg' ||
name === 'w3c-svg-11-test-suite/svg/filters-composite-05-f.svg' ||
// messed gradients
name === 'w3c-svg-11-test-suite/svg/pservers-grad-18-b.svg' ||
// removing wrapping <g> breaks :first-child pseudo-class
name === 'w3c-svg-11-test-suite/svg/styling-pres-04-f.svg' ||
// rect is converted to path which matches wrong styles
name === 'w3c-svg-11-test-suite/svg/styling-css-08-f.svg' ||
// complex selectors are messed because of converting shapes to paths
name === 'w3c-svg-11-test-suite/svg/struct-use-10-f.svg' ||
name === 'w3c-svg-11-test-suite/svg/struct-use-11-f.svg' ||
name === 'w3c-svg-11-test-suite/svg/styling-css-01-b.svg' ||
name === 'w3c-svg-11-test-suite/svg/styling-css-04-f.svg' ||
// strange artifact breaks inconsistently breaks regression tests
name === 'w3c-svg-11-test-suite/svg/filters-conv-05-f.svg'
) {
console.info(`${name} is skipped`);
skipped += 1;
return;
}
await page.goto(`http://localhost:5000/original/${name}`);
await page.setViewportSize({ width, height });
const originalBuffer = await page.screenshot({
Expand Down Expand Up @@ -93,7 +74,6 @@ const runTests = async ({ list }) => {
Array.from(new Array(os.cpus().length * 2), () => worker()),
);
await browser.close();
console.info(`Skipped: ${skipped}`);
console.info(`Mismatched: ${mismatched}`);
console.info(`Passed: ${passed}`);
return mismatched === 0;
Expand Down

0 comments on commit 64e64e0

Please sign in to comment.