Skip to content

Commit

Permalink
Move process arguments handling to renderSuite.run
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoabinader committed Sep 13, 2017
1 parent 44248ee commit 7d452ea
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 59 deletions.
56 changes: 43 additions & 13 deletions test/integration/lib/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>} [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<string>} [options.ignores] - map of test names to disable. A key is the relative
* @param {Object<string>} [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<boolean>} [options.shuffle] - Boolean representing whether
* or not to shuffle the render tests sequence.
* @param {Object<string>} [options.seed] - Seed for shuffling the render tests
* sequence.
* or not to shuffle the render tests sequence.
* @param {Object<boolean>} [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) => {
Expand Down
48 changes: 2 additions & 46 deletions test/render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 7d452ea

Please sign in to comment.