This repository has been archived by the owner on Oct 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
buildTree/buildSFX/compileOutputs take optional compiler cache
- Loading branch information
Showing
4 changed files
with
99 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
define([], function(module) { | ||
console.log('I hate caches'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
var Builder = require('../index'); | ||
var expect = require('chai').expect; | ||
|
||
suite('Test compiler cache', function() { | ||
var builder = new Builder('test/fixtures/test-cache-tree'); | ||
builder.config({ transpiler: 'babel' }); | ||
|
||
test('Use cache entry when available', function() { | ||
var loadName = 'simple.js'; | ||
var outputPath = 'test/output/cached.js'; | ||
var cache = {}; | ||
var tree; | ||
|
||
return builder.trace(loadName).then(function(_tree) { | ||
tree = _tree; | ||
return builder.buildTree(tree, null, {}, cache); | ||
}) | ||
.then(function(output) { | ||
var cacheEntry = cache[loadName]; | ||
expect(cacheEntry).to.be.an('object'); | ||
expect(cacheEntry.sourceHash).to.be.a('string'); | ||
var cacheOutput = cacheEntry.output; | ||
expect(cacheOutput).to.be.an('object'); | ||
|
||
// poison cache | ||
cacheOutput.source = cacheOutput.source.replace('hate', 'love'); | ||
|
||
return builder.buildTree(tree, null, {}, cache); | ||
}) | ||
.then(function(output) { | ||
// verify buildTree use poisoned cache rather than recompiling | ||
var outputSource = output.source; | ||
expect(outputSource).not.to.contain('hate caches'); | ||
expect(outputSource).to.contain('love caches'); | ||
|
||
// invalidate poisoned cache entry and rebuild | ||
cache[loadName].sourceHash = 'out of date'; | ||
return builder.buildTree(tree, null, {}, cache); | ||
}) | ||
.then(function(output) { | ||
// verify original source is used once more | ||
var outputSource = output.source; | ||
expect(outputSource).to.contain('hate caches'); | ||
expect(outputSource).not.to.contain('love caches'); | ||
}); | ||
}); | ||
}); |