Skip to content

Commit

Permalink
error message fixes, comment fixes (#7772)
Browse files Browse the repository at this point in the history
Co-authored-by: artem-babich <[email protected]>
  • Loading branch information
titerman and Artem-Babich authored Jun 8, 2023
1 parent e824f8d commit ef85ba0
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 38 deletions.
12 changes: 6 additions & 6 deletions src/errors/runtime/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { removePreventModuleCachingSuffix } from '../test-run/utils';
import REPORTER_MODULE_PREFIX from '../../reporter/module-prefix';

const ERROR_SEPARATOR = '\n\n';
const NO_STACK_AVAILABLE_MSG = 'No stack trace available for this error';
const NO_STACK_AVAILABLE_MSG = 'No stack trace is available for this error';
const MODULE_NOT_FOUND_CODE = 'MODULE_NOT_FOUND';

function formatErrorWithCallsite (error) {
Expand Down Expand Up @@ -57,7 +57,7 @@ export class TestCompilationError extends Error {
data: [errorMessage],
});

// NOTE: stack includes message as well.
// NOTE: The stack includes the error message.
this.stack = renderTemplate(template, removePreventModuleCachingSuffix(originalError.stack));
}
}
Expand All @@ -82,7 +82,7 @@ export class APIError extends Error {
else
this.callsite = getCallsiteForMethod(callsite);

// NOTE: We need property getters here because callsite can be replaced by an external code.
// NOTE: Property getters are necessary because the callsite can be replaced with external code.
// See https://github.com/DevExpress/testcafe/blob/v1.0.0/src/compiler/test-file/formats/raw.js#L22
// Also we can't use an ES6 getter for the 'stack' property, because it will create a getter on the class prototype
// that cannot override the instance property created by the Error parent class.
Expand Down Expand Up @@ -152,7 +152,7 @@ export class ReporterPluginError extends GeneralError {
if (!err?.stack) {
const inspectedObject = util.inspect(err);

return `No stack trace is available for a raised error.\nRaised error object inspection:\n${inspectedObject}`;
return `No stack trace is available for the raised error.\nError object inspection:\n${inspectedObject}`;
}

return err.stack;
Expand Down Expand Up @@ -237,8 +237,8 @@ export class LoadReporterError extends GeneralError {
if (!isModuleNotFoundError)
return formatErrorWithCallsite(originalError);

// NOTE: ModuleNotFound error "message" property have the following pattern <message>\nRequire stack:\n<line1>\n<line2>
// We don't need to show require stack if error was produced by require('testcafe-reporter-<name>') call. If it wasn't, we need to show full require stack
// NOTE: The "message" property of the ModuleNotFound error has the following pattern: <message>\nRequire stack:\n<line1>\n<line2>.
// We need to output the full "require" stack, unless "require('testcafe-reporter-<name>')" caused the error.
const errorText = originalError.message.split('\n')[0];

if (errorText.includes(reporterFullName))
Expand Down
26 changes: 13 additions & 13 deletions src/errors/runtime/templates.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('[API] ClientFunction', function () {
only: 'chrome',
}).catch(function (errs) {
expect(errs[0].indexOf(
'ClientFunction cannot implicitly resolve the test run in context of which it should be executed.'
'ClientFunction does not have test controller access.'
)).eql(0);

expect(errs[0]).contains(' > 42 | await fn();');
Expand Down
2 changes: 1 addition & 1 deletion test/functional/fixtures/api/es-next/request/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('Request', () => {
it('Should rise an error if url is not valid', function () {
return runTests('testcafe-fixtures/request-test.js', 'Should rise an error if url is not valid', { shouldFail: true })
.catch(function (errs) {
expect(errs[0]).contains('Requested url isn\'t valid (crash).');
expect(errs[0]).contains('The request url is invalid (crash).');
expect(/await t.request\('crash'\)/.test(errs[0])).ok;
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/server/api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ describe('API', function () {
stackTop: testfile,

message: 'Cannot prepare tests due to the following error:\n\n' +
'The "invalidProp" option does not exist. Use the following options to configure skipJsErrors callback: "fn" and "dependencies".',
'The "invalidProp" option does not exist. Use the following options to configure skipJsErrors callbacks: "fn" and "dependencies".',

callsite: ' 1 |fixture`SkipJsErrors API`\n' +
' > 2 | .skipJsErrors({ fn: () => true, invalidProp: false });\n' +
Expand Down Expand Up @@ -1668,7 +1668,7 @@ describe('API', function () {
stackTop: testfile,

message: 'Cannot prepare tests due to the following error:\n\n' +
"Cannot implicitly resolve the test run in the context of which the test controller action should be executed. Use test function's 't' argument instead.",
"The action does not have implicit test controller access. Reference the 't' object to gain it.",

callsite: ' 1 |import { t } from \'testcafe\';\n' +
' 2 |\n' +
Expand Down
2 changes: 1 addition & 1 deletion test/server/cli-argument-parser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe('CLI argument parser', function () {
});

it('Should raise error if "--ports" option has less than 2 ports specified', function () {
return assertRaisesError('--ports 1337', 'The "--ports" argument accepts two values at a time.');
return assertRaisesError('--ports 1337', 'The "--ports" option requires two arguments.');
});
});

Expand Down
7 changes: 3 additions & 4 deletions test/server/configuration-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ describe('TestCafeConfiguration', function () {
}

expect(message).eql(
`Failed to parse the "${filePath}" configuration file. \n\n` +
`This file is not a well-formed JSON file. Error details:\n\n` +
`Failed to parse the "${filePath}" configuration file. The file contains invalid JSON syntax. \n\nError details:\n\n` +
`JSON5: invalid end of input at 1:2`
);
});
Expand Down Expand Up @@ -691,8 +690,8 @@ describe('TypeScriptConfiguration', function () {
fs.unlinkSync(tsConfigPath);

expect(message).eql(
`Failed to parse the "${typeScriptConfiguration.filePath}" configuration file. \n\n` +
`This file is not a well-formed JSON file. Error details:\n\n` +
`Failed to parse the "${typeScriptConfiguration.filePath}" configuration file. The file contains invalid JSON syntax. \n\n` +
`Error details:\n\n` +
`JSON5: invalid end of input at 1:2`
);
});
Expand Down
Loading

0 comments on commit ef85ba0

Please sign in to comment.