Skip to content
This repository was archived by the owner on Jul 21, 2020. It is now read-only.

Commit 9496210

Browse files
author
Andy Wermke
committed
Merge v0.24.0 from original AVA repo
2 parents a848c1c + e401bd1 commit 9496210

31 files changed

+2931
-5527
lines changed

api.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class Api extends EventEmitter {
5555
this.options = Object.assign({match: []}, options);
5656
this.options.require = resolveModules(arrify(this.options.require).concat('ts-node/register'));
5757
}
58+
5859
_runFile(file, runStatus, execArgv) {
5960
const hash = this.precompiler.precompileFile(file);
6061
const precompiled = Object.assign({}, this._precompiledHelpers);
@@ -71,17 +72,20 @@ class Api extends EventEmitter {
7172

7273
return emitter;
7374
}
75+
7476
run(files, options) {
7577
return new AvaFiles({cwd: this.options.resolveTestsFrom, files})
7678
.findTestFiles()
7779
.then(files => this._run(files, options));
7880
}
81+
7982
_onTimeout(runStatus) {
8083
const timeout = ms(this.options.timeout);
8184
const err = new AvaError(`Exited because no new tests completed within the last ${timeout}ms of inactivity`);
8285
this._handleError(runStatus, err);
8386
runStatus.emit('timeout');
8487
}
88+
8589
_setupTimeout(runStatus) {
8690
const timeout = ms(this.options.timeout);
8791

@@ -92,9 +96,11 @@ class Api extends EventEmitter {
9296
runStatus._restartTimer();
9397
runStatus.on('test', runStatus._restartTimer);
9498
}
99+
95100
_cancelTimeout(runStatus) {
96101
runStatus._restartTimer.cancel();
97102
}
103+
98104
_setupPrecompiler(files) {
99105
const isCacheEnabled = this.options.cacheEnabled !== false;
100106
let cacheDir = uniqueTempDir();
@@ -121,6 +127,7 @@ class Api extends EventEmitter {
121127
});
122128
});
123129
}
130+
124131
_precompileHelpers() {
125132
this._precompiledHelpers = {};
126133

@@ -136,6 +143,7 @@ class Api extends EventEmitter {
136143
this._precompiledHelpers[file] = hash;
137144
});
138145
}
146+
139147
_run(files, options) {
140148
options = options || {};
141149

@@ -175,6 +183,7 @@ class Api extends EventEmitter {
175183
return this._runWithPool(files, runStatus, concurrency);
176184
});
177185
}
186+
178187
_computeForkExecArgs(files) {
179188
const execArgv = this.options.testOnlyExecArgv || process.execArgv;
180189
let debugArgIndex = -1;
@@ -220,12 +229,14 @@ class Api extends EventEmitter {
220229
return forkExecArgv;
221230
});
222231
}
232+
223233
_handleError(runStatus, err) {
224234
runStatus.handleExceptions({
225235
exception: err,
226236
file: err.file ? path.relative(process.cwd(), err.file) : undefined
227237
});
228238
}
239+
229240
_runWithPool(files, runStatus, concurrency) {
230241
const tests = [];
231242
let execArgvList;

bench/concurrent/alternating-sync-async.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import test from '../../';
1+
import test from '../..';
22

33
for (let i = 0; i < 10000; i++) {
44
if (i % 2) {

bench/concurrent/async-immediate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import test from '../../';
1+
import test from '../..';
22

33
for (let i = 0; i < 10000; i++) {
44
test(`test${i}`, () => new Promise(resolve => setImmediate(resolve)));

bench/concurrent/async-timeout.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import test from '../../';
1+
import test from '../..';
22

33
for (let i = 0; i < 10000; i++) {
44
test(`test${i}`, () => new Promise(resolve => setTimeout(resolve, 0)));

bench/concurrent/sync.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import test from '../../';
1+
import test from '../..';
22

33
for (let i = 0; i < 10000; i++) {
44
test(`test${i}`, () => {});

bench/other/failures.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import test from '../../';
1+
import test from '../..';
22

33
for (let i = 0; i < 1000; i++) {
44
test.serial(`test${i}`, t => {

bench/serial/alternating-sync-async.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import test from '../../';
1+
import test from '../..';
22

33
for (let i = 0; i < 10000; i++) {
44
if (i % 2) {

bench/serial/async-immediate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import test from '../../';
1+
import test from '../..';
22

33
for (let i = 0; i < 10000; i++) {
44
test.serial(`test${i}`, () => new Promise(resolve => setImmediate(resolve)));

bench/serial/async-timeout.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import test from '../../';
1+
import test from '../..';
22

33
for (let i = 0; i < 3000; i++) {
44
test.serial(`test${i}`, () => new Promise(resolve => setTimeout(resolve, 0)));

bench/serial/sync.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import test from '../../';
1+
import test from '../..';
22

33
for (let i = 0; i < 10000; i++) {
44
test.serial(`test${i}`, () => {});

docs/recipes/typescript.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,23 @@ test(async (t) => {
5050
});
5151
```
5252

53+
## Working with [macros](https://github.com/avajs/ava#test-macros)
54+
55+
In order to be able to assign the `title` property to a macro:
56+
57+
```ts
58+
import test, { AssertContext, Macro } from 'ava';
59+
60+
const macro: Macro<AssertContext> = (t, input, expected) => {
61+
t.is(eval(input), expected);
62+
}
63+
64+
macro.title = (providedTitle, input, expected) => `${providedTitle} ${input} = ${expected}`.trim();
65+
66+
test(macro, '2 + 2', 4);
67+
test(macro, '2 * 3', 6);
68+
test('providedTitle', macro, '3 * 3', 9);
69+
```
5370

5471
## Working with [`context`](https://github.com/avajs/ava#test-context)
5572

lib/assert.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,25 @@ function wrapAssertions(callbacks) {
8787
if (Object.is(actual, expected)) {
8888
pass(this);
8989
} else {
90-
const actualDescriptor = concordance.describe(actual, concordanceOptions);
91-
const expectedDescriptor = concordance.describe(expected, concordanceOptions);
92-
fail(this, new AssertionError({
93-
assertion: 'is',
94-
message,
95-
raw: {actual, expected},
96-
values: [formatDescriptorDiff(actualDescriptor, expectedDescriptor)]
97-
}));
90+
const result = concordance.compare(actual, expected, concordanceOptions);
91+
const actualDescriptor = result.actual || concordance.describe(actual, concordanceOptions);
92+
const expectedDescriptor = result.expected || concordance.describe(expected, concordanceOptions);
93+
94+
if (result.pass) {
95+
fail(this, new AssertionError({
96+
assertion: 'is',
97+
message,
98+
raw: {actual, expected},
99+
values: [formatDescriptorWithLabel('Values are deeply equal to each other, but they are not the same:', actualDescriptor)]
100+
}));
101+
} else {
102+
fail(this, new AssertionError({
103+
assertion: 'is',
104+
message,
105+
raw: {actual, expected},
106+
values: [formatDescriptorDiff(actualDescriptor, expectedDescriptor)]
107+
}));
108+
}
98109
}
99110
},
100111

lib/ava-files.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ class AvaFiles {
126126

127127
autoBind(this);
128128
}
129+
129130
findTestFiles() {
130131
return handlePaths(this.files, this.excludePatterns, {
131132
cwd: this.cwd,
@@ -135,6 +136,7 @@ class AvaFiles {
135136
symlinks: Object.create(null)
136137
});
137138
}
139+
138140
findTestHelpers() {
139141
return handlePaths(defaultHelperPatterns(), ['!**/node_modules/**'], {
140142
cwd: this.cwd,
@@ -145,6 +147,7 @@ class AvaFiles {
145147
symlinks: Object.create(null)
146148
});
147149
}
150+
148151
isSource(filePath) {
149152
let mixedPatterns = [];
150153
const defaultIgnorePatterns = getDefaultIgnorePatterns();
@@ -196,6 +199,7 @@ class AvaFiles {
196199

197200
return false;
198201
}
202+
199203
isTest(filePath) {
200204
const excludePatterns = this.excludePatterns;
201205
const initialPatterns = this.files.concat(excludePatterns);
@@ -242,6 +246,7 @@ class AvaFiles {
242246
// excludePatterns into account. This mimicks the behavior in api.ts
243247
return multimatch(matchable(filePath), recursivePatterns.concat(excludePatterns)).length === 1;
244248
}
249+
245250
getChokidarPatterns() {
246251
let paths = [];
247252
let ignored = [];

lib/beautify-stack.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ let ignoreStackLines = [];
88

99
const avaInternals = /\/ava\/(?:lib\/)?[\w-]+\.js:\d+:\d+\)?$/;
1010
const avaDependencies = /\/node_modules\/(?:bluebird|empower-core|(?:ava\/node_modules\/)?(?:babel-runtime|core-js))\//;
11-
const stackFrameLine = /^.+( \(.+:[0-9]+:[0-9]+\)|:[0-9]+:[0-9]+)$/;
11+
const stackFrameLine = /^.+( \(.+:\d+:\d+\)|:\d+:\d+)$/;
1212

1313
if (!debug.enabled) {
1414
ignoreStackLines = StackUtils.nodeInternals();

lib/caching-precompiler.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class CachingPrecompiler {
1616
this.fileHashes = {};
1717
this.transform = this._createTransform();
1818
}
19+
1920
precompileFile(filePath) {
2021
if (!this.fileHashes[filePath]) {
2122
const source = stripBomBuf(fs.readFileSync(filePath));
@@ -24,13 +25,16 @@ class CachingPrecompiler {
2425

2526
return this.fileHashes[filePath];
2627
}
28+
2729
// Conditionally called by caching-transform when precompiling is required
2830
_init() {
2931
return this._transform;
3032
}
33+
3134
_transform(code) {
3235
return code.toString();
3336
}
37+
3438
_createTransform() {
3539
const salt = packageHash.sync([
3640
require.resolve('../package.json')
@@ -44,6 +48,7 @@ class CachingPrecompiler {
4448
ext: '.js'
4549
});
4650
}
51+
4752
_generateHash(code, filePath, salt) {
4853
const hash = md5Hex([code, filePath, salt]);
4954
this.fileHashes[filePath] = hash;

lib/cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ exports.run = () => {
7373
],
7474
default: {
7575
cache: conf.cache,
76-
color: 'color' in conf ? conf.color : require('supports-color') !== false,
76+
color: 'color' in conf ? conf.color : require('supports-color').stdout !== false,
7777
concurrency: conf.concurrency,
7878
failFast: conf.failFast,
7979
init: conf.init,

lib/logger.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,44 +6,51 @@ class Logger {
66
this.reporter = reporter;
77
autoBind(this);
88
}
9+
910
start(runStatus) {
1011
if (!this.reporter.start) {
1112
return;
1213
}
1314

1415
this.write(this.reporter.start(runStatus), runStatus);
1516
}
17+
1618
reset(runStatus) {
1719
if (!this.reporter.reset) {
1820
return;
1921
}
2022

2123
this.write(this.reporter.reset(runStatus), runStatus);
2224
}
25+
2326
test(test, runStatus) {
2427
this.write(this.reporter.test(test, runStatus), runStatus);
2528
}
29+
2630
unhandledError(err, runStatus) {
2731
if (!this.reporter.unhandledError) {
2832
return;
2933
}
3034

3135
this.write(this.reporter.unhandledError(err, runStatus), runStatus);
3236
}
37+
3338
finish(runStatus) {
3439
if (!this.reporter.finish) {
3540
return;
3641
}
3742

3843
this.write(this.reporter.finish(runStatus), runStatus);
3944
}
45+
4046
section() {
4147
if (!this.reporter.section) {
4248
return;
4349
}
4450

4551
this.write(this.reporter.section());
4652
}
53+
4754
clear() {
4855
if (!this.reporter.clear) {
4956
return false;
@@ -52,27 +59,31 @@ class Logger {
5259
this.write(this.reporter.clear());
5360
return true;
5461
}
62+
5563
write(str, runStatus) {
5664
if (typeof str === 'undefined') {
5765
return;
5866
}
5967

6068
this.reporter.write(str, runStatus);
6169
}
70+
6271
stdout(data, runStatus) {
6372
if (!this.reporter.stdout) {
6473
return;
6574
}
6675

6776
this.reporter.stdout(data, runStatus);
6877
}
78+
6979
stderr(data, runStatus) {
7080
if (!this.reporter.stderr) {
7181
return;
7282
}
7383

7484
this.reporter.stderr(data, runStatus);
7585
}
86+
7687
exit(code) {
7788
process.exit(code); // eslint-disable-line unicorn/no-process-exit
7889
}

lib/reporters/improper-usage-messages.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ exports.forError = error => {
1515
Visit the following URL for more details:
1616
1717
${chalk.blue.underline('https://github.com/avajs/ava#throwsfunctionpromise-error-message')}`;
18-
} else if (assertion === 'snapshot') {
18+
}
19+
20+
if (assertion === 'snapshot') {
1921
const name = error.improperUsage.name;
2022
const snapPath = error.improperUsage.snapPath;
2123

0 commit comments

Comments
 (0)