ava 3.5.2 → 3.6.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.
package/index.d.ts CHANGED
@@ -308,6 +308,9 @@ export interface ExecutionContext<Context = unknown> extends Assertions {
308
308
  /** Title of the test or hook. */
309
309
  readonly title: string;
310
310
 
311
+ /** Whether the test has passed. Only accurate in afterEach hooks. */
312
+ readonly passed: boolean;
313
+
311
314
  log: LogFn;
312
315
  plan: PlanFn;
313
316
  timeout: TimeoutFn;
@@ -343,29 +346,29 @@ export interface TimeoutFn {
343
346
 
344
347
  export interface TryFn<Context = unknown> {
345
348
  /**
346
- * Requires opt-in. Attempt to run some assertions. The result must be explicitly committed or discarded or else
349
+ * Attempt to run some assertions. The result must be explicitly committed or discarded or else
347
350
  * the test will fail. A macro may be provided. The title may help distinguish attempts from
348
351
  * one another.
349
352
  */
350
353
  <Args extends any[]>(title: string, fn: EitherMacro<Args, Context>, ...args: Args): Promise<TryResult>;
351
354
 
352
355
  /**
353
- * Requires opt-in. Attempt to run some assertions. The result must be explicitly committed or discarded or else
356
+ * Attempt to run some assertions. The result must be explicitly committed or discarded or else
354
357
  * the test will fail. A macro may be provided. The title may help distinguish attempts from
355
358
  * one another.
356
359
  */
357
360
  <Args extends any[]>(title: string, fn: [EitherMacro<Args, Context>, ...Array<EitherMacro<Args, Context>>], ...args: Args): Promise<TryResult[]>;
358
361
 
359
362
  /**
360
- * Requires opt-in. Attempt to run some assertions. The result must be explicitly committed or discarded or else
361
- * the test will fail. A macro may be provided.
362
- */
363
+ * Attempt to run some assertions. The result must be explicitly committed or discarded or else
364
+ * the test will fail. A macro may be provided.
365
+ */
363
366
  <Args extends any[]>(fn: EitherMacro<Args, Context>, ...args: Args): Promise<TryResult>;
364
367
 
365
368
  /**
366
- * Requires opt-in. Attempt to run some assertions. The result must be explicitly committed or discarded or else
367
- * the test will fail. A macro may be provided.
368
- */
369
+ * Attempt to run some assertions. The result must be explicitly committed or discarded or else
370
+ * the test will fail. A macro may be provided.
371
+ */
369
372
  <Args extends any[]>(fn: [EitherMacro<Args, Context>, ...Array<EitherMacro<Args, Context>>], ...args: Args): Promise<TryResult[]>;
370
373
  }
371
374
 
package/lib/runner.js CHANGED
@@ -266,7 +266,7 @@ class Runner extends Emittery {
266
266
  return result;
267
267
  }
268
268
 
269
- async runHooks(tasks, contextRef, titleSuffix) {
269
+ async runHooks(tasks, contextRef, titleSuffix, testPassed) {
270
270
  const hooks = tasks.map(task => new Runnable({
271
271
  contextRef,
272
272
  experiments: this.experiments,
@@ -278,7 +278,8 @@ class Runner extends Emittery {
278
278
  updateSnapshots: this.updateSnapshots,
279
279
  metadata: task.metadata,
280
280
  powerAssert: this.powerAssert,
281
- title: `${task.title}${titleSuffix || ''}`
281
+ title: `${task.title}${titleSuffix || ''}`,
282
+ testPassed
282
283
  }));
283
284
  const outcome = await this.runMultiple(hooks, this.serial);
284
285
  for (const result of outcome.storedResults) {
@@ -304,10 +305,11 @@ class Runner extends Emittery {
304
305
  }
305
306
 
306
307
  async runTest(task, contextRef) {
307
- let hooksAndTestOk = false;
308
-
309
308
  const hookSuffix = ` for ${task.title}`;
310
- if (await this.runHooks(this.tasks.beforeEach, contextRef, hookSuffix)) {
309
+ let hooksOk = await this.runHooks(this.tasks.beforeEach, contextRef, hookSuffix);
310
+
311
+ let testOk = false;
312
+ if (hooksOk) {
311
313
  // Only run the test if all `beforeEach` hooks passed.
312
314
  const test = new Runnable({
313
315
  contextRef,
@@ -325,7 +327,9 @@ class Runner extends Emittery {
325
327
  });
326
328
 
327
329
  const result = await this.runSingle(test);
328
- if (result.passed) {
330
+ testOk = result.passed;
331
+
332
+ if (testOk) {
329
333
  this.emit('stateChange', {
330
334
  type: 'test-passed',
331
335
  title: result.title,
@@ -333,7 +337,8 @@ class Runner extends Emittery {
333
337
  knownFailing: result.metadata.failing,
334
338
  logs: result.logs
335
339
  });
336
- hooksAndTestOk = await this.runHooks(this.tasks.afterEach, contextRef, hookSuffix);
340
+
341
+ hooksOk = await this.runHooks(this.tasks.afterEach, contextRef, hookSuffix, testOk);
337
342
  } else {
338
343
  this.emit('stateChange', {
339
344
  type: 'test-failed',
@@ -347,8 +352,8 @@ class Runner extends Emittery {
347
352
  }
348
353
  }
349
354
 
350
- const alwaysOk = await this.runHooks(this.tasks.afterEachAlways, contextRef, hookSuffix);
351
- return hooksAndTestOk && alwaysOk;
355
+ const alwaysOk = await this.runHooks(this.tasks.afterEachAlways, contextRef, hookSuffix, testOk);
356
+ return alwaysOk && hooksOk && testOk;
352
357
  }
353
358
 
354
359
  async start() {
package/lib/test.js CHANGED
@@ -174,6 +174,10 @@ class ExecutionContext extends assert.Assertions {
174
174
  testMap.get(this).contextRef.set(context);
175
175
  }
176
176
 
177
+ get passed() {
178
+ return testMap.get(this).testPassed;
179
+ }
180
+
177
181
  _throwsArgStart(assertion, file, line) {
178
182
  testMap.get(this).trackThrows({assertion, file, line});
179
183
  }
@@ -192,6 +196,7 @@ class Test {
192
196
  this.metadata = options.metadata;
193
197
  this.powerAssert = options.powerAssert;
194
198
  this.title = options.title;
199
+ this.testPassed = options.testPassed;
195
200
  this.registerUniqueTitle = options.registerUniqueTitle;
196
201
  this.logs = [];
197
202
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ava",
3
- "version": "3.5.2",
3
+ "version": "3.6.0",
4
4
  "description": "Testing can be a drag. AVA helps you get it done.",
5
5
  "license": "MIT",
6
6
  "repository": "avajs/ava",
@@ -59,7 +59,7 @@
59
59
  "ansi-styles": "^4.2.1",
60
60
  "arrgv": "^1.0.2",
61
61
  "arrify": "^2.0.1",
62
- "chalk": "^3.0.0",
62
+ "chalk": "^4.0.0",
63
63
  "chokidar": "^3.3.1",
64
64
  "chunkd": "^2.0.1",
65
65
  "ci-info": "^2.0.0",
@@ -75,9 +75,9 @@
75
75
  "currently-unhandled": "^0.4.1",
76
76
  "debug": "^4.1.1",
77
77
  "del": "^5.1.0",
78
- "emittery": "^0.5.1",
78
+ "emittery": "^0.6.0",
79
79
  "equal-length": "^1.0.0",
80
- "figures": "^3.1.0",
80
+ "figures": "^3.2.0",
81
81
  "globby": "^11.0.0",
82
82
  "ignore-by-default": "^1.0.0",
83
83
  "import-local": "^3.0.2",
@@ -90,11 +90,11 @@
90
90
  "md5-hex": "^3.0.1",
91
91
  "ms": "^2.1.2",
92
92
  "ora": "^4.0.3",
93
- "p-map": "^3.0.0",
94
- "picomatch": "^2.2.1",
93
+ "p-map": "^4.0.0",
94
+ "picomatch": "^2.2.2",
95
95
  "pkg-conf": "^3.1.0",
96
96
  "plur": "^4.0.0",
97
- "pretty-ms": "^6.0.0",
97
+ "pretty-ms": "^6.0.1",
98
98
  "read-pkg": "^5.2.0",
99
99
  "resolve-cwd": "^3.0.0",
100
100
  "slash": "^3.0.0",
@@ -105,34 +105,32 @@
105
105
  "temp-dir": "^2.0.0",
106
106
  "trim-off-newlines": "^1.0.1",
107
107
  "update-notifier": "^4.1.0",
108
- "write-file-atomic": "^3.0.1",
109
- "yargs": "^15.1.0"
108
+ "write-file-atomic": "^3.0.3",
109
+ "yargs": "^15.3.1"
110
110
  },
111
111
  "devDependencies": {
112
112
  "@ava/babel": "^1.0.1",
113
- "@sinonjs/fake-timers": "^6.0.0",
114
- "ansi-escapes": "^4.3.0",
113
+ "@sinonjs/fake-timers": "^6.0.1",
114
+ "ansi-escapes": "^4.3.1",
115
115
  "delay": "^4.3.0",
116
116
  "esm": "^3.2.25",
117
117
  "execa": "^4.0.0",
118
118
  "get-stream": "^5.1.0",
119
- "lolex": "^5.1.2",
120
- "nyc": "^15.0.0",
119
+ "nyc": "^15.0.1",
121
120
  "p-event": "^4.1.0",
122
121
  "proxyquire": "^2.1.3",
123
- "react": "^16.12.0",
124
- "react-test-renderer": "^16.12.0",
122
+ "react": "^16.13.1",
123
+ "react-test-renderer": "^16.13.1",
125
124
  "replace-string": "^3.0.0",
126
- "sinon": "^8.1.1",
125
+ "sinon": "^9.0.1",
127
126
  "source-map-fixtures": "^2.1.0",
128
- "tap": "^14.10.6",
127
+ "tap": "^14.10.7",
129
128
  "temp-write": "^4.0.0",
130
- "tempy": "^0.4.0",
129
+ "tempy": "^0.5.0",
131
130
  "touch": "^3.1.0",
132
- "ts-node": "^8.6.2",
133
131
  "tsd": "^0.11.0",
134
132
  "typescript": "^3.7.5",
135
- "xo": "^0.28.1",
133
+ "xo": "^0.28.2",
136
134
  "zen-observable": "^0.8.15"
137
135
  },
138
136
  "xo": {
package/readme.md CHANGED
@@ -156,7 +156,6 @@ We have a growing list of [common pitfalls](docs/08-common-pitfalls.md) you may
156
156
  - [Passing arguments to your test files](docs/recipes/passing-arguments-to-your-test-files.md)
157
157
  - [Testing React components](docs/recipes/react.md)
158
158
  - [Testing Vue.js components](docs/recipes/vue.md)
159
- - [JSPM and SystemJS](docs/recipes/jspm-systemjs.md)
160
159
  - [Debugging tests with Chrome DevTools](docs/recipes/debugging-with-chrome-devtools.md)
161
160
  - [Debugging tests with VSCode](docs/recipes/debugging-with-vscode.md)
162
161
  - [Debugging tests with WebStorm](docs/recipes/debugging-with-webstorm.md)