2017-08-08 19:50:31 +03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const path = require('path');
|
|
|
|
const glob = require('glob');
|
|
|
|
const fs = require('fs');
|
|
|
|
const slash = require('slash');
|
|
|
|
const parseRefTest = require('./parse-reftest');
|
|
|
|
const outputPath = 'tests/reftests.js';
|
|
|
|
|
2017-08-11 17:22:10 +03:00
|
|
|
const ignoredTests = fs
|
|
|
|
.readFileSync(path.resolve(__dirname, `../tests/reftests/ignore.txt`))
|
|
|
|
.toString()
|
2019-04-07 22:49:10 +03:00
|
|
|
.split(/\r\n|\r|\n/)
|
2017-08-11 17:22:10 +03:00
|
|
|
.filter(l => l.length)
|
|
|
|
.reduce((acc, l) => {
|
|
|
|
const m = l.match(/^(\[(.+)\])?(.+)$/i);
|
|
|
|
acc[m[3]] = m[2] ? m[2].split(',') : [];
|
|
|
|
return acc;
|
|
|
|
}, {});
|
2017-08-10 18:24:26 +03:00
|
|
|
|
2017-08-08 19:50:31 +03:00
|
|
|
glob(
|
|
|
|
'../tests/reftests/**/*.html',
|
|
|
|
{
|
|
|
|
cwd: __dirname,
|
|
|
|
root: path.resolve(__dirname, '../../')
|
|
|
|
},
|
|
|
|
(err, files) => {
|
|
|
|
if (err) {
|
|
|
|
console.error(err);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
const testList = files.reduce((acc, filename) => {
|
|
|
|
const refTestFilename = path.resolve(__dirname, filename.replace(/\.html$/, '.txt'));
|
2017-08-10 18:24:26 +03:00
|
|
|
const name = `/${slash(path.relative('../', filename))}`;
|
2017-08-11 17:22:10 +03:00
|
|
|
if (!Array.isArray(ignoredTests[name]) || ignoredTests[name].length) {
|
2017-08-10 18:24:26 +03:00
|
|
|
acc[name] = fs.existsSync(refTestFilename)
|
|
|
|
? parseRefTest(fs.readFileSync(refTestFilename).toString())
|
|
|
|
: null;
|
|
|
|
} else {
|
|
|
|
console.log(`IGNORED: ${name}`);
|
|
|
|
}
|
|
|
|
|
2017-08-08 19:50:31 +03:00
|
|
|
return acc;
|
|
|
|
}, {});
|
|
|
|
fs.writeFileSync(
|
|
|
|
path.resolve(__dirname, `../${outputPath}`),
|
2017-08-11 17:22:10 +03:00
|
|
|
`module.exports = ${JSON.stringify({testList, ignoredTests}, null, 4)};`
|
2017-08-08 19:50:31 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
console.log(`${outputPath} updated`);
|
|
|
|
}
|
|
|
|
);
|