tests: Use require() to load frontend test specs

This makes core and plugin tests consistent with each other, makes it
possible to `require()` relative paths in spec files, simplifies the
code somewhat, and should make it easier to move away from
require-kernel.

Also:
  * Wrap plugin tests inside a `describe()` that contains the plugin
    name to make it easier to grep for a plugin's tests and for
    consistency with core tests.
  * Add "<core>" to the core test descriptions to make it easier to
    distinguish them from plugin tests.
This commit is contained in:
Richard Hansen 2021-05-08 19:28:08 -04:00
parent d8eb79428f
commit e4f011df76
3 changed files with 38 additions and 38 deletions

View file

@ -141,9 +141,17 @@ $(() => {
require.setLibraryURI(absUrl('../../javascripts/lib'));
require.setGlobalKeyPath('require');
const $body = $('body');
for (const spec of window.frontendTestSpecs.map((spec) => encodeURI(spec))) {
$body.append($('<script>').attr('src', spec.startsWith('/') ? spec : `specs/${spec}`));
// This loads the test specs serially. While it is technically possible to load them in parallel,
// the code would be very complex (it involves wrapping require.define(), configuring
// require-kernel to use the wrapped .define() via require.setGlobalKeyPath(), and using the
// asynchronous form of require()). In addition, the performance gains would be minimal because
// require-kernel only loads 2 at a time by default. (Increasing the default could cause problems
// because browsers like to limit the number of concurrent fetches.)
for (const spec of window.frontendTestSpecs) {
const desc = spec
.replace(/^ep_etherpad-lite\/tests\/frontend\/specs\//, '<core> ')
.replace(/^([^/ ]*)\/static\/tests\/frontend\/specs\//, '<$1> ');
describe(`${desc}.js`, function () { require(spec); });
}
// initialize the test helper