Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
Added plugin/preprocessor support
Browse files Browse the repository at this point in the history
  • Loading branch information
lebek committed Jul 23, 2013
1 parent e37c99c commit 5147106
Showing 1 changed file with 51 additions and 2 deletions.
53 changes: 51 additions & 2 deletions lib/cli.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var util = require('util');
var path = require('path')
var path = require('path');
var fs = require('fs');
var webdriver = require('selenium-webdriver');
var remote = require('selenium-webdriver/remote');
Expand All @@ -25,7 +25,7 @@ var config = {
showColors: true,
includeStackTrace: true
}
}
};

var originalOnComplete = config.jasmineNodeOpts.onComplete;

Expand Down Expand Up @@ -59,11 +59,57 @@ var printVersion = function () {
process.exit(0);
};

var requirePlugin = function(name) {
util.puts('Loading plugin: ' + name);
try {
return require(name);
} catch (e) {
if (e.code === 'MODULE_NOT_FOUND' && e.message.indexOf(name) !== -1) {
throw new Error('Cannot find plugin: ' + name);
} else {
throw new Error('Error during loading ' + name + ' plugin: ' + e.message);
}
}
};

var preprocess = function (originalPath, preprocessors) {
var env = process.env;
var tmp = env.TMPDIR || env.TMP || env.TEMP || '/tmp';
var contentPath = tmp + '/' + path.basename(originalPath) + '.js';

var nextPreprocessor = function(content) {
if (!preprocessors.length) {
return fs.writeFileSync(contentPath, content);
}

preprocessors.shift()(originalPath, content, nextPreprocessor);
};

nextPreprocessor(fs.readFileSync(originalPath).toString());

return contentPath;
};

var run = function() {
if (config.jasmineNodeOpts.specFolders) {
throw new Error('Using config.jasmineNodeOpts.specFolders is deprecated ' +
'in Protractor 0.6.0. Please switch to config.specs.');
}

var plugins = [];
var preprocessors = [];
if (config.plugins) {
plugins = config.plugins;
for (var i = 0; i < plugins.length; ++i) {
var plugin = requirePlugin(plugins[i]);
for (key in plugin) {
if (key.substring(0, 13) == "preprocessor:") {
preprocessors.push(plugin[key]);
}
}
}
}

// Check the specs.
// TODO(ralphj): Interpret patterns from the specs, e.g.
// 'specs/*.js'
Expand All @@ -74,7 +120,10 @@ var run = function() {
if (!fs.existsSync(specs[i])) {
throw new Error('Test file ' + specs[i] + ' not found.');
}

specs[i] = preprocess(specs[i], preprocessors);
}

minijn.addSpecs(specs);

if (config.sauceUser && config.sauceKey) {
Expand Down

0 comments on commit 5147106

Please sign in to comment.