ava 0.16.0 → 0.18.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,114 +1,64 @@
1
1
  'use strict';
2
2
  /* eslint-disable import/order */
3
- var opts = JSON.parse(process.argv[2]);
4
- var testPath = opts.file;
3
+ const process = require('./process-adapter');
5
4
 
6
- // Fake TTY support
7
- if (opts.tty) {
8
- process.stdout.isTTY = true;
9
- process.stdout.columns = opts.tty.columns || 80;
10
- process.stdout.rows = opts.tty.rows;
5
+ const opts = process.opts;
6
+ const testPath = opts.file;
11
7
 
12
- var tty = require('tty');
13
- var isatty = tty.isatty;
14
-
15
- tty.isatty = function (fd) {
16
- if (fd === 1 || fd === process.stdout) {
17
- return true;
18
- }
19
-
20
- return isatty(fd);
21
- };
22
- }
23
-
24
- var path = require('path');
25
- var fs = require('fs');
26
- var debug = require('debug')('ava');
27
- var sourceMapSupport = require('source-map-support');
28
-
29
- if (debug.enabled) {
30
- // Forward the `time-require` `--sorted` flag.
31
- // Intended for internal optimization tests only.
32
- if (opts._sorted) {
33
- process.argv.push('--sorted');
34
- }
35
-
36
- require('time-require');
37
- }
38
-
39
- // bind globals first before anything has a chance to interfere
40
- var globals = require('./globals');
8
+ // Bind globals first before anything has a chance to interfere
9
+ const globals = require('./globals');
41
10
  globals.options = opts;
42
- var Promise = require('bluebird');
11
+ const Promise = require('bluebird');
43
12
 
44
13
  // Bluebird specific
45
14
  Promise.longStackTraces();
46
15
 
47
16
  (opts.require || []).forEach(require);
48
17
 
49
- var sourceMapCache = Object.create(null);
50
-
51
- sourceMapSupport.install({
52
- environment: 'node',
53
- handleUncaughtExceptions: false,
54
- retrieveSourceMap: function (source) {
55
- if (sourceMapCache[source]) {
56
- return {
57
- url: source,
58
- map: fs.readFileSync(sourceMapCache[source], 'utf8')
59
- };
60
- }
61
- }
62
- });
18
+ process.installSourceMapSupport();
63
19
 
64
- var currentlyUnhandled = require('currently-unhandled')();
65
- var serializeError = require('./serialize-error');
66
- var send = require('./send');
67
- var throwsHelper = require('./throws-helper');
68
- var installPrecompiler = require('require-precompiled');
69
- var cacheDir = opts.cacheDir;
20
+ const currentlyUnhandled = require('currently-unhandled')();
21
+ const serializeError = require('./serialize-error');
22
+ const send = process.send;
23
+ const throwsHelper = require('./throws-helper');
70
24
 
71
- // check if test files required ava and show error, when they didn't
25
+ // Check if test files required ava and show error, when they didn't
72
26
  exports.avaRequired = false;
73
27
 
74
- installPrecompiler(function (filename) {
75
- var precompiled = opts.precompiled[filename];
28
+ process.installPrecompilerHook();
76
29
 
77
- if (precompiled) {
78
- sourceMapCache[filename] = path.join(cacheDir, precompiled + '.js.map');
79
- return fs.readFileSync(path.join(cacheDir, precompiled + '.js'), 'utf8');
80
- }
30
+ const dependencies = [];
31
+ process.installDependencyTracking(dependencies, testPath);
81
32
 
82
- return null;
83
- });
84
-
85
- var dependencies = [];
86
- Object.keys(require.extensions).forEach(function (ext) {
87
- var wrappedHandler = require.extensions[ext];
88
- require.extensions[ext] = function (module, filename) {
89
- if (filename !== testPath) {
90
- dependencies.push(filename);
91
- }
92
- wrappedHandler(module, filename);
93
- };
94
- });
95
-
96
- require(testPath);
33
+ require(testPath); // eslint-disable-line import/no-dynamic-require
97
34
 
98
35
  process.on('unhandledRejection', throwsHelper);
99
36
 
100
- process.on('uncaughtException', function (exception) {
37
+ process.on('uncaughtException', exception => {
101
38
  throwsHelper(exception);
102
- send('uncaughtException', {exception: serializeError(exception)});
39
+
40
+ let serialized;
41
+ try {
42
+ serialized = serializeError(exception);
43
+ } catch (ignore) { // eslint-disable-line unicorn/catch-error-name
44
+ // Avoid using serializeError
45
+ const err = new Error('Failed to serialize uncaught exception');
46
+ serialized = {
47
+ name: err.name,
48
+ message: err.message,
49
+ stack: err.stack
50
+ };
51
+ }
52
+ send('uncaughtException', {exception: serialized});
103
53
  });
104
54
 
105
- // if ava was not required, show an error
55
+ // If AVA was not required, show an error
106
56
  if (!exports.avaRequired) {
107
57
  send('no-tests', {avaRequired: false});
108
58
  }
109
59
 
110
- // parse and re-emit ava messages
111
- process.on('message', function (message) {
60
+ // Parse and re-emit AVA messages
61
+ process.on('message', message => {
112
62
  if (!message.ava) {
113
63
  return;
114
64
  }
@@ -116,35 +66,35 @@ process.on('message', function (message) {
116
66
  process.emit(message.name, message.data);
117
67
  });
118
68
 
119
- process.on('ava-exit', function () {
120
- // use a little delay when running on AppVeyor (because it's shit)
121
- var delay = process.env.AVA_APPVEYOR ? 100 : 0;
69
+ process.on('ava-exit', () => {
70
+ // Use a little delay when running on AppVeyor (because it's shit)
71
+ const delay = process.env.AVA_APPVEYOR ? 100 : 0;
122
72
 
123
- globals.setTimeout(function () {
73
+ globals.setTimeout(() => {
124
74
  process.exit(0); // eslint-disable-line xo/no-process-exit
125
75
  }, delay);
126
76
  });
127
77
 
128
- var tearingDown = false;
129
- process.on('ava-teardown', function () {
130
- // ava-teardown can be sent more than once.
78
+ let tearingDown = false;
79
+ process.on('ava-teardown', () => {
80
+ // AVA-teardown can be sent more than once
131
81
  if (tearingDown) {
132
82
  return;
133
83
  }
134
84
  tearingDown = true;
135
85
 
136
- var rejections = currentlyUnhandled();
86
+ let rejections = currentlyUnhandled();
137
87
 
138
88
  if (rejections.length === 0) {
139
89
  exit();
140
90
  return;
141
91
  }
142
92
 
143
- rejections = rejections.map(function (rejection) {
93
+ rejections = rejections.map(rejection => {
144
94
  return serializeError(rejection.reason);
145
95
  });
146
96
 
147
- send('unhandledRejections', {rejections: rejections});
97
+ send('unhandledRejections', {rejections});
148
98
  globals.setTimeout(exit, 100);
149
99
  });
150
100
 
@@ -152,5 +102,5 @@ function exit() {
152
102
  // Include dependencies in the final teardown message. This ensures the full
153
103
  // set of dependencies is included no matter how the process exits, unless
154
104
  // it flat out crashes.
155
- send('teardown', {dependencies: dependencies});
105
+ send('teardown', {dependencies});
156
106
  }