|
1 | 1 | 'use strict'; |
| 2 | +var loudRejection = require('loud-rejection/api')(process); |
2 | 3 | var resolveFrom = require('resolve-from'); |
3 | 4 | var createEspowerPlugin = require('babel-plugin-espower/create'); |
4 | 5 | var requireFromString = require('require-from-string'); |
| 6 | +var serializeValue = require('./serialize-value'); |
5 | 7 |
|
6 | 8 | var hasGenerators = parseInt(process.version.slice(1), 10) > 0; |
7 | 9 | var testPath = process.argv[2]; |
@@ -32,20 +34,46 @@ module.exports = { |
32 | 34 | } |
33 | 35 | }; |
34 | 36 |
|
| 37 | +function send(name, data) { |
| 38 | + process.send({name: name, data: data}); |
| 39 | +} |
| 40 | + |
| 41 | +process.on('uncaughtException', function (exception) { |
| 42 | + send('uncaughtException', {uncaughtException: serializeValue(exception)}); |
| 43 | +}); |
| 44 | + |
35 | 45 | var transpiled = babel.transformFileSync(testPath, options); |
36 | 46 | requireFromString(transpiled.code, testPath, { |
37 | 47 | appendPaths: module.paths |
38 | 48 | }); |
39 | 49 |
|
40 | 50 | if (!avaRequired) { |
41 | | - console.error('No tests found in ' + testPath + ', make sure to import "ava" at the top of your test file'); |
42 | | - setImmediate(function () { |
43 | | - process.exit(1); |
44 | | - }); |
| 51 | + throw new Error('No tests found in ' + testPath + ', make sure to import "ava" at the top of your test file'); |
45 | 52 | } |
46 | 53 |
|
47 | 54 | process.on('message', function (message) { |
48 | | - if (message['ava-kill-command']) { |
| 55 | + var command = message['ava-child-process-command']; |
| 56 | + if (command) { |
| 57 | + process.emit('ava-' + command, message.data); |
| 58 | + } |
| 59 | +}); |
| 60 | + |
| 61 | +process.on('ava-kill', function () { |
| 62 | + setTimeout(function () { |
49 | 63 | process.exit(0); |
| 64 | + }, process.env.AVA_APPVEYOR ? 100 : 0); |
| 65 | +}); |
| 66 | + |
| 67 | +process.on('ava-cleanup', function () { |
| 68 | + var unhandled = loudRejection.currentlyUnhandled(); |
| 69 | + if (unhandled.length) { |
| 70 | + unhandled = unhandled.map(function (entry) { |
| 71 | + return serializeValue(entry.reason); |
| 72 | + }); |
| 73 | + send('unhandledRejections', {unhandledRejections: unhandled}); |
50 | 74 | } |
| 75 | + |
| 76 | + setTimeout(function () { |
| 77 | + send('cleaned-up', {}); |
| 78 | + }, 100); |
51 | 79 | }); |
0 commit comments