ava 0.15.0 → 0.17.0

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,98 +1,36 @@
1
1
  'use strict';
2
- var opts = JSON.parse(process.argv[2]);
3
- var testPath = opts.file;
4
-
5
- // Fake TTY support
6
- if (opts.tty) {
7
- process.stdout.isTTY = true;
8
- process.stdout.columns = opts.tty.columns || 80;
9
- process.stdout.rows = opts.tty.rows;
10
-
11
- var tty = require('tty');
12
- var isatty = tty.isatty;
13
-
14
- tty.isatty = function (fd) {
15
- if (fd === 1 || fd === process.stdout) {
16
- return true;
17
- }
18
-
19
- return isatty(fd);
20
- };
21
- }
22
-
23
- var path = require('path');
24
- var fs = require('fs');
25
- var debug = require('debug')('ava');
26
- var sourceMapSupport = require('source-map-support');
27
-
28
- if (debug.enabled) {
29
- // Forward the `time-require` `--sorted` flag.
30
- // Intended for internal optimization tests only.
31
- if (opts._sorted) {
32
- process.argv.push('--sorted');
33
- }
2
+ /* eslint-disable import/order */
3
+ var process = require('./process-adapter');
34
4
 
35
- require('time-require');
36
- }
5
+ var opts = process.opts;
6
+ var testPath = opts.file;
37
7
 
38
8
  // bind globals first before anything has a chance to interfere
39
9
  var globals = require('./globals');
40
10
  globals.options = opts;
41
- var Promise = require('bluebird'); // eslint-disable-line
11
+ var Promise = require('bluebird');
42
12
 
43
13
  // Bluebird specific
44
14
  Promise.longStackTraces();
45
15
 
46
16
  (opts.require || []).forEach(require);
47
17
 
48
- var sourceMapCache = Object.create(null);
49
-
50
- sourceMapSupport.install({
51
- environment: 'node',
52
- handleUncaughtExceptions: false,
53
- retrieveSourceMap: function (source) {
54
- if (sourceMapCache[source]) {
55
- return {
56
- url: source,
57
- map: fs.readFileSync(sourceMapCache[source], 'utf8')
58
- };
59
- }
60
- }
61
- });
18
+ process.installSourceMapSupport();
62
19
 
63
- var loudRejection = require('loud-rejection/api')(process); // eslint-disable-line
20
+ var currentlyUnhandled = require('currently-unhandled')();
64
21
  var serializeError = require('./serialize-error');
65
- var send = require('./send');
22
+ var send = process.send;
66
23
  var throwsHelper = require('./throws-helper');
67
- var installPrecompiler = require('require-precompiled'); // eslint-disable-line
68
- var cacheDir = opts.cacheDir;
69
24
 
70
25
  // check if test files required ava and show error, when they didn't
71
26
  exports.avaRequired = false;
72
27
 
73
- installPrecompiler(function (filename) {
74
- var precompiled = opts.precompiled[filename];
75
-
76
- if (precompiled) {
77
- sourceMapCache[filename] = path.join(cacheDir, precompiled + '.js.map');
78
- return fs.readFileSync(path.join(cacheDir, precompiled + '.js'), 'utf8');
79
- }
80
-
81
- return null;
82
- });
28
+ process.installPrecompilerHook();
83
29
 
84
30
  var dependencies = [];
85
- Object.keys(require.extensions).forEach(function (ext) {
86
- var wrappedHandler = require.extensions[ext];
87
- require.extensions[ext] = function (module, filename) {
88
- if (filename !== testPath) {
89
- dependencies.push(filename);
90
- }
91
- wrappedHandler(module, filename);
92
- };
93
- });
31
+ process.installDependencyTracking(dependencies, testPath);
94
32
 
95
- require(testPath);
33
+ require(testPath); // eslint-disable-line import/no-dynamic-require
96
34
 
97
35
  process.on('unhandledRejection', throwsHelper);
98
36
 
@@ -120,7 +58,7 @@ process.on('ava-exit', function () {
120
58
  var delay = process.env.AVA_APPVEYOR ? 100 : 0;
121
59
 
122
60
  globals.setTimeout(function () {
123
- process.exit(0); // eslint-disable-line
61
+ process.exit(0); // eslint-disable-line xo/no-process-exit
124
62
  }, delay);
125
63
  });
126
64
 
@@ -132,7 +70,7 @@ process.on('ava-teardown', function () {
132
70
  }
133
71
  tearingDown = true;
134
72
 
135
- var rejections = loudRejection.currentlyUnhandled();
73
+ var rejections = currentlyUnhandled();
136
74
 
137
75
  if (rejections.length === 0) {
138
76
  exit();
package/lib/test.js CHANGED
@@ -13,6 +13,7 @@ var assert = require('./assert');
13
13
  var enhanceAssert = require('./enhance-assert');
14
14
  var globals = require('./globals');
15
15
  var throwsHelper = require('./throws-helper');
16
+ var formatter = enhanceAssert.formatter();
16
17
 
17
18
  function Test(title, fn, contextRef, report) {
18
19
  if (!(this instanceof Test)) {
@@ -117,7 +118,7 @@ Test.prototype.promise = function () {
117
118
  if (!this._promise) {
118
119
  this._promise = {};
119
120
 
120
- this._promise.promise = new Promise(function (resolve, reject) { // eslint-disable-line
121
+ this._promise.promise = new Promise(function (resolve, reject) { // eslint-disable-line no-use-extend-native/no-use-extend-native
121
122
  self._promise.resolve = resolve;
122
123
  self._promise.reject = reject;
123
124
  }).tap(function (result) {
@@ -188,15 +189,22 @@ Test.prototype.run = function () {
188
189
  Test.prototype._result = function () {
189
190
  var reason = this.assertError;
190
191
  var passed = reason === undefined;
192
+
191
193
  if (this.metadata.failing) {
192
194
  passed = !passed;
195
+
193
196
  if (passed) {
194
197
  reason = undefined;
195
198
  } else {
196
199
  reason = new Error('Test was expected to fail, but succeeded, you should stop marking the test as failing');
197
200
  }
198
201
  }
199
- return {passed: passed, result: this, reason: reason};
202
+
203
+ return {
204
+ passed: passed,
205
+ result: this,
206
+ reason: reason
207
+ };
200
208
  };
201
209
 
202
210
  Object.defineProperty(Test.prototype, 'end', {
@@ -218,9 +226,10 @@ Test.prototype._end = function (err) {
218
226
  operator: 'callback'
219
227
  });
220
228
  }
221
- this._setAssertError(err);
222
229
 
230
+ this._setAssertError(err);
223
231
  this.exit();
232
+
224
233
  return;
225
234
  }
226
235
 
@@ -294,8 +303,12 @@ function PublicApi(test) {
294
303
 
295
304
  function onAssertionEvent(event) {
296
305
  if (event.assertionThrew) {
297
- event.error.powerAssertContext = event.powerAssertContext;
298
- event.error.originalMessage = event.originalMessage;
306
+ if (event.powerAssertContext) {
307
+ event.error.message = formatter(event.powerAssertContext);
308
+ if (event.originalMessage) {
309
+ event.error.message = event.originalMessage + ' ' + event.error.message;
310
+ }
311
+ }
299
312
  this._test._setAssertError(event.error);
300
313
  this._test._assert(null);
301
314
  return null;
@@ -4,20 +4,22 @@ var path = require('path');
4
4
  var chalk = require('chalk');
5
5
  var globals = require('./globals');
6
6
 
7
- module.exports = function throwsHelper(error) {
7
+ module.exports = function (error) {
8
8
  if (!error || !error._avaThrowsHelperData) {
9
9
  return;
10
10
  }
11
+
11
12
  var data = error._avaThrowsHelperData;
12
13
  var codeFrame = require('babel-code-frame');
13
14
  var frame = '';
15
+
14
16
  try {
15
17
  var rawLines = fs.readFileSync(data.filename, 'utf8');
16
18
  frame = codeFrame(rawLines, data.line, data.column, {highlightCode: true});
17
- } catch (e) {
18
- console.warn(e);
19
- console.warn(e);
19
+ } catch (err) {
20
+ console.warn(err);
20
21
  }
22
+
21
23
  console.error(
22
24
  [
23
25
  'Improper usage of t.throws detected at ' + chalk.bold.yellow('%s (%d:%d)') + ':',
package/lib/watcher.js CHANGED
@@ -1,20 +1,12 @@
1
1
  'use strict';
2
2
  var nodePath = require('path');
3
3
  var debug = require('debug')('ava:watcher');
4
- var diff = require('arr-diff');
4
+ var diff = require('lodash.difference');
5
+ var chokidar = require('chokidar');
5
6
  var flatten = require('arr-flatten');
6
7
  var union = require('array-union');
7
8
  var uniq = require('array-uniq');
8
- var AvaError = require('./ava-error');
9
- var AvaFiles = require('./ava-files');
10
-
11
- function requireChokidar() {
12
- try {
13
- return require('chokidar');
14
- } catch (err) {
15
- throw new AvaError('The optional dependency chokidar failed to install and is required for --watch. Chokidar is likely not supported on your platform.');
16
- }
17
- }
9
+ var AvaFiles = require('ava-files');
18
10
 
19
11
  function rethrowAsync(err) {
20
12
  // Don't swallow exceptions. Note that any expected error should already have
@@ -26,9 +18,10 @@ function rethrowAsync(err) {
26
18
 
27
19
  function Watcher(logger, api, files, sources) {
28
20
  this.debouncer = new Debouncer(this);
29
- this.avaFiles = new AvaFiles(files, sources);
30
-
31
- this.isTest = this.avaFiles.makeTestMatcher();
21
+ this.avaFiles = new AvaFiles({
22
+ files: files,
23
+ sources: sources
24
+ });
32
25
 
33
26
  this.clearLogOnNextRun = true;
34
27
  this.runVector = 0;
@@ -96,7 +89,7 @@ Watcher.prototype.watchFiles = function () {
96
89
  var self = this;
97
90
  var patterns = this.avaFiles.getChokidarPatterns();
98
91
 
99
- requireChokidar().watch(patterns.paths, {
92
+ chokidar.watch(patterns.paths, {
100
93
  ignored: patterns.ignored,
101
94
  ignoreInitial: true
102
95
  }).on('all', function (event, path) {
@@ -110,7 +103,6 @@ Watcher.prototype.watchFiles = function () {
110
103
 
111
104
  Watcher.prototype.trackTestDependencies = function (api) {
112
105
  var self = this;
113
- var isSource = this.avaFiles.makeSourceMatcher();
114
106
 
115
107
  var relative = function (absPath) {
116
108
  return nodePath.relative('.', absPath);
@@ -118,7 +110,7 @@ Watcher.prototype.trackTestDependencies = function (api) {
118
110
 
119
111
  api.on('test-run', function (runStatus) {
120
112
  runStatus.on('dependencies', function (file, dependencies) {
121
- var sourceDeps = dependencies.map(relative).filter(isSource);
113
+ var sourceDeps = dependencies.map(relative).filter(self.avaFiles.isSource);
122
114
  self.updateTestDependencies(file, sourceDeps);
123
115
  });
124
116
  });
@@ -266,7 +258,7 @@ Watcher.prototype.runAfterChanges = function () {
266
258
  this.dirtyStates = {};
267
259
 
268
260
  var dirtyPaths = Object.keys(dirtyStates);
269
- var dirtyTests = dirtyPaths.filter(this.isTest);
261
+ var dirtyTests = dirtyPaths.filter(this.avaFiles.isTest);
270
262
  var dirtySources = diff(dirtyPaths, dirtyTests);
271
263
  var addedOrChangedTests = dirtyTests.filter(function (path) {
272
264
  return dirtyStates[path] !== 'unlink';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ava",
3
- "version": "0.15.0",
3
+ "version": "0.17.0",
4
4
  "description": "Futuristic test runner 🚀",
5
5
  "license": "MIT",
6
6
  "repository": "avajs/ava",
@@ -30,21 +30,30 @@
30
30
  "name": "Juan Soto",
31
31
  "email": "juan@juansoto.me",
32
32
  "url": "juansoto.me"
33
+ },
34
+ {
35
+ "name": "Jeroen Engels",
36
+ "email": "jfm.engels@gmail.com",
37
+ "url": "github.com/jfmengels"
33
38
  }
34
39
  ],
35
40
  "bin": "cli.js",
41
+ "typings": "types/generated.d.ts",
36
42
  "engines": {
37
43
  "node": ">=0.10.0"
38
44
  },
39
45
  "scripts": {
40
- "test": "xo && nyc --cache --reporter=lcov --reporter=text tap --no-cov --timeout=150 test/*.js test/reporters/*.js",
46
+ "test": "scripts/xo.js && nyc --cache --reporter=lcov --reporter=text tap --no-cov --timeout=150 test/*.js test/reporters/*.js",
41
47
  "test-win": "tap --no-cov --reporter=classic --timeout=150 test/*.js test/reporters/*.js",
42
- "visual": "node test/visual/run-visual-tests.js"
48
+ "visual": "node test/visual/run-visual-tests.js",
49
+ "prepublish": "npm run make-ts",
50
+ "make-ts": "babel-node --presets=babel-preset-es2015 --plugins=transform-runtime types/make.js"
43
51
  },
44
52
  "files": [
45
53
  "lib",
46
54
  "*.js",
47
- "index.d.ts"
55
+ "*.js.flow",
56
+ "types/generated.d.ts"
48
57
  ],
49
58
  "keywords": [
50
59
  "test",
@@ -77,24 +86,27 @@
77
86
  "tap"
78
87
  ],
79
88
  "dependencies": {
80
- "arr-diff": "^2.0.0",
81
89
  "arr-flatten": "^1.0.1",
82
90
  "array-union": "^1.0.1",
83
91
  "array-uniq": "^1.0.2",
84
92
  "arrify": "^1.0.0",
93
+ "auto-bind": "^0.1.0",
94
+ "ava-files": "^0.2.0",
85
95
  "ava-init": "^0.1.0",
86
- "babel-code-frame": "^6.7.5",
87
- "babel-core": "^6.3.21",
88
- "babel-plugin-ava-throws-helper": "0.0.4",
89
- "babel-plugin-detective": "^1.0.2",
90
- "babel-plugin-espower": "^2.1.0",
91
- "babel-plugin-transform-runtime": "^6.3.13",
92
- "babel-preset-es2015": "^6.3.13",
93
- "babel-preset-stage-2": "^6.3.13",
94
- "babel-runtime": "^6.3.19",
96
+ "babel-code-frame": "^6.16.0",
97
+ "babel-core": "^6.17.0",
98
+ "babel-plugin-ava-throws-helper": "^0.1.0",
99
+ "babel-plugin-detective": "^2.0.0",
100
+ "babel-plugin-espower": "^2.3.1",
101
+ "babel-plugin-transform-runtime": "^6.15.0",
102
+ "babel-preset-es2015": "^6.16.0",
103
+ "babel-preset-es2015-node4": "^2.1.0",
104
+ "babel-preset-stage-2": "^6.17.0",
105
+ "babel-runtime": "^6.11.6",
95
106
  "bluebird": "^3.0.0",
96
107
  "caching-transform": "^1.0.0",
97
108
  "chalk": "^1.0.0",
109
+ "chokidar": "^1.4.2",
98
110
  "clean-yaml-object": "^0.1.0",
99
111
  "cli-cursor": "^1.0.2",
100
112
  "cli-spinners": "^0.1.2",
@@ -103,12 +115,13 @@
103
115
  "common-path-prefix": "^1.0.0",
104
116
  "convert-source-map": "^1.2.0",
105
117
  "core-assert": "^0.2.0",
118
+ "currently-unhandled": "^0.4.1",
106
119
  "debug": "^2.2.0",
107
- "empower-core": "^0.5.0",
120
+ "empower-core": "^0.6.1",
108
121
  "figures": "^1.4.0",
109
122
  "find-cache-dir": "^0.1.1",
110
123
  "fn-name": "^2.0.0",
111
- "globby": "^4.0.0",
124
+ "get-port": "^2.1.0",
112
125
  "has-flag": "^2.0.0",
113
126
  "ignore-by-default": "^1.0.0",
114
127
  "is-ci": "^1.0.7",
@@ -118,37 +131,40 @@
118
131
  "is-promise": "^2.1.0",
119
132
  "last-line-stream": "^1.0.0",
120
133
  "lodash.debounce": "^4.0.3",
134
+ "lodash.difference": "^4.3.0",
135
+ "lodash.isequal": "^4.4.0",
121
136
  "loud-rejection": "^1.2.0",
122
137
  "matcher": "^0.1.1",
123
138
  "max-timeout": "^1.0.0",
124
139
  "md5-hex": "^1.2.0",
125
140
  "meow": "^3.7.0",
126
141
  "ms": "^0.7.1",
127
- "multimatch": "^2.1.0",
128
- "not-so-shallow": "^0.1.3",
129
142
  "object-assign": "^4.0.1",
130
143
  "observable-to-promise": "^0.4.0",
131
144
  "option-chain": "^0.1.0",
132
145
  "package-hash": "^1.1.0",
133
146
  "pkg-conf": "^1.0.1",
134
147
  "plur": "^2.0.0",
135
- "power-assert-formatter": "^1.3.0",
136
- "power-assert-renderers": "^0.1.0",
148
+ "power-assert-context-formatter": "^1.0.4",
149
+ "power-assert-renderer-assertion": "^1.0.1",
150
+ "power-assert-renderer-succinct": "^1.0.1",
137
151
  "pretty-ms": "^2.0.0",
138
152
  "repeating": "^2.0.0",
139
153
  "require-precompiled": "^0.1.0",
140
154
  "resolve-cwd": "^1.0.0",
155
+ "semver": "^5.3.0",
141
156
  "set-immediate-shim": "^1.0.1",
142
- "slash": "^1.0.0",
143
157
  "source-map-support": "^0.4.0",
144
158
  "stack-utils": "^0.4.0",
145
159
  "strip-ansi": "^3.0.1",
146
160
  "strip-bom": "^2.0.0",
147
161
  "time-require": "^0.1.2",
148
162
  "unique-temp-dir": "^1.0.0",
149
- "update-notifier": "^0.7.0"
163
+ "update-notifier": "^1.0.0"
150
164
  },
151
165
  "devDependencies": {
166
+ "babel-cli": "^6.10.1",
167
+ "babel-preset-react": "^6.5.0",
152
168
  "cli-table2": "^0.2.0",
153
169
  "coveralls": "^2.11.4",
154
170
  "delay": "^1.3.0",
@@ -159,19 +175,22 @@
159
175
  "inquirer": "^1.0.2",
160
176
  "lolex": "^1.4.0",
161
177
  "mkdirp": "^0.5.1",
162
- "nyc": "^6.0.0",
178
+ "nyc": "^9.0.1",
163
179
  "pify": "^2.3.0",
164
180
  "proxyquire": "^1.7.4",
165
181
  "rimraf": "^2.5.0",
166
- "signal-exit": "^2.1.2",
182
+ "signal-exit": "^3.0.0",
167
183
  "sinon": "^1.17.2",
168
184
  "source-map-fixtures": "^2.1.0",
169
- "tap": "^5.4.2",
185
+ "tap": "^8.0.0",
170
186
  "touch": "^1.0.0",
171
- "xo": "*",
172
- "zen-observable": "^0.2.1"
187
+ "xo": "^0.17.0",
188
+ "zen-observable": "^0.3.0"
173
189
  },
174
- "optionalDependencies": {
175
- "chokidar": "^1.4.2"
190
+ "xo": {
191
+ "rules": {
192
+ "import/newline-after-import": "off",
193
+ "no-use-extend-native/no-use-extend-native": "off"
194
+ }
176
195
  }
177
196
  }
package/profile.js CHANGED
@@ -9,7 +9,6 @@ var EventEmitter = require('events').EventEmitter;
9
9
  var meow = require('meow');
10
10
  var Promise = require('bluebird');
11
11
  var pkgConf = require('pkg-conf');
12
- var arrify = require('arrify');
13
12
  var findCacheDir = require('find-cache-dir');
14
13
  var uniqueTempDir = require('unique-temp-dir');
15
14
  var CachingPrecompiler = require('./lib/caching-precompiler');
@@ -35,12 +34,10 @@ var cli = meow([
35
34
  'Options',
36
35
  ' --fail-fast Stop after first test failure',
37
36
  ' --serial, -s Run tests serially',
38
- ' --require, -r Module to preload (Can be repeated)',
39
37
  ''
40
38
  ], {
41
39
  string: [
42
- '_',
43
- 'require'
40
+ '_'
44
41
  ],
45
42
  boolean: [
46
43
  'fail-fast',
@@ -50,7 +47,6 @@ var cli = meow([
50
47
  ],
51
48
  default: conf,
52
49
  alias: {
53
- r: 'require',
54
50
  s: 'serial'
55
51
  }
56
52
  });
@@ -60,15 +56,23 @@ if (cli.input.length !== 1) {
60
56
  }
61
57
 
62
58
  var file = path.resolve(cli.input[0]);
63
- var cacheDir = findCacheDir({name: 'ava', files: [file]}) || uniqueTempDir();
59
+ var cacheDir = findCacheDir({
60
+ name: 'ava',
61
+ files: [file]
62
+ }) || uniqueTempDir();
63
+
64
+ var precompiler = new CachingPrecompiler({
65
+ path: cacheDir,
66
+ babel: conf.babel
67
+ });
68
+
64
69
  var precompiled = {};
65
- precompiled[file] = new CachingPrecompiler(cacheDir, conf.babel).precompileFile(file);
70
+ precompiled[file] = precompiler.precompileFile(file);
66
71
 
67
72
  var opts = {
68
73
  file: file,
69
74
  failFast: cli.flags.failFast,
70
75
  serial: cli.flags.serial,
71
- require: arrify(cli.flags.require),
72
76
  tty: false,
73
77
  cacheDir: cacheDir,
74
78
  precompiled: precompiled
@@ -102,12 +106,13 @@ events.on('results', function (data) {
102
106
  if (console.profileEnd) {
103
107
  console.profileEnd();
104
108
  }
109
+
105
110
  console.log('RESULTS:', data.stats);
106
111
 
107
112
  if (process.exit) {
108
113
  // Delay is For Node 0.10 which emits uncaughtExceptions async.
109
114
  setTimeout(function () {
110
- process.exit(data.stats.failCount + uncaughtExceptionCount); // eslint-disable-line
115
+ process.exit(data.stats.failCount + uncaughtExceptionCount); // eslint-disable-line unicorn/no-process-exit
111
116
  }, 20);
112
117
  }
113
118
  });
@@ -134,5 +139,5 @@ if (console.profile) {
134
139
  }
135
140
 
136
141
  setImmediate(function () {
137
- require('./lib/test-worker');
142
+ require('./lib/test-worker'); // eslint-disable-line import/no-unassigned-import
138
143
  });