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

View File

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