Skip to content

Commit

Permalink
simple cache by test file content hash
Browse files Browse the repository at this point in the history
  • Loading branch information
floatdrop committed Nov 11, 2015
1 parent fc201d2 commit f9ecfda
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ var hasFlag = require('has-flag');
var serializeError = require('serialize-error');
var Runner = require('./lib/runner');
var runner = new Runner();
var cache = require('cacha')('.ava/cache');

cache.clean();

// if fail-fast is enabled, use this variable to detect,
// that no more tests should be logged
Expand Down
23 changes: 18 additions & 5 deletions lib/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
var resolveFrom = require('resolve-from');
var createEspowerPlugin = require('babel-plugin-espower/create');
var requireFromString = require('require-from-string');
var hasha = require('hasha');
var cache = require('cacha')('.ava/cache');

var hasGenerators = parseInt(process.version.slice(1), 10) > 0;
var testPath = process.argv[2];
Expand All @@ -24,13 +26,24 @@ var options = {
]
};

var transpiled = babel.transformFileSync(testPath, options);
requireFromString(transpiled.code, testPath, {
appendPaths: module.paths
});

process.on('message', function (message) {
if (message['ava-kill-command']) {
process.exit(0);
}
});

var hash = hasha.fromFileSync(testPath);

cache.get(hash, 'utf8')
.then(function (code) {
if (code !== undefined) {
return code;
}

return cache.set(hash, babel.transformFileSync(testPath, options).code, 'utf8');
})
.then(function (code) {
requireFromString(code, testPath, {
appendPaths: module.paths
});
});
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"babel-plugin-espower": "^1.1.0",
"babel-runtime": "^5.8.29",
"bluebird": "^3.0.0",
"cacha": "^1.0.1",
"chalk": "^1.0.0",
"co-with-promise": "^4.6.0",
"core-assert": "^0.1.0",
Expand All @@ -75,6 +76,7 @@
"fn-name": "^2.0.0",
"globby": "^3.0.1",
"has-flag": "^1.0.0",
"hasha": "^2.0.2",
"is-generator": "^1.0.2",
"meow": "^3.3.0",
"plur": "^2.0.0",
Expand Down

0 comments on commit f9ecfda

Please sign in to comment.