File size: 5,705 Bytes
bc20498 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
'use strict'
var broccoliNodeInfo = require('..')
var chai = require('chai'), expect = chai.expect
var versions = {
'broccoli-plugin': {
'1.0.0': 'broccoli-plugin-1-0-0',
'1.1.0': 'broccoli-plugin-1-1-0',
'1.2.0': 'broccoli-plugin-1-2-0',
'1.3.0': 'broccoli-plugin-1-3-0',
},
'broccoli-source': {
'1.1.0': 'broccoli-source-1-1-0'
}
};
function forEachVersion(packageName, callback) {
for (var versionNumber in versions[packageName]) {
var aliasedPackageName = versions[packageName][versionNumber];
var entryPoint = require(aliasedPackageName);
callback(versionNumber, entryPoint);
}
}
describe('transform nodes', function() {
forEachVersion('broccoli-plugin', function(version, Plugin) {
describe('broccoli-plugin ' + version, function() {
NoopPlugin.prototype = Object.create(Plugin.prototype)
NoopPlugin.prototype.constructor = NoopPlugin
function NoopPlugin(inputNodes, options) {
Plugin.call(this, inputNodes || [], options)
}
NoopPlugin.prototype.build = function() {
}
it('has all properties', function() {
var nodeInfo = broccoliNodeInfo.getNodeInfo(new NoopPlugin)
expect(nodeInfo.nodeType).to.equal('transform')
expect(nodeInfo.name).to.equal('NoopPlugin')
expect(nodeInfo).to.have.property('annotation', undefined)
expect(nodeInfo.instantiationStack).to.be.a('string')
expect(nodeInfo.inputNodes).to.deep.equal([])
expect(nodeInfo.setup).to.be.a('function')
expect(nodeInfo.getCallbackObject).to.be.a('function')
expect(nodeInfo.persistentOutput).to.equal(false)
expect(nodeInfo.needsCache).to.equal(true)
expect(nodeInfo.fsFacade).to.equal(false)
// Check that there are no extra keys
expect(nodeInfo).to.have.keys([
'nodeType', 'name', 'annotation', 'instantiationStack',
'inputNodes', 'setup', 'getCallbackObject', 'persistentOutput',
'needsCache', 'volatile', 'trackInputChanges', 'fsFacade'
])
})
it('does not eagerly evaluate instantiationStack', function() {
var plugin = new NoopPlugin();
plugin.__broccoliGetInfo__ = function(features) {
var originalNodeInfo = NoopPlugin.prototype.__broccoliGetInfo__.call(this, features);
var nodeInfo = {}
for (var key in originalNodeInfo) {
nodeInfo[key] = originalNodeInfo[key]
}
Object.defineProperty(nodeInfo, 'instantiationStack', {
enumerable: true,
configurable: true,
get: function() {
throw new Error('Do not eagerly evaluate instantiationStack!!!!');
}
});
return nodeInfo;
};
// should not throw here at all
var nodeInfo = broccoliNodeInfo.getNodeInfo(plugin);
// ensure that we *do* throw the error if we actually access
expect(function () {
nodeInfo.instantiationStack;
}).throws(/Do not eagerly evaluate instantiationStack/);
});
})
})
})
describe('source nodes', function() {
forEachVersion('broccoli-source', function(version, broccoliSource) {
describe('broccoli-source ' + version, function() {
var classNames = { 'WatchedDir': true, 'UnwatchedDir': false }
Object.keys(classNames).forEach(function(className) {
var class_ = broccoliSource[className]
var watched = classNames[className]
describe(className, function() {
it('has all properties', function() {
var nodeInfo = broccoliNodeInfo.getNodeInfo(new class_('some/dir'))
expect(nodeInfo.nodeType).to.equal('source')
expect(nodeInfo.name).to.be.a('string')
expect(nodeInfo).to.have.property('annotation', undefined)
expect(nodeInfo.instantiationStack).to.be.a('string')
expect(nodeInfo.sourceDirectory).to.equal('some/dir')
expect(nodeInfo.watched).to.equal(watched)
// Check that there are no extra keys
expect(nodeInfo).to.have.keys(['nodeType', 'name', 'annotation', 'instantiationStack',
'sourceDirectory', 'watched'])
})
})
})
})
})
})
describe('invalid nodes', function() {
['read', 'rebuild'].forEach(function(functionName) {
it('rejects .' + functionName + '-based nodes', function() {
var node = {}
node[functionName] = function() { }
expect(function() {
broccoliNodeInfo.getNodeInfo(node)
}).to.throw(broccoliNodeInfo.InvalidNodeError, 'The .read/.rebuild API is no longer supported')
})
})
it('rejects null', function() {
expect(function() {
broccoliNodeInfo.getNodeInfo(null)
}).to.throw(broccoliNodeInfo.InvalidNodeError, 'null is not a Broccoli node')
})
it('rejects non-node objects', function() {
expect(function() {
broccoliNodeInfo.getNodeInfo({})
}).to.throw(broccoliNodeInfo.InvalidNodeError, '[object Object] is not a Broccoli node')
})
it('rejects string nodes', function() {
expect(function() {
broccoliNodeInfo.getNodeInfo('some/dir')
}).to.throw(broccoliNodeInfo.InvalidNodeError, '"some/dir": String nodes are not supported')
})
it('rejects nodes with invalid nodeType', function() {
expect(function() {
console.log(broccoliNodeInfo.getNodeInfo({
__broccoliFeatures__: { persistentOutputFlag: true, sourceDirectories: true },
__broccoliGetInfo__: function(builderFeatures) {
return { nodeType: 'foo' }
}
}))
}).to.throw(broccoliNodeInfo.InvalidNodeError, 'Unexpected nodeType: foo')
})
})
|