-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
'use strict'; | ||
|
||
var debug = require('debug')('ava'); | ||
var hasha = require('hasha'); | ||
var cacha = require('cacha'); | ||
var join = require('path').join; | ||
|
||
var cache = cacha(join(module.paths[1], '.cache', 'ava')); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
vadimdemedes
Contributor
|
||
|
||
var opts = JSON.parse(process.argv[2]); | ||
|
||
|
@@ -36,24 +41,17 @@ sourceMapSupport.install({ | |
} | ||
}); | ||
|
||
var createEspowerPlugin = require('babel-plugin-espower/create'); | ||
var requireFromString = require('require-from-string'); | ||
var loudRejection = require('loud-rejection/api')(process); | ||
var serializeError = require('serialize-error'); | ||
var babel = require('babel-core'); | ||
var send = require('./send'); | ||
|
||
var testPath = opts.file; | ||
|
||
// initialize power-assert | ||
var powerAssert = createEspowerPlugin(babel, { | ||
patterns: require('./enhance-assert').PATTERNS | ||
}); | ||
|
||
// if generators are not supported, use regenerator | ||
var options = { | ||
presets: ['stage-2', 'es2015'], | ||
plugins: [powerAssert, 'transform-runtime'], | ||
plugins: ['transform-runtime'], | ||
sourceMaps: true | ||
}; | ||
|
||
|
@@ -70,11 +68,43 @@ if (inputSourceMap) { | |
} | ||
|
||
// include test file | ||
var transpiled = babel.transformFileSync(testPath, options); | ||
sourceMapCache[testPath] = transpiled.map; | ||
requireFromString(transpiled.code, testPath, { | ||
appendPaths: module.paths | ||
}); | ||
var cachePath = hasha(testPath); | ||
var hashPath = hasha(testPath) + '_hash'; | ||
|
||
var prevHash = cache.getSync(hashPath, {encoding: 'utf8'}); | ||
var currHash = hasha.fromFileSync(testPath); | ||
|
||
if (prevHash === currHash) { | ||
var cached = JSON.parse(cache.getSync(cachePath)); | ||
|
||
sourceMapCache[testPath] = cached.map; | ||
requireFromString(cached.code, testPath, { | ||
appendPaths: module.paths | ||
}); | ||
} else { | ||
var createEspowerPlugin = require('babel-plugin-espower/create'); | ||
var babel = require('babel-core'); | ||
|
||
// initialize power-assert | ||
var powerAssert = createEspowerPlugin(babel, { | ||
patterns: require('./enhance-assert').PATTERNS | ||
}); | ||
|
||
options.plugins.push(powerAssert); | ||
|
||
var transpiled = babel.transformFileSync(testPath, options); | ||
|
||
cache.setSync(hashPath, currHash); | ||
cache.setSync(cachePath, JSON.stringify({ | ||
code: transpiled.code, | ||
map: transpiled.map | ||
})); | ||
|
||
sourceMapCache[testPath] = transpiled.map; | ||
requireFromString(transpiled.code, testPath, { | ||
appendPaths: module.paths | ||
}); | ||
} | ||
|
||
process.on('uncaughtException', function (exception) { | ||
send('uncaughtException', {exception: serializeError(exception)}); | ||
|
module.paths[1]
- Is that a documented value? Might it be better to usefind-up('package.json')
?