Allow tests to be ignored by specific browsers

This commit is contained in:
Niklas von Hertzen 2017-08-11 22:22:10 +08:00
parent af09280c38
commit 31a9f913ed
4 changed files with 264 additions and 206 deletions

View File

@ -7,10 +7,16 @@ const slash = require('slash');
const parseRefTest = require('./parse-reftest'); const parseRefTest = require('./parse-reftest');
const outputPath = 'tests/reftests.js'; const outputPath = 'tests/reftests.js';
const ignoredTests = [ const ignoredTests = fs
'/tests/reftests/background/radial-gradient.html', .readFileSync(path.resolve(__dirname, `../tests/reftests/ignore.txt`))
'/tests/reftests/text/chinese.html' .toString()
]; .split('\n')
.filter(l => l.length)
.reduce((acc, l) => {
const m = l.match(/^(\[(.+)\])?(.+)$/i);
acc[m[3]] = m[2] ? m[2].split(',') : [];
return acc;
}, {});
glob( glob(
'../tests/reftests/**/*.html', '../tests/reftests/**/*.html',
@ -27,8 +33,7 @@ glob(
const testList = files.reduce((acc, filename) => { const testList = files.reduce((acc, filename) => {
const refTestFilename = path.resolve(__dirname, filename.replace(/\.html$/, '.txt')); const refTestFilename = path.resolve(__dirname, filename.replace(/\.html$/, '.txt'));
const name = `/${slash(path.relative('../', filename))}`; const name = `/${slash(path.relative('../', filename))}`;
if (ignoredTests.indexOf(name) === -1) { if (!Array.isArray(ignoredTests[name]) || ignoredTests[name].length) {
console.log(name);
acc[name] = fs.existsSync(refTestFilename) acc[name] = fs.existsSync(refTestFilename)
? parseRefTest(fs.readFileSync(refTestFilename).toString()) ? parseRefTest(fs.readFileSync(refTestFilename).toString())
: null; : null;
@ -36,12 +41,11 @@ glob(
console.log(`IGNORED: ${name}`); console.log(`IGNORED: ${name}`);
} }
return acc; return acc;
}, {}); }, {});
fs.writeFileSync( fs.writeFileSync(
path.resolve(__dirname, `../${outputPath}`), path.resolve(__dirname, `../${outputPath}`),
`module.exports = ${JSON.stringify(testList, null, 4)};` `module.exports = ${JSON.stringify({testList, ignoredTests}, null, 4)};`
); );
console.log(`${outputPath} updated`); console.log(`${outputPath} updated`);

View File

@ -10,7 +10,7 @@ app.use('/', express.static(path.resolve(__dirname, '../')));
const listener = app.listen(0, () => { const listener = app.listen(0, () => {
async function run() { async function run() {
const chromeless = new Chromeless(); const chromeless = new Chromeless();
const tests = Object.keys(reftests); const tests = Object.keys(reftests.testList);
let i = 0; let i = 0;
while (tests[i]) { while (tests[i]) {
const filename = tests[i]; const filename = tests[i];

View File

@ -0,0 +1,5 @@
/tests/reftests/background/radial-gradient.html
/tests/reftests/text/chinese.html
[Edge]/tests/reftests/acid2.html
[Edge]/tests/reftests/pseudoelements.html
[Edge]/tests/reftests/text/multiple.html

View File

@ -1,8 +1,10 @@
import {expect} from 'chai'; import {expect} from 'chai';
import parseRefTest from '../scripts/parse-reftest'; import parseRefTest from '../scripts/parse-reftest';
import reftests from './reftests'; import reftests from './reftests';
import querystring from 'querystring';
const DOWNLOAD_REFTESTS = true; const DOWNLOAD_REFTESTS = true;
const query = querystring.parse(location.search.replace(/^\?/, ''));
const downloadResult = (filename, data) => { const downloadResult = (filename, data) => {
const downloadUrl = URL.createObjectURL(new Blob([data], {type: 'text/plain'})); const downloadUrl = URL.createObjectURL(new Blob([data], {type: 'text/plain'}));
@ -32,7 +34,7 @@ const assertPath = (result, expected, desc) => {
case 'Circle': case 'Circle':
expect(r.x).to.be.closeTo(e.x, 10, `${desc} Circle #${i + 1} x`); expect(r.x).to.be.closeTo(e.x, 10, `${desc} Circle #${i + 1} x`);
expect(r.y).to.be.closeTo(e.y, 10, `${desc} Circle #${i + 1} y`); expect(r.y).to.be.closeTo(e.y, 10, `${desc} Circle #${i + 1} y`);
expect(r.r).to.equal(e.r, `${desc} Circle #${i + 1} r`); expect(r.r).to.be.closeTo(e.r, 5, `${desc} Circle #${i + 1} r`);
break; break;
case 'Vector': case 'Vector':
expect(r.x).to.be.closeTo(e.x, 10, `${desc} vector #${i + 1} x`); expect(r.x).to.be.closeTo(e.x, 10, `${desc} vector #${i + 1} x`);
@ -67,13 +69,20 @@ const assertPath = (result, expected, desc) => {
); );
}); });
} else { } else {
Object.keys(reftests).forEach(url => { Object.keys(reftests.testList)
.filter(test => {
return (
!Array.isArray(reftests.ignoredTests[test]) ||
reftests.ignoredTests[test].indexOf(query.browser) === -1
);
})
.forEach(url => {
describe(url, function() { describe(url, function() {
this.timeout(30000); this.timeout(30000);
var windowWidth = 800; const windowWidth = 800;
var windowHeight = 600; const windowHeight = 600;
var testContainer = document.createElement('iframe'); const testContainer = document.createElement('iframe');
var REFTEST = reftests[url]; const REFTEST = reftests.testList[url];
testContainer.width = windowWidth; testContainer.width = windowWidth;
testContainer.height = windowHeight; testContainer.height = windowHeight;
testContainer.style.visibility = 'hidden'; testContainer.style.visibility = 'hidden';
@ -167,18 +176,40 @@ const assertPath = (result, expected, desc) => {
break; break;
case 'Text': case 'Text':
expect(RESULT.font).to.equal(args.font, `${desc} font`); expect(RESULT.font).to.equal(
args.font,
`${desc} font`
);
break; break;
case 'T': case 'T':
expect(RESULT.x).to.be.closeTo(args.x, 10, `${desc} x`); expect(RESULT.x).to.be.closeTo(
expect(RESULT.y).to.be.closeTo(args.y, 10, `${desc} y`); args.x,
expect(RESULT.text).to.equal(args.text, `${desc} text`); 10,
`${desc} x`
);
expect(RESULT.y).to.be.closeTo(
args.y,
10,
`${desc} y`
);
expect(RESULT.text).to.equal(
args.text,
`${desc} text`
);
break; break;
case 'Transform': case 'Transform':
expect(RESULT.x).to.be.closeTo(args.x, 10, `${desc} x`); expect(RESULT.x).to.be.closeTo(
expect(RESULT.y).to.be.closeTo(args.y, 10, `${desc} y`); args.x,
10,
`${desc} x`
);
expect(RESULT.y).to.be.closeTo(
args.y,
10,
`${desc} y`
);
expect(RESULT.matrix).to.equal( expect(RESULT.matrix).to.equal(
args.matrix, args.matrix,
`${desc} matrix` `${desc} matrix`
@ -186,8 +217,16 @@ const assertPath = (result, expected, desc) => {
break; break;
case 'Repeat': case 'Repeat':
expect(RESULT.x).to.be.closeTo(args.x, 10, `${desc} x`); expect(RESULT.x).to.be.closeTo(
expect(RESULT.y).to.be.closeTo(args.y, 10, `${desc} y`); args.x,
10,
`${desc} x`
);
expect(RESULT.y).to.be.closeTo(
args.y,
10,
`${desc} y`
);
expect(RESULT.width).to.be.closeTo( expect(RESULT.width).to.be.closeTo(
args.width, args.width,
3, 3,
@ -206,8 +245,16 @@ const assertPath = (result, expected, desc) => {
break; break;
case 'Gradient': case 'Gradient':
expect(RESULT.x).to.be.closeTo(args.x, 10, `${desc} x`); expect(RESULT.x).to.be.closeTo(
expect(RESULT.y).to.be.closeTo(args.y, 10, `${desc} y`); args.x,
10,
`${desc} x`
);
expect(RESULT.y).to.be.closeTo(
args.y,
10,
`${desc} y`
);
expect(RESULT.x0).to.be.closeTo( expect(RESULT.x0).to.be.closeTo(
args.x0, args.x0,
5, 5,
@ -277,7 +324,9 @@ const assertPath = (result, expected, desc) => {
}); });
} else if (DOWNLOAD_REFTESTS) { } else if (DOWNLOAD_REFTESTS) {
downloadResult( downloadResult(
url.slice(url.lastIndexOf('/') + 1).replace(/\.html$/i, '.txt'), url
.slice(url.lastIndexOf('/') + 1)
.replace(/\.html$/i, '.txt'),
result result
); );
} }