Skip to content

Commit

Permalink
fixed failing exclusion test
Browse files Browse the repository at this point in the history
  • Loading branch information
danwrong committed Nov 15, 2011
1 parent 55773b7 commit 496c687
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 31 deletions.
6 changes: 5 additions & 1 deletion src/loadbuilder/asset.js
Expand Up @@ -46,7 +46,7 @@ util.extend(Script.prototype, {
this._source = fs.readFileSync(this.fullPath(), 'utf8');
}

return this._source;
return this.deferWrapper(this._source);
},
fullPath: function() {
return this.builder.path(this.id);
Expand All @@ -59,6 +59,10 @@ util.extend(Script.prototype, {
console.log(e.reason + ' line: ' + e.line +
', col: ' + e.character + '\n');
});
},
deferWrapper: function(source) {
return this.builder.options.useDeferred === true ? "deferred('" +
this.id + "', function() {\n" + source + "\n});" : source;
}
});

Expand Down
16 changes: 11 additions & 5 deletions test/asset.js
Expand Up @@ -2,15 +2,21 @@ var builder = require('loadbuilder/builder'),
asset = require('loadbuilder/asset'),
assert = require('assert');

var myBuilder = builder({
docroot: __dirname
});

module.exports = {
testAssetShouldRetrieveSource: function() {

var a = new asset.Script('fixtures/simple.js');
a.builder = myBuilder;
a.builder = builder({
docroot: __dirname
});
assert.equal("alert('hello world');", a.toSource());
},
testAssetCanBeWrappedInDeferred: function() {
var a = new asset.Script('fixtures/simple.js');
a.builder = builder({
docroot: __dirname,
useDeferred: true
});
assert.equal("deferred('fixtures/simple.js', function() {\nalert('hello world');\n});", a.toSource());
}
}
71 changes: 46 additions & 25 deletions test/builder.js
@@ -1,40 +1,61 @@
var builder = require('loadbuilder/builder'),
asset = require('loadbuilder/asset'),
assert = require('assert');
assert = require('assert'),
fs = require('fs');

var opts = {
docroot: __dirname
};

module.exports = {
// testBuildShouldProvideSourceOfAllAssetsInCollection: function() {
// assert.equal(
// "alert('hello world');\nalert('hello world again');",
// builder(opts).include('fixtures/simple.js', 'fixtures/simple2.js').toSource()
// );
// },
// testShouldDedupeAssetsInACollection: function() {
// assert.equal(
// "alert('hello world');\nalert('hello world again');",
// builder(opts).include('fixtures/simple.js', 'fixtures/simple2.js', 'fixtures/simple.js').toSource()
// );
// },
// testShouldBeAbleToExcludeFiles: function() {
// assert.equal(
// "alert('hello world');",
// builder(opts).include('fixtures/simple.js', 'fixtures/simple2.js').exclude('fixtures/simple2.js').toSource()
// );
// },
// testShouldCollectDependencies: function() {
// assert.equal(
// "alert('hello dep1');\nusing('fixtures/dep1dep.js');\nalert('hello');\nusing('fixtures/dep1.js', 'fixtures/dep2.js');",
// builder(opts).include('fixtures/has_dep.js').toSource()
// );
// },
testBuildShouldProvideSourceOfAllAssetsInCollection: function() {
assert.equal(
"alert('hello world');\nalert('hello world again');",
builder(opts).include('fixtures/simple.js', 'fixtures/simple2.js').toSource()
);
},
testShouldDedupeAssetsInACollection: function() {
assert.equal(
"alert('hello world');\nalert('hello world again');",
builder(opts).include('fixtures/simple.js', 'fixtures/simple2.js', 'fixtures/simple.js').toSource()
);
},
testShouldBeAbleToExcludeFiles: function() {
assert.equal(
"alert('hello world');",
builder(opts).include('fixtures/simple.js', 'fixtures/simple2.js').exclude('fixtures/simple2.js').toSource()
);
},
testShouldCollectDependencies: function() {
assert.equal(
"alert('hello dep1');\nusing('fixtures/dep1dep.js');\nalert('hello');\nusing('fixtures/dep1.js', 'fixtures/dep2.js');",
builder(opts).include('fixtures/has_dep.js').toSource()
);
},
testShouldExcludeDependenciesOfExcludedAsset: function() {
assert.equal(
"alert('hello');\nusing('fixtures/dep1.js', 'fixtures/dep2.js');",
builder(opts).include('fixtures/has_dep.js').exclude('fixtures/dep1.js').toSource()
);
},
testShouldBeAbleToExcludeMultipleDependencies: function() {
assert.equal(
"using('fixtures/dep1.js', 'fixtures/dep2.js');",
builder(opts).include('fixtures/has_dep.js').exclude('fixtures/dep1.js', 'fixtures/dep2.js').toSource()
);
},
testShouldBeAbleToExcludeABundle: function() {
var a = builder(opts).include('fixtures/dep1.js', 'fixtures/dep2.js');
assert.equal(
"using('fixtures/dep1.js', 'fixtures/dep2.js');",
builder(opts).include('fixtures/has_dep.js').exclude(a).toSource()
);
},
testShouldBeAbleToWriteToAFile: function() {
var path = __dirname + '/bundle.js';
builder(opts).include('fixtures/simple.js', 'fixtures/simple2.js').write(path, function() {
assert.equal("alert('hello world');\nalert('hello world again');",fs.readFileSync(path, 'utf8'));
fs.unlinkSync(path);
});
}
};

0 comments on commit 496c687

Please sign in to comment.