Commit 79e86f32 by xzyfer

Tweak spec.js to support :only_on and multiple :todo engines

parent 65321899
...@@ -62,6 +62,8 @@ ...@@ -62,6 +62,8 @@
"in-publish": "^2.0.0", "in-publish": "^2.0.0",
"lodash.assign": "^4.2.0", "lodash.assign": "^4.2.0",
"lodash.clonedeep": "^4.3.2", "lodash.clonedeep": "^4.3.2",
"lodash.isarray": "^4.0.0",
"lodash.mergewith": "^4.6.0",
"meow": "^3.7.0", "meow": "^3.7.0",
"mkdirp": "^0.5.1", "mkdirp": "^0.5.1",
"nan": "^2.3.2", "nan": "^2.3.2",
......
...@@ -7,7 +7,9 @@ var assert = require('assert'), ...@@ -7,7 +7,9 @@ var assert = require('assert'),
? require('../lib-cov') ? require('../lib-cov')
: require('../lib'), : require('../lib'),
readYaml = require('read-yaml'), readYaml = require('read-yaml'),
objectMerge = require('object-merge'), mergeWith = require('lodash.mergewith'),
assign = require('lodash.assign'),
isArray = require('lodash.isarray'),
glob = require('glob'), glob = require('glob'),
specPath = require('sass-spec').dirname.replace(/\\/g, '/'), specPath = require('sass-spec').dirname.replace(/\\/g, '/'),
impl = 'libsass', impl = 'libsass',
...@@ -32,7 +34,7 @@ var initialize = function(inputCss, options) { ...@@ -32,7 +34,7 @@ var initialize = function(inputCss, options) {
testCase.statusPath = join(folder, 'status'); testCase.statusPath = join(folder, 'status');
testCase.optionsPath = join(folder, 'options.yml'); testCase.optionsPath = join(folder, 'options.yml');
if (exists(testCase.optionsPath)) { if (exists(testCase.optionsPath)) {
options = objectMerge(options, readYaml.sync(testCase.optionsPath)); options = mergeWith(assign({}, options), readYaml.sync(testCase.optionsPath), customizer);
} }
testCase.includePaths = [ testCase.includePaths = [
folder, folder,
...@@ -41,6 +43,7 @@ var initialize = function(inputCss, options) { ...@@ -41,6 +43,7 @@ var initialize = function(inputCss, options) {
testCase.precision = parseFloat(options[':precision']) || 5; testCase.precision = parseFloat(options[':precision']) || 5;
testCase.outputStyle = options[':output_style'] ? options[':output_style'].replace(':', '') : 'nested'; testCase.outputStyle = options[':output_style'] ? options[':output_style'].replace(':', '') : 'nested';
testCase.todo = options[':todo'] !== undefined && options[':todo'] !== null && options[':todo'].indexOf(impl) !== -1; testCase.todo = options[':todo'] !== undefined && options[':todo'] !== null && options[':todo'].indexOf(impl) !== -1;
testCase.only = options[':only_on'] !== undefined && options[':only_on'] !== null && options[':only_on'];
testCase.warningTodo = options[':warning_todo'] !== undefined && options[':warning_todo'] !== null && options[':warning_todo'].indexOf(impl) !== -1; testCase.warningTodo = options[':warning_todo'] !== undefined && options[':warning_todo'] !== null && options[':warning_todo'].indexOf(impl) !== -1;
testCase.startVersion = parseFloat(options[':start_version']) || 0; testCase.startVersion = parseFloat(options[':start_version']) || 0;
testCase.endVersion = parseFloat(options[':end_version']) || 99; testCase.endVersion = parseFloat(options[':end_version']) || 99;
...@@ -59,6 +62,8 @@ var runTest = function(inputCssPath, options) { ...@@ -59,6 +62,8 @@ var runTest = function(inputCssPath, options) {
it(test.name, function(done) { it(test.name, function(done) {
if (test.todo || test.warningTodo) { if (test.todo || test.warningTodo) {
this.skip('Test marked with TODO'); this.skip('Test marked with TODO');
} else if (test.only && test.only.indexOf(impl) === -1) {
this.skip('Tests marked for only: ' + test.only.join(', '));
} else if (version < test.startVersion) { } else if (version < test.startVersion) {
this.skip('Tests marked for newer Sass versions only'); this.skip('Tests marked for newer Sass versions only');
} else if (version > test.endVersion) { } else if (version > test.endVersion) {
...@@ -109,11 +114,18 @@ var specSuite = { ...@@ -109,11 +114,18 @@ var specSuite = {
suites: [], suites: [],
options: {} options: {}
}; };
function customizer(objValue, srcValue) {
if (isArray(objValue)) {
return objValue.concat(srcValue);
}
}
var executeSuite = function(suite, tests) { var executeSuite = function(suite, tests) {
var suiteFolderLength = suite.folder.split('/').length; var suiteFolderLength = suite.folder.split('/').length;
var optionsFile = join(suite.folder, 'options.yml'); var optionsFile = join(suite.folder, 'options.yml');
if (exists(optionsFile)) { if (exists(optionsFile)) {
suite.options = objectMerge(suite.options, readYaml.sync(optionsFile)); suite.options = mergeWith(assign({}, suite.options), readYaml.sync(optionsFile), customizer);
} }
// Push tests in the current suite // Push tests in the current suite
...@@ -143,7 +155,7 @@ var executeSuite = function(suite, tests) { ...@@ -143,7 +155,7 @@ var executeSuite = function(suite, tests) {
folder: suite.folder + '/' + prevSuite, folder: suite.folder + '/' + prevSuite,
tests: [], tests: [],
suites: [], suites: [],
options: suite.options options: assign({}, suite.options),
}, },
tests.slice(prevSuiteStart, i) tests.slice(prevSuiteStart, i)
) )
...@@ -159,7 +171,7 @@ var executeSuite = function(suite, tests) { ...@@ -159,7 +171,7 @@ var executeSuite = function(suite, tests) {
folder: suite.folder + '/' + suiteName, folder: suite.folder + '/' + suiteName,
tests: [], tests: [],
suites: [], suites: [],
options: suite.options options: assign({}, suite.options),
}, },
tests.slice(prevSuiteStart, tests.length) tests.slice(prevSuiteStart, tests.length)
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment