blob: 014a4bf0d49bf2c6f92152ab6619f4a5a607cd18 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
'use strict';
const chalk = require('chalk');
exports.forError = error => {
if (!error.improperUsage) {
return null;
}
const assertion = error.assertion;
if (assertion === 'throws' || assertion === 'notThrows') {
return `Try wrapping the first argument to \`t.${assertion}()\` in a function:
${chalk.cyan(`t.${assertion}(() => { `)}${chalk.grey('/* your code here */')}${chalk.cyan(' })')}
Visit the following URL for more details:
${chalk.blue.underline('https://github.com/avajs/ava#throwsfunctionpromise-error-message')}`;
}
if (assertion === 'snapshot') {
const name = error.improperUsage.name;
const snapPath = error.improperUsage.snapPath;
if (name === 'ChecksumError') {
return `The snapshot file is corrupted.
File path: ${chalk.yellow(snapPath)}
Please run AVA again with the ${chalk.cyan('--update-snapshots')} flag to recreate it.`;
}
if (name === 'LegacyError') {
return `The snapshot file was created with AVA 0.19. It's not supported by this AVA version.
File path: ${chalk.yellow(snapPath)}
Please run AVA again with the ${chalk.cyan('--update-snapshots')} flag to upgrade.`;
}
if (name === 'VersionMismatchError') {
const snapVersion = error.improperUsage.snapVersion;
const expectedVersion = error.improperUsage.expectedVersion;
const upgradeMessage = snapVersion < expectedVersion ?
`Please run AVA again with the ${chalk.cyan('--update-snapshots')} flag to upgrade.` :
'You should upgrade AVA.';
return `The snapshot file is v${snapVersion}, but only v${expectedVersion} is supported.
File path: ${chalk.yellow(snapPath)}
${upgradeMessage}`;
}
}
return null;
};
|