Skip to content

Commit

Permalink
Read tests from dir
Browse files Browse the repository at this point in the history
  • Loading branch information
rtsao committed Jan 15, 2016
1 parent f97b80f commit 651d297
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions test/index.js
Expand Up @@ -8,14 +8,21 @@ var scopeStyles = require('../');
var getCss = scopeStyles.getCss;
var getHash = scopeStyles.getHash;

var tests = [
'basic',
'falsy-values',
'nest-inside-media',
'no-hash',
'override-hash',
'prefix'
];
var extensions = {
source: '.source.js',
opts: '.options.json',
json: '.expected.json',
css: '.expected.css'
};

var fixtureRegex = new RegExp(extensions.source + '$');
var matchesFixture = fixtureRegex.test.bind(fixtureRegex);

var tests = fs.readdirSync('test')
.filter(matchesFixture)
.map(function toName(file) {
return path.basename(file, extensions.source);
});

tests.forEach(testFromName);

Expand All @@ -35,10 +42,10 @@ function runTest(name, source, expected, opts) {
}

function getFixtures(name) {
var sourcePath = path.join(__dirname, name + '.source.js');
var optsPath = path.join(__dirname, name + '.options.json');
var jsonPath = path.join(__dirname, name + '.expected.json');
var cssPath = path.join(__dirname, name + '.expected.css');
var sourcePath = fixturePath(name, extensions.source);
var optsPath = fixturePath(name, extensions.opts);
var jsonPath = fixturePath(name, extensions.json);
var cssPath = fixturePath(name, extensions.css);

return {
source: require(sourcePath),
Expand All @@ -57,3 +64,7 @@ function moduleExists(name) {
return false;
}
}

function fixturePath(name, ext) {
return path.join(__dirname, name + ext);
}

0 comments on commit 651d297

Please sign in to comment.