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

Commit c7f5f86

Browse files
committed
Merge v0.25.0 from original AVA code base
1 parent 69dc3c2 commit c7f5f86

22 files changed

+251
-142
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ node_modules
33
coverage
44
bench/.results
55
types/generated.d.ts
6+
/package-lock.json.md5

.travis.yml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
language: node_js
22
node_js:
3+
- 9
34
- 8
45
- 6
56
- 4
@@ -8,6 +9,8 @@ env:
89
- FRESH_DEPS=true
910
matrix:
1011
exclude:
12+
- node_js: 9
13+
env: FRESH_DEPS=true
1114
- node_js: 6
1215
env: FRESH_DEPS=true
1316
- node_js: 4
@@ -16,8 +19,17 @@ cache:
1619
directories:
1720
- $HOME/.npm
1821
before_install:
19-
- npm install --global npm@5.4.2
22+
- npm install --global npm@5.6.0
2023
- npm --version
21-
install:
22-
- if [[ ${FRESH_DEPS} == "true" ]]; then npm install --no-shrinkwrap --prefer-online; else npm install --prefer-offline; fi
23-
after_success: ./node_modules/.bin/codecov --file=./coverage/lcov.info
24+
- md5sum package-lock.json > package-lock.json.md5
25+
install: |
26+
if [[ ${FRESH_DEPS} == "true" ]]; then
27+
npm install --no-shrinkwrap --prefer-online;
28+
else
29+
npm install --prefer-offline;
30+
if ! md5sum --quiet -c package-lock.json.md5; then
31+
echo "package-lock.json was modified unexpectedly. Please rebuild it using npm@$(npm -v) and commit the changes.";
32+
exit 1;
33+
fi
34+
fi
35+
after_success: npx codecov --file=./coverage/lcov.info

appveyor.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,22 @@ configuration:
1111
- LockedDeps
1212
environment:
1313
matrix:
14+
- nodejs_version: 9
1415
- nodejs_version: 8
1516
- nodejs_version: 6
1617
- nodejs_version: 4
1718
matrix:
1819
fast_finish: true
1920
exclude:
21+
- configuration: FreshDeps
22+
nodejs_version: 9
2023
- configuration: FreshDeps
2124
nodejs_version: 6
2225
- configuration: FreshDeps
2326
nodejs_version: 4
2427
install:
2528
- ps: Install-Product node $env:nodejs_version
26-
- npm install --global npm@5.4.2
29+
- npm install --global npm@5.6.0
2730
- npm --version
2831
- git config core.symlinks true
2932
- git reset --hard

cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if (importLocal(__filename)) {
88
debug('Using local install of AVA');
99
} else {
1010
if (debug.enabled) {
11-
require('time-require'); // eslint-disable-line import/no-unassigned-import
11+
require('@ladjs/time-require'); // eslint-disable-line import/no-unassigned-import
1212
}
1313

1414
try {

docs/common-pitfalls.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ test(t => {
7575
});
7676
```
7777

78+
### Helpers are not compiled when using a non-default test folder
79+
80+
This is a [known issue](https://github.com/avajs/ava/issues/1319). You should put your tests in a folder called `test` or `__tests__`.
81+
7882
---
7983

8084
Is your problem not listed here? Submit a pull request or comment on [this issue](https://github.com/avajs/ava/issues/404).

docs/recipes/babelrc.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ You can override the default Babel configuration AVA uses for test transpilation
3636
}
3737
```
3838

39+
Note that this only affects how AVA transpiles your tests. If you use `babel-register` you'll still need to add separate Babel configuration as explained [here](#transpiling-sources).
40+
3941
## Use Babel Polyfills
4042

4143
AVA lets you write your tests using new JavaScript syntax, even on Node.js versions that otherwise wouldn't support it. However, it doesn't add or modify built-ins of your current environment. Using AVA would, for example, not provide modern features such as `Array.prototype.includes()` to an underlying Node.js 4 environment.

docs/recipes/debugging-with-vscode.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Add following to the `configurations` object:
1818
"program": "${workspaceRoot}/node_modules/ava/profile.js",
1919
"args": [
2020
"${file}"
21+
],
22+
"skipFiles": [
23+
"<node_internals>/**/*.js"
2124
]
2225
}
2326
```
@@ -33,3 +36,25 @@ Save this configuration after you added it.
3336
Set breakpoints in the code **or** write `debugger;` at the point where it should stop.
3437

3538
Hit the green `Debug` button next to the list of configurations on the top left in the `Debug` view. Once the breakpoint is hit, you can evaluate variables and step through the code.
39+
40+
## Serial debugging
41+
42+
By default AVA runs tests concurrently. This may complicate debugging. Add a configuration with the `--serial` argument so AVA runs only one test at a time:
43+
44+
```json
45+
{
46+
"type": "node",
47+
"request": "launch",
48+
"name": "Run AVA test serially",
49+
"program": "${workspaceRoot}/node_modules/ava/profile.js",
50+
"args": [
51+
"--serial",
52+
"${file}"
53+
],
54+
"skipFiles": [
55+
"<node_internals>/**/*.js"
56+
]
57+
}
58+
```
59+
60+
*Note that, if your tests aren't properly isolated, certain test failures may not appear when running the tests serially.*

docs/recipes/precompiling-with-webpack.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ npm scripts:
222222
{
223223
"scripts": {
224224
"precompile-src": "cross-env NODE_ENV=test babel src --out-dir _src",
225-
"precompile-tests": "cross-env NODE_ENV=test webpack --config webpack.config.test.js",
225+
"precompile-tests": "cross-env NODE_ENV=test webpack --config webpack.config.js",
226226
"pretest": "npm run precompile-src && npm run precompile-tests",
227227
"test": "cross-env NODE_ENV=test nyc --cache ava _build"
228228
}

index.js.flow

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ type TestContext = AssertContext & {
8484
title: string;
8585
plan(count: number): void;
8686
skip: AssertContext;
87-
log(message: string): void;
87+
log(...values: Array<any>): void;
8888
};
8989
type ContextualTestContext = TestContext & { context: any; };
9090
type ContextualCallbackTestContext = TestContext & { context: any; end(): void; };

lib/assert.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,22 @@ class AssertionError extends Error {
4949

5050
if (opts.stack) {
5151
this.stack = opts.stack;
52+
} else {
53+
const limitBefore = Error.stackTraceLimit;
54+
Error.stackTraceLimit = Infinity;
55+
Error.captureStackTrace(this);
56+
Error.stackTraceLimit = limitBefore;
5257
}
5358
}
5459
}
5560
exports.AssertionError = AssertionError;
5661

5762
function getStack() {
63+
const limitBefore = Error.stackTraceLimit;
64+
Error.stackTraceLimit = Infinity;
5865
const obj = {};
5966
Error.captureStackTrace(obj, getStack);
67+
Error.stackTraceLimit = limitBefore;
6068
return obj.stack;
6169
}
6270

@@ -122,8 +130,16 @@ function wrapAssertions(callbacks) {
122130
}
123131
},
124132

125-
log(text) {
126-
log(this, text);
133+
log() {
134+
const args = Array.from(arguments, value => {
135+
return typeof value === 'string' ?
136+
value :
137+
concordance.format(value, concordanceOptions);
138+
});
139+
140+
if (args.length > 0) {
141+
log(this, args.join(' '));
142+
}
127143
},
128144

129145
deepEqual(actual, expected, message) {

lib/main.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ worker.setRunner(runner);
2323
// that no more tests should be logged
2424
let isFailed = false;
2525

26-
Error.stackTraceLimit = Infinity;
27-
2826
function test(props) {
2927
if (isFailed) {
3028
return;

lib/process-adapter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ if (opts.tty) {
4848
}
4949

5050
if (debug.enabled) {
51-
// Forward the `time-require` `--sorted` flag.
51+
// Forward the `@ladjs/time-require` `--sorted` flag.
5252
// Intended for internal optimization tests only.
5353
if (opts._sorted) {
5454
process.argv.push('--sorted');
5555
}
5656

57-
require('time-require'); // eslint-disable-line import/no-unassigned-import
57+
require('@ladjs/time-require'); // eslint-disable-line import/no-unassigned-import
5858
}
5959

6060
const sourceMapCache = new Map();

lib/reporters/tap.js

Lines changed: 25 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
'use strict';
2-
const format = require('util').format;
3-
const indentString = require('indent-string');
2+
const supertap = require('supertap');
43
const stripAnsi = require('strip-ansi');
5-
const yaml = require('js-yaml');
64

75
function dumpError(error, includeMessage) {
86
const obj = Object.assign({}, error.object);
@@ -32,7 +30,7 @@ function dumpError(error, includeMessage) {
3230
obj.at = error.stack.split('\n')[0];
3331
}
3432

35-
return ` ---\n${indentString(yaml.safeDump(obj).trim(), 4)}\n ...`;
33+
return obj;
3634
}
3735

3836
class TapReporter {
@@ -41,79 +39,42 @@ class TapReporter {
4139
}
4240

4341
start() {
44-
return 'TAP version 13';
42+
return supertap.start();
4543
}
4644

4745
test(test) {
48-
const output = [];
49-
50-
let directive = '';
51-
const passed = test.todo ? 'not ok' : 'ok';
52-
53-
if (test.todo) {
54-
directive = '# TODO';
55-
} else if (test.skip) {
56-
directive = '# SKIP';
57-
}
58-
59-
const title = stripAnsi(test.title);
60-
61-
const appendLogs = () => {
62-
if (test.logs) {
63-
test.logs.forEach(log => {
64-
const logLines = indentString(log, 4);
65-
const logLinesWithLeadingFigure = logLines.replace(
66-
/^ {4}/,
67-
' * '
68-
);
69-
70-
output.push(logLinesWithLeadingFigure);
71-
});
72-
}
73-
};
74-
75-
output.push(`# ${title}`);
76-
77-
if (test.error) {
78-
output.push(format('not ok %d - %s', ++this.i, title));
79-
appendLogs();
80-
output.push(dumpError(test.error, true));
81-
} else {
82-
output.push(format('%s %d - %s %s', passed, ++this.i, title, directive).trim());
83-
appendLogs();
84-
}
85-
86-
return output.join('\n');
46+
return supertap.test(test.title, {
47+
passed: !test.error,
48+
index: ++this.i,
49+
todo: test.todo,
50+
skip: test.skip,
51+
comment: test.logs,
52+
error: test.error ? dumpError(test.error, true) : null
53+
});
8754
}
8855

8956
unhandledError(err) {
90-
const output = [
91-
`# ${err.message}`,
92-
format('not ok %d - %s', ++this.i, err.message)
93-
];
57+
let error;
58+
9459
// AvaErrors don't have stack traces
9560
if (err.type !== 'exception' || err.name !== 'AvaError') {
96-
output.push(dumpError(err, false));
61+
error = dumpError(err, false);
9762
}
9863

99-
return output.join('\n');
64+
return supertap.test(err.message, {
65+
passed: false,
66+
index: ++this.i,
67+
error
68+
});
10069
}
10170

10271
finish(runStatus) {
103-
const output = [
104-
'',
105-
'1..' + (runStatus.passCount + runStatus.failCount + runStatus.skipCount),
106-
'# tests ' + (runStatus.passCount + runStatus.failCount + runStatus.skipCount),
107-
'# pass ' + runStatus.passCount
108-
];
109-
110-
if (runStatus.skipCount > 0) {
111-
output.push(`# skip ${runStatus.skipCount}`);
112-
}
113-
114-
output.push('# fail ' + (runStatus.failCount + runStatus.rejectionCount + runStatus.exceptionCount), '');
115-
116-
return output.join('\n');
72+
return supertap.finish({
73+
passed: runStatus.passCount,
74+
failed: runStatus.failCount,
75+
skipped: runStatus.skipCount,
76+
crashed: runStatus.rejectionCount + runStatus.exceptionCount
77+
});
11778
}
11879

11980
write(str) {

lib/test-worker.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@ globals.options = opts;
2828
const serializeError = require('./serialize-error');
2929

3030
process.env.TS_NODE_TYPE_CHECK = true;
31-
(opts.require || []).forEach(x => require(x));
31+
32+
(opts.require || []).forEach(x => {
33+
if (/[/\\]@std[/\\]esm[/\\]index\.js$/.test(x)) {
34+
require = require(x)(module); // eslint-disable-line no-global-assign
35+
} else {
36+
require(x);
37+
}
38+
});
3239

3340
adapter.installSourceMapSupport();
3441
adapter.installPrecompilerHook();

0 commit comments

Comments
 (0)