diff --git a/index.js b/index.js index 9b4b962a2d..d3547fec27 100644 --- a/index.js +++ b/index.js @@ -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 diff --git a/lib/babel.js b/lib/babel.js index 8f78dd45c2..38177a0d9b 100644 --- a/lib/babel.js +++ b/lib/babel.js @@ -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]; @@ -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 cache.set(hash, babel.transformFileSync(testPath, options).code, 'utf8'); + } + + return code; + }) + .then(function (code) { + requireFromString(code, testPath, { + appendPaths: module.paths + }); + }); diff --git a/package.json b/package.json index 36f967c38f..9b770e57ff 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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",