Skip to content

Commit

Permalink
fix '"Cannot read property 'tests' of null" when using client scripts' (
Browse files Browse the repository at this point in the history
close #6305) (#6771)
  • Loading branch information
miherlosev committed Dec 27, 2021
1 parent 17c5082 commit 4667b3f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/custom-client-scripts/client-script.ts
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/errors/runtime/templates.js
Expand Up @@ -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.',
Expand Down
7 changes: 6 additions & 1 deletion src/live/test-runner.js
Expand Up @@ -146,7 +146,7 @@ class LiveModeRunner extends Runner {
}

async _finishPreviousTestRuns () {
if (!this.configurationCache.tests) return;
if (!this.configurationCache?.tests) return;

this.testRunController.run();
}
Expand All @@ -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();
}

Expand Down
4 changes: 3 additions & 1 deletion test/server/custom-client-scripts-test.js
Expand Up @@ -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');
});
});

Expand Down

0 comments on commit 4667b3f

Please sign in to comment.