From 4667b3f125948259a2724f0d978c39e70d0a3196 Mon Sep 17 00:00:00 2001 From: Mikhail Losev Date: Mon, 27 Dec 2021 11:40:09 +0300 Subject: [PATCH] fix '"Cannot read property 'tests' of null" when using client scripts' (close #6305) (#6771) --- src/custom-client-scripts/client-script.ts | 2 +- src/errors/runtime/templates.js | 2 +- src/live/test-runner.js | 7 ++++++- test/server/custom-client-scripts-test.js | 4 +++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/custom-client-scripts/client-script.ts b/src/custom-client-scripts/client-script.ts index dedbb928bb..2476c5b185 100644 --- a/src/custom-client-scripts/client-script.ts +++ b/src/custom-client-scripts/client-script.ts @@ -61,7 +61,7 @@ export default class ClientScript { this.url = path || this.url; } catch (e) { - throw new GeneralError(RUNTIME_ERRORS.cannotLoadClientScriptFromPath, path); + throw new GeneralError(RUNTIME_ERRORS.cannotLoadClientScriptFromPath, path, e.message); } } diff --git a/src/errors/runtime/templates.js b/src/errors/runtime/templates.js index 44bb4f5a2e..9b0d4abd8c 100644 --- a/src/errors/runtime/templates.js +++ b/src/errors/runtime/templates.js @@ -98,7 +98,7 @@ export default { [RUNTIME_ERRORS.clientScriptInitializerIsNotSpecified]: 'Initialize your client script with one of the following: a JavaScript script, a JavaScript file path, or the name of a JavaScript module.', [RUNTIME_ERRORS.clientScriptBasePathIsNotSpecified]: 'Specify the base path for the client script file.', [RUNTIME_ERRORS.clientScriptInitializerMultipleContentSources]: 'Client scripts can only have one initializer: JavaScript code, a JavaScript file path, or the name of a JavaScript module.', - [RUNTIME_ERRORS.cannotLoadClientScriptFromPath]: 'Cannot load a client script from {path}.', + [RUNTIME_ERRORS.cannotLoadClientScriptFromPath]: 'Cannot load a client script from {path}.\n{errorMessage}', [RUNTIME_ERRORS.clientScriptModuleEntryPointPathCalculationError]: 'A client script tried to load a JavaScript module that TestCafe cannot locate:\n\n{errorMessage}.', [RUNTIME_ERRORS.methodIsNotAvailableForAnIPCHost]: 'This method cannot be called on a service host.', [RUNTIME_ERRORS.tooLargeIPCPayload]: 'The specified payload is too large to form an IPC packet.', diff --git a/src/live/test-runner.js b/src/live/test-runner.js index 64cd716da4..2f95f3ceaa 100644 --- a/src/live/test-runner.js +++ b/src/live/test-runner.js @@ -146,7 +146,7 @@ class LiveModeRunner extends Runner { } async _finishPreviousTestRuns () { - if (!this.configurationCache.tests) return; + if (!this.configurationCache?.tests) return; this.testRunController.run(); } @@ -156,6 +156,11 @@ class LiveModeRunner extends Runner { if (this.bootstrappingError) return Promise.reject(this.bootstrappingError); + else if (!this.configurationCache) { + // NOTE: Such errors handled in process.on('unhandledRejection') handler. + return Promise.reject(null); + } + return Promise.resolve(); } diff --git a/test/server/custom-client-scripts-test.js b/test/server/custom-client-scripts-test.js index ab4914d4da..695eb45ea1 100644 --- a/test/server/custom-client-scripts-test.js +++ b/test/server/custom-client-scripts-test.js @@ -187,7 +187,9 @@ describe('Client scripts', () => { expect.fail('Should throw the error'); }) .catch(e => { - expect(e.message).eql('Cannot load a client script from /non-existing-file.'); + expect(e.message).contains( + 'Cannot load a client script from /non-existing-file.\n' + + 'ENOENT: no such file or directory, open'); }); });