ava 3.11.0 → 3.11.1

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.
@@ -18,7 +18,6 @@ const colors = require('./colors');
18
18
  const formatSerializedError = require('./format-serialized-error');
19
19
  const improperUsageMessages = require('./improper-usage-messages');
20
20
  const prefixTitle = require('./prefix-title');
21
- const whileCorked = require('./while-corked');
22
21
 
23
22
  const nodeInternals = require('stack-utils').nodeInternals();
24
23
 
@@ -97,6 +96,48 @@ class LineWriterWithSpinner extends LineWriter {
97
96
  }
98
97
  }
99
98
 
99
+ function manageCorking(stream) {
100
+ let corked = false;
101
+ const cork = () => {
102
+ corked = true;
103
+ stream.cork();
104
+ };
105
+
106
+ const uncork = () => {
107
+ corked = false;
108
+ stream.uncork();
109
+ };
110
+
111
+ return {
112
+ decorateFlushingWriter(fn) {
113
+ return function (...args) {
114
+ if (corked) {
115
+ stream.uncork();
116
+ }
117
+
118
+ try {
119
+ return fn.apply(this, args);
120
+ } finally {
121
+ if (corked) {
122
+ stream.cork();
123
+ }
124
+ }
125
+ };
126
+ },
127
+
128
+ decorateWriter(fn) {
129
+ return function (...args) {
130
+ cork();
131
+ try {
132
+ return fn.apply(this, args);
133
+ } finally {
134
+ uncork();
135
+ }
136
+ };
137
+ }
138
+ };
139
+ }
140
+
100
141
  class Reporter {
101
142
  constructor({
102
143
  verbose,
@@ -112,13 +153,16 @@ class Reporter {
112
153
  this.stdStream = stdStream;
113
154
  this.watching = watching;
114
155
  this.relativeFile = file => path.relative(projectDir, file);
115
- this.consumeStateChange = whileCorked(this.reportStream, this.consumeStateChange);
156
+
157
+ const {decorateWriter, decorateFlushingWriter} = manageCorking(this.reportStream);
158
+ this.consumeStateChange = decorateWriter(this.consumeStateChange);
159
+ this.endRun = decorateWriter(this.endRun);
116
160
 
117
161
  if (this.verbose) {
118
162
  this.durationThreshold = durationThreshold || 100;
119
163
  this.spinner = null;
164
+ this.clearSpinner = () => {};
120
165
  this.lineWriter = new LineWriter(this.reportStream);
121
- this.endRun = whileCorked(this.reportStream, this.endRun);
122
166
  } else {
123
167
  this.spinner = ora({
124
168
  isEnabled: true,
@@ -128,8 +172,8 @@ class Reporter {
128
172
  spinner: spinner || (process.platform === 'win32' ? 'line' : 'dots'),
129
173
  stream: reportStream
130
174
  });
175
+ this.clearSpinner = decorateFlushingWriter(this.spinner.clear.bind(this.spinner));
131
176
  this.lineWriter = new LineWriterWithSpinner(this.reportStream, this.spinner);
132
- this.endRun = whileCorked(this.reportStream, whileCorked(this.lineWriter, this.endRun));
133
177
  }
134
178
 
135
179
  this.reset();
@@ -362,9 +406,7 @@ class Reporter {
362
406
 
363
407
  case 'worker-stderr': {
364
408
  // Forcibly clear the spinner, writing the chunk corrupts the TTY.
365
- if (this.spinner !== null) {
366
- this.spinner.clear();
367
- }
409
+ this.clearSpinner();
368
410
 
369
411
  this.stdStream.write(event.chunk);
370
412
  // If the chunk does not end with a linebreak, *forcibly* write one to
@@ -386,9 +428,7 @@ class Reporter {
386
428
 
387
429
  case 'worker-stdout': {
388
430
  // Forcibly clear the spinner, writing the chunk corrupts the TTY.
389
- if (this.spinner !== null) {
390
- this.spinner.clear();
391
- }
431
+ this.clearSpinner();
392
432
 
393
433
  this.stdStream.write(event.chunk);
394
434
  // If the chunk does not end with a linebreak, *forcibly* write one to
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ava",
3
- "version": "3.11.0",
3
+ "version": "3.11.1",
4
4
  "description": "Node.js test runner that lets you develop with confidence.",
5
5
  "license": "MIT",
6
6
  "repository": "avajs/ava",
@@ -1,13 +0,0 @@
1
- 'use strict';
2
- function whileCorked(stream, fn) {
3
- return function (...args) {
4
- stream.cork();
5
- try {
6
- fn.apply(this, args);
7
- } finally {
8
- stream.uncork();
9
- }
10
- };
11
- }
12
-
13
- module.exports = whileCorked;