1 | 'use strict';
|
2 | var loudRejection = require('loud-rejection/api')(process);
|
3 | var resolveFrom = require('resolve-from');
|
4 | var createEspowerPlugin = require('babel-plugin-espower/create');
|
5 | var requireFromString = require('require-from-string');
|
6 | var serializeValue = require('./serialize-value');
|
7 |
|
8 | var hasGenerators = parseInt(process.version.slice(1), 10) > 0;
|
9 | var testPath = process.argv[2];
|
10 | var babel;
|
11 |
|
12 | try {
|
13 | var localBabel = resolveFrom('.', 'babel-core') || resolveFrom('.', 'babel');
|
14 | babel = require(localBabel);
|
15 | } catch (err) {
|
16 | babel = require('babel-core');
|
17 | }
|
18 |
|
19 | var options = {
|
20 | blacklist: hasGenerators ? ['regenerator'] : [],
|
21 | optional: hasGenerators ? ['asyncToGenerator', 'runtime'] : ['runtime'],
|
22 | plugins: [
|
23 | createEspowerPlugin(babel, {
|
24 | patterns: require('./enhance-assert').PATTERNS
|
25 | })
|
26 | ]
|
27 | };
|
28 |
|
29 | var avaRequired;
|
30 |
|
31 | module.exports = {
|
32 | avaRequired: function () {
|
33 | avaRequired = true;
|
34 | }
|
35 | };
|
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 |
|
45 | var transpiled = babel.transformFileSync(testPath, options);
|
46 | requireFromString(transpiled.code, testPath, {
|
47 | appendPaths: module.paths
|
48 | });
|
49 |
|
50 | if (!avaRequired) {
|
51 | throw new Error('No tests found in ' + testPath + ', make sure to import "ava" at the top of your test file');
|
52 | }
|
53 |
|
54 | process.on('message', function (message) {
|
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 () {
|
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});
|
74 | }
|
75 |
|
76 | setTimeout(function () {
|
77 | send('cleaned-up', {});
|
78 | }, 100);
|
79 | });
|