mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-30 04:09:13 -04:00

Also add symlinks from the old `bin/` and `tests/` locations to avoid breaking scripts and other tools. Motivations: * Scripts and tests no longer have to do dubious things like: require('ep_etherpad-lite/node_modules/foo') to access packages installed as dependencies in `src/package.json`. * Plugins can access the backend test helper library in a non-hacky way: require('ep_etherpad-lite/tests/backend/common') * We can delete the top-level `package.json` without breaking our ability to lint the files in `bin/` and `tests/`. Deleting the top-level `package.json` has downsides: It will cause `npm` to print warnings whenever plugins are installed, npm will no longer be able to enforce a plugin's peer dependency on ep_etherpad-lite, and npm will keep deleting the `node_modules/ep_etherpad-lite` symlink that points to `../src`. But there are significant upsides to deleting the top-level `package.json`: It will drastically speed up plugin installation because `npm` doesn't have to recursively walk the dependencies in `src/package.json`. Also, deleting the top-level `package.json` avoids npm's horrible dependency hoisting behavior (where it moves stuff from `src/node_modules/` to the top-level `node_modules/` directory). Dependency hoisting causes numerous mysterious problems such as silent failures in `npm outdated` and `npm update`. Dependency hoisting also breaks plugins that do: require('ep_etherpad-lite/node_modules/foo')
60 lines
2.1 KiB
JavaScript
60 lines
2.1 KiB
JavaScript
'use strict';
|
|
|
|
const apiHandler = require('../../node/handler/APIHandler');
|
|
const log4js = require('log4js');
|
|
const process = require('process');
|
|
const server = require('../../node/server');
|
|
const settings = require('../../node/utils/Settings');
|
|
const supertest = require('supertest');
|
|
const webaccess = require('../../node/hooks/express/webaccess');
|
|
|
|
const backups = {};
|
|
let inited = false;
|
|
|
|
exports.apiKey = apiHandler.exportedForTestingOnly.apiKey;
|
|
exports.agent = null;
|
|
exports.baseUrl = null;
|
|
exports.httpServer = null;
|
|
exports.logger = log4js.getLogger('test');
|
|
|
|
const logLevel = exports.logger.level;
|
|
|
|
// Mocha doesn't monitor unhandled Promise rejections, so convert them to uncaught exceptions.
|
|
// https://github.com/mochajs/mocha/issues/2640
|
|
process.on('unhandledRejection', (reason, promise) => { throw reason; });
|
|
|
|
exports.init = async function () {
|
|
if (inited) return exports.agent;
|
|
inited = true;
|
|
|
|
if (!logLevel.isLessThanOrEqualTo(log4js.levels.DEBUG)) {
|
|
exports.logger.warn('Disabling non-test logging for the duration of the test. ' +
|
|
'To enable non-test logging, change the loglevel setting to DEBUG.');
|
|
log4js.setGlobalLogLevel(log4js.levels.OFF);
|
|
exports.logger.setLevel(logLevel);
|
|
}
|
|
|
|
// Note: This is only a shallow backup.
|
|
backups.settings = Object.assign({}, settings);
|
|
// Start the Etherpad server on a random unused port.
|
|
settings.port = 0;
|
|
settings.ip = 'localhost';
|
|
exports.httpServer = await server.start();
|
|
exports.baseUrl = `http://localhost:${exports.httpServer.address().port}`;
|
|
exports.logger.debug(`HTTP server at ${exports.baseUrl}`);
|
|
// Create a supertest user agent for the HTTP server.
|
|
exports.agent = supertest(exports.baseUrl);
|
|
// Speed up authn tests.
|
|
backups.authnFailureDelayMs = webaccess.authnFailureDelayMs;
|
|
webaccess.authnFailureDelayMs = 0;
|
|
|
|
after(async function () {
|
|
webaccess.authnFailureDelayMs = backups.authnFailureDelayMs;
|
|
// Note: This does not unset settings that were added.
|
|
Object.assign(settings, backups.settings);
|
|
log4js.setGlobalLogLevel(logLevel);
|
|
await server.exit();
|
|
});
|
|
|
|
return exports.agent;
|
|
};
|