diff --git a/test/integration/lib/render.js b/test/integration/lib/render.js index 88f201583db..2b16198b232 100644 --- a/test/integration/lib/render.js +++ b/test/integration/lib/render.js @@ -49,27 +49,57 @@ function compare(path1, path2, diffPath, callback) { * * @param {string} implementation - identify the implementation under test; used to * deal with implementation-specific test exclusions and fudge-factors - * @param {Object} options - * @param {Array} [options.tests] - array of test names to run; tests not in the - * array will be skipped. Test names can be the name of a group, or the name of a group and the name - * of an individual test, separated by a slash. - * @param {Object} [options.ignores] - map of test names to disable. A key is the relative + * @param {Object} [ignores] - map of test names to disable. A key is the relative * path to a test directory, e.g. `"render-tests/background-color/default"`. A value is a string * that by convention links to an issue that explains why the test is currently disabled. By default, * disabled tests will be run, but not fail the test run if the result does not match the expected * result. If the value begins with "skip", the test will not be run at all -- use this for tests * that would crash the test harness entirely if they were run. - * @param {Object} [options.shuffle] - Boolean representing whether - * or not to shuffle the render tests sequence. - * @param {Object} [options.seed] - Seed for shuffling the render tests - * sequence. - * or not to shuffle the render tests sequence. - * @param {Object} [options.recycleMap] - Boolean representing whether - * or not to recycle the Map object when running the tests. * @param {renderFn} render - a function that performs the rendering * @returns {undefined} terminates the process when testing is complete */ -exports.run = function (implementation, options, render) { +exports.run = function (implementation, ignores, render) { + const options = { ignores, tests:[], shuffle:false, recycleMap:false, seed:makeHash() }; + + // https://stackoverflow.com/a/1349426/229714 + function makeHash() { + const array = []; + const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + + for (let i = 0; i < 10; ++i) + array.push(possible.charAt(Math.floor(Math.random() * possible.length))); + + // join array elements without commas. + return array.join(''); + } + + function checkParameter(param) { + const index = options.tests.indexOf(param); + if (index === -1) + return false; + options.tests.splice(index, 1); + return true; + } + + function checkValueParameter(defaultValue, param) { + const index = options.tests.findIndex((elem) => { return String(elem).startsWith(param); }); + if (index === -1) + return defaultValue; + + const split = String(options.tests.splice(index, 1)).split('='); + if (split.length !== 2) + return defaultValue; + + return split[1]; + } + + if (process.argv.length > 2) { + options.tests = process.argv.slice(2).filter((value, index, self) => { return self.indexOf(value) === index; }) || []; + options.shuffle = checkParameter('--shuffle'); + options.recycleMap = checkParameter('--recycle-map'); + options.seed = checkValueParameter(options.seed, '--seed'); + } + const directory = path.join(__dirname, '../render-tests'); harness(directory, implementation, options, (style, params, done) => { render(style, params, (err, data) => { diff --git a/test/render.test.js b/test/render.test.js index 2b8c87e3e12..10c72cbf8b2 100644 --- a/test/render.test.js +++ b/test/render.test.js @@ -2,52 +2,8 @@ require('flow-remove-types/register'); -const renderSuite = require('./integration').render; +const suite = require('./integration').render; const suiteImplementation = require('./suite_implementation'); const ignores = require('./ignores.json'); -let tests; -let shuffle = false; -let recycleMap = false; -let seed; - -// https://stackoverflow.com/a/1349426/229714 -function makeHash() { - const array = []; - const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - - for (let i = 0; i < 10; ++i) - array.push(possible.charAt(Math.floor(Math.random() * possible.length))); - - // join array elements without commas. - return array.join(''); -} - -function checkParameter(param) { - const index = tests.indexOf(param); - if (index === -1) - return false; - tests.splice(index, 1); - return true; -} - -function checkValueParameter(defaultValue, param) { - const index = tests.findIndex((elem) => { return String(elem).startsWith(param); }); - if (index === -1) - return defaultValue; - - const split = String(tests.splice(index, 1)).split('='); - if (split.length !== 2) - return defaultValue; - - return split[1]; -} - -if (process.argv[1] === __filename && process.argv.length > 2) { - tests = process.argv.slice(2).filter((value, index, self) => { return self.indexOf(value) === index; }); - shuffle = checkParameter('--shuffle'); - seed = checkValueParameter(makeHash(), '--seed'); - recycleMap = checkParameter('--recycle-map'); -} - -renderSuite.run('js', { tests, ignores, shuffle, seed, recycleMap }, suiteImplementation); +suite.run('js', ignores, suiteImplementation);