Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: expand and optimize regression testing #1918

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 20 additions & 15 deletions .github/workflows/main.yml
@@ -1,11 +1,10 @@
name: CI

env:
FORCE_COLOR: 2
NODE: 20

on:
push:
branches:
- main
pull_request:
branches:
- main
Expand All @@ -26,18 +25,6 @@ jobs:
- run: yarn install
- run: yarn lint
- run: yarn typecheck
regression:
name: Test regressions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE }}
cache: yarn
- run: yarn install
- run: yarn playwright install --with-deps chromium
- run: yarn test-regression
test:
name: ${{ matrix.os }} Node.js ${{ matrix.node-version }}
strategy:
Expand All @@ -61,3 +48,21 @@ jobs:
- run: yarn playwright install --with-deps chromium
- run: yarn test
- run: yarn test-bundles
regression:
name: Test regressions
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
needs:
- lint
- test
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE }}
cache: yarn
- run: yarn install
- run: yarn playwright install --with-deps chromium
- run: yarn test-regression
58 changes: 23 additions & 35 deletions test/regression-extract.js
Expand Up @@ -11,55 +11,44 @@

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

/** Files to skip regression testing for due to parsing issues. */
const exclude = [
// animated
'svg/filters-light-04-f.svg',
'svg/filters-composite-05-f.svg',
'svgs/W3C_SVG_11_TestSuite/svg/filters-light-04-f.svg',
'svgs/W3C_SVG_11_TestSuite/svg/filters-composite-05-f.svg',
// messed gradients
'svg/pservers-grad-18-b.svg',
'svgs/W3C_SVG_11_TestSuite/svg/pservers-grad-18-b.svg',
// removing wrapping <g> breaks :first-child pseudo-class
'svg/styling-pres-04-f.svg',
'svgs/W3C_SVG_11_TestSuite/svg/styling-pres-04-f.svg',
// rect is converted to path which matches wrong styles
'svg/styling-css-08-f.svg',
'svgs/W3C_SVG_11_TestSuite/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',
'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
'svg/filters-conv-05-f.svg',
'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(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),
);
}
if (
name.endsWith('.svg') &&
!exclude.includes(name) &&
!name.startsWith('svgs/W3C_SVG_11_TestSuite/svg/animate-')
) {
const file = path.join(baseDir, header.name);

Check failure

Code scanning / CodeQL

Arbitrary file access during archive extraction ("Zip Slip") High

Unsanitized archive entry, which may contain '..', is used in a
file system operation
.
await fs.promises.mkdir(path.dirname(file), { recursive: true });
await pipeline(stream, fs.createWriteStream(file));
}
} catch (error) {
console.error(error);
Expand All @@ -74,11 +63,10 @@

(async () => {
try {
console.info('Downloading W3C SVG 1.1 Test Suite and extracting files');
console.info('Downloading SVGO 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\//,
'https://svg.github.io/svgo-test-suite/svgo-test-suite.tar.gz',
path.join(__dirname, 'regression-fixtures'),
);
} catch (error) {
console.error(error);
Expand Down