-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes #942 This does a few things: - Moves anything used in child processes that the browser can't replicate into `lib/process-adapter.js` (so that browser implementations can implement that missing functionality). - Separates out `prefix-title` so `karma-ava` can use it. It enables use of [`karma-ava`](https://github.com/avajs/karma-ava), which is very preliminary right now, but does work: https://cloud.githubusercontent.com/assets/4082216/16401095/75720328-3caf-11e6-950d-27a9e48bbf9a.png -- This also includes two commits from #896
- Loading branch information
1 parent
01a110e
commit 204f2be
Showing
7 changed files
with
156 additions
and
133 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,25 @@ | ||
'use strict'; | ||
var path = require('path'); | ||
|
||
module.exports = function (file, base, separator) { | ||
var prefix = file | ||
.replace(base, function (match, offset) { | ||
// only replace this.base if it is found at the start of the path | ||
return offset === 0 ? '' : match; | ||
}) | ||
.replace(/\.spec/, '') | ||
.replace(/\.test/, '') | ||
.replace(/test\-/g, '') | ||
.replace(/\.js$/, '') | ||
.split(path.sep) | ||
.filter(function (p) { | ||
return p !== '__tests__'; | ||
}) | ||
.join(separator); | ||
|
||
if (prefix.length > 0) { | ||
prefix += separator; | ||
} | ||
|
||
return prefix; | ||
}; |
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,107 @@ | ||
'use strict'; | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var chalk = require('chalk'); | ||
var sourceMapSupport = require('source-map-support'); | ||
var installPrecompiler = require('require-precompiled'); | ||
|
||
var debug = require('debug')('ava'); | ||
|
||
// check if the test is being run without AVA cli | ||
var isForked = typeof process.send === 'function'; | ||
|
||
if (!isForked) { | ||
var fp = path.relative('.', process.argv[1]); | ||
|
||
console.log(); | ||
console.error('Test files must be run with the AVA CLI:\n\n ' + chalk.grey.dim('$') + ' ' + chalk.cyan('ava ' + fp) + '\n'); | ||
|
||
process.exit(1); // eslint-disable-line xo/no-process-exit | ||
} | ||
|
||
exports.send = function (name, data) { | ||
process.send({ | ||
name: 'ava-' + name, | ||
data: data, | ||
ava: true | ||
}); | ||
}; | ||
|
||
exports.on = process.on.bind(process); | ||
exports.emit = process.emit.bind(process); | ||
exports.exit = process.exit.bind(process); | ||
exports.env = process.env; | ||
|
||
var opts = exports.opts = JSON.parse(process.argv[2]); | ||
|
||
// Fake TTY support | ||
if (opts.tty) { | ||
process.stdout.isTTY = true; | ||
process.stdout.columns = opts.tty.columns || 80; | ||
process.stdout.rows = opts.tty.rows; | ||
|
||
var tty = require('tty'); | ||
var isatty = tty.isatty; | ||
|
||
tty.isatty = function (fd) { | ||
if (fd === 1 || fd === process.stdout) { | ||
return true; | ||
} | ||
|
||
return isatty(fd); | ||
}; | ||
} | ||
|
||
if (debug.enabled) { | ||
// Forward the `time-require` `--sorted` flag. | ||
// Intended for internal optimization tests only. | ||
if (opts._sorted) { | ||
process.argv.push('--sorted'); | ||
} | ||
|
||
require('time-require'); | ||
} | ||
|
||
var sourceMapCache = Object.create(null); | ||
var cacheDir = opts.cacheDir; | ||
|
||
exports.installSourceMapSupport = function () { | ||
sourceMapSupport.install({ | ||
environment: 'node', | ||
handleUncaughtExceptions: false, | ||
retrieveSourceMap: function (source) { | ||
if (sourceMapCache[source]) { | ||
return { | ||
url: source, | ||
map: fs.readFileSync(sourceMapCache[source], 'utf8') | ||
}; | ||
} | ||
} | ||
}); | ||
}; | ||
|
||
exports.installPrecompilerHook = function () { | ||
installPrecompiler(function (filename) { | ||
var precompiled = opts.precompiled[filename]; | ||
|
||
if (precompiled) { | ||
sourceMapCache[filename] = path.join(cacheDir, precompiled + '.js.map'); | ||
return fs.readFileSync(path.join(cacheDir, precompiled + '.js'), 'utf8'); | ||
} | ||
|
||
return null; | ||
}); | ||
}; | ||
|
||
exports.installDependencyTracking = function (dependencies, testPath) { | ||
Object.keys(require.extensions).forEach(function (ext) { | ||
var wrappedHandler = require.extensions[ext]; | ||
require.extensions[ext] = function (module, filename) { | ||
if (filename !== testPath) { | ||
dependencies.push(filename); | ||
} | ||
|
||
wrappedHandler(module, filename); | ||
}; | ||
}); | ||
}; |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.