Skip to content

Commit

Permalink
add phantomjs node (closes #60)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Varankin committed Mar 19, 2014
1 parent 651fc96 commit 8e3f96b
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 13 deletions.
1 change: 1 addition & 0 deletions bem/nodes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = function rollRegistry(registry) {
[
'monkey',
'level',
'phantomjs',
'common',
'examples',
'tests',
Expand Down
50 changes: 50 additions & 0 deletions bem/nodes/phantomjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
var URL = require('url'),
BEM = require('bem'),
Q = require('q'),
exec = require('child_process').exec,
LOGGER = BEM.logger,
MOCHA_PHANTOM_BIN = require.resolve('mocha-phantomjs/bin/mocha-phantomjs'),
mochaReporter = process.env.MOCHA_PHANTOM_REPORTER || 'spec';

module.exports = function(registry) {

registry.decl('PhantomJsNode', 'FileNode', {

make : function() {
var _this = this,
url = URL.format({
protocol : 'file',
host : '/',
pathname : this.getPath()
}),
defer = Q.defer();

exec([MOCHA_PHANTOM_BIN, '--reporter', mochaReporter, url].join(' '), function(err, stdout, stderr) {
LOGGER.finfo('Tests results for "%s":\n%s', _this.path, stdout, stderr? '\nStderr: ' + stderr : '');

if(err === null) {
defer.resolve();
return;
}
LOGGER.error('Tests failed:', err);
defer.reject(err);
});

LOGGER.info('[i] Page was sent to Phantom (' + url + ')');

return defer.promise;
},

isValid : function() {
return Q.resolve(false);
}

}, {

createId : function(o) {
return this.__base(o) + '.phantomjs';
}

});

};
43 changes: 30 additions & 13 deletions bem/nodes/specs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var PATH = require('path'),
var FS = require('fs'),
PATH = require('path'),
BEM = require('bem'),
Q = require('q'),
U = BEM.util;
Expand Down Expand Up @@ -120,6 +121,33 @@ registry.decl('SpecNode', 'TargetBundleNode', {
this.__base(o);
},

createSourceItemNode : function(tech, bundleNode, magicNode) {
tech = 'spec.bemjson.js';
return this['create-' + tech + '-node'](tech, bundleNode, magicNode);
},

createPhantomJsNode : function(tech, bundleNode, magicNode) {
var arch = this.ctx.arch,
PhantomJsNode = registry.getNodeClass('PhantomJsNode'),
bundlePath = this.getBundlePath(tech),
opts = {
root : this.root,
path : bundlePath
};

if(arch.hasNode(PhantomJsNode.createId(opts))) {
return null;
}

var phantomJsNode = new PhantomJsNode(opts);
arch.setNode(phantomJsNode, null, arch.getNode(bundlePath));

bundleNode && arch.addParents(phantomJsNode, bundleNode);
magicNode && arch.addChildren(phantomJsNode, magicNode);

return phantomJsNode;
},

createTechNode : function(tech, bundleNode, magicNode) {
if(tech === this.item.tech) {
// Use `spec.bemjson.js` tech instead of `bemjson.js`
Expand All @@ -128,11 +156,6 @@ registry.decl('SpecNode', 'TargetBundleNode', {
return this.__base.apply(this, arguments);
},

createSourceItemNode : function(tech, bundleNode, magicNode) {
tech = 'spec.bemjson.js';
return this['create-' + tech + '-node'](tech, bundleNode, magicNode);
},

'create-spec.bemjson.js-node' : function(tech, bundleNode, magicNode) {
return this.setBemCreateNode(
tech,
Expand All @@ -143,13 +166,7 @@ registry.decl('SpecNode', 'TargetBundleNode', {
},

'create-phantomjs-node' : function(tech, bundleNode, magicNode) {
return this.setBemCreateNode(
tech,
this.level.resolveTech(tech),
bundleNode,
magicNode,
true,
false); // FIXME: false because of http://github.com/bem/bem-tools#527
return this.createPhantomJsNode('html', bundleNode, magicNode);
},

'create-spec.js+browser.js+bemhtml-node' : function(tech, bundleNode, magicNode) {
Expand Down

0 comments on commit 8e3f96b

Please sign in to comment.