Skip to content

Commit f063dab

Browse files
authored
chore: add hint message for some known errors (#608)
1 parent 6e4430b commit f063dab

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

packages/core/src/utils/error.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from 'node:fs';
22
import { originalPositionFor, TraceMap } from '@jridgewell/trace-mapping';
33
import { type StackFrame, parse as stackTraceParse } from 'stacktrace-parser';
44
import type { FormattedError, GetSourcemap } from '../types';
5-
import { color, formatTestPath, isDebug, logger } from '../utils';
5+
import { color, formatTestPath, globalApis, isDebug, logger } from '../utils';
66

77
export async function printError(
88
error: FormattedError,
@@ -22,6 +22,24 @@ export async function printError(
2222
logger.log(`${color.red(tips.join('\n'))}\n`);
2323
return;
2424
}
25+
26+
if (error.message.includes('is not defined')) {
27+
const [, varName] = error.message.match(/(.*) is not defined/) || [];
28+
if (varName) {
29+
if ((globalApis as string[]).includes(varName)) {
30+
error.message = error.message.replace(
31+
`${varName} is not defined`,
32+
`${varName} is not defined. Did you forget to enable "globals" configuration?`,
33+
);
34+
} else if (['jest', 'vitest'].includes(varName)) {
35+
error.message = error.message.replace(
36+
`${varName} is not defined`,
37+
`${varName} is not defined. Did you mean rstest?`,
38+
);
39+
}
40+
}
41+
}
42+
2543
logger.log(
2644
`${color.red(color.bold(errorName))}${color.red(`: ${error.message}`)}\n`,
2745
);

0 commit comments

Comments
 (0)