Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow test files to have different extensions with transform #324

Merged
merged 5 commits into from Mar 10, 2015
@@ -207,11 +207,16 @@ To use source transforms, you must specify a file that tells Lab how to do the t
var Babel = require('babel-core');
module.exports = [
{ext: '.js', transform: function (content, filename) {
{ext: '.js', transform: function (content, filename) {
var result = Babel.transform(content, { sourceMap: 'inline', filename: filename, sourceFileName: filename });
return result.code;
}}
// Make sure to only transform your code or the dependencies you want
if (filename.indexOf('node_modules') <= -1) {

This comment has been minimized.

Copy link
@geek

geek Mar 6, 2015

Member

I think this can be ===

var result = Babel.transform(content, { sourceMap: 'inline', filename: filename, sourceFileName: filename });
return result.code;
}
return content;
}}
];
```

@@ -12,7 +12,9 @@ var Utils = require('./utils');

// Declare internals

var internals = {};
var internals = {
pattern: new RegExp('.(js)$')

This comment has been minimized.

Copy link
@geek

geek Mar 6, 2015

Member

generally we do /.(js)$/

};


exports.run = function () {
@@ -73,7 +75,7 @@ internals.traverse = function (paths, options) {
}

if (stat.isFile() &&
/\.(js)$/.test(file) &&
internals.pattern.test(file) &&
Path.basename(file)[0] !== '.') {

files.push(file);
@@ -309,9 +311,17 @@ internals.options = function () {
var transform = require(Path.resolve(options.transform));

Hoek.assert(Array.isArray(transform), 'transform module must export an array of objects {ext: ".js", transform: null or function (content, filename)}');

options.transform = transform;

var includes = 'js|' + transform.map(internals.mapTransform).join('|');

This comment has been minimized.

Copy link
@gergoerdosi

gergoerdosi Mar 6, 2015

Contributor

This will create a wrong regex ( .(js|)$ ) if the transform module exports an empty array. Also, the dot should be escaped, below and above too.

var regex = '.(' + includes + ')$';
internals.pattern = new RegExp(regex);
}

return options;
};

internals.mapTransform = function (transform) {

return transform.ext;
};
@@ -15,7 +15,6 @@ var Transform = require('./transform');
// Declare internals

var internals = {
origLoader: require.extensions['.js'],
patterns: [],
sources: {},
transforms: [ { ext: '.js', transform: null } ]
@@ -50,7 +49,8 @@ internals.prime = function (extension) {
}
}

return internals.origLoader(localModule, filename);
var src = Fs.readFileSync(filename, 'utf8');
return localModule._compile(internals.transform(filename, src), filename);
};
};

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.