restructure: move bin/ and tests/ to src/

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')
This commit is contained in:
John McLear 2021-02-03 12:08:43 +00:00 committed by Richard Hansen
parent efde0b787a
commit 2ea8ea1275
146 changed files with 191 additions and 1161 deletions

View file

@ -0,0 +1,135 @@
'use strict';
describe('embed links', function () {
const objectify = function (str) {
const hash = {};
const parts = str.split('&');
for (let i = 0; i < parts.length; i++) {
const keyValue = parts[i].split('=');
hash[keyValue[0]] = keyValue[1];
}
return hash;
};
const checkiFrameCode = function (embedCode, readonly) {
// turn the code into an html element
const $embediFrame = $(embedCode);
// read and check the frame attributes
const width = $embediFrame.attr('width');
const height = $embediFrame.attr('height');
const name = $embediFrame.attr('name');
expect(width).to.be('100%');
expect(height).to.be('600');
expect(name).to.be(readonly ? 'embed_readonly' : 'embed_readwrite');
// parse the url
const src = $embediFrame.attr('src');
const questionMark = src.indexOf('?');
const url = src.substr(0, questionMark);
const paramsStr = src.substr(questionMark + 1);
const params = objectify(paramsStr);
const expectedParams = {
showControls: 'true',
showChat: 'true',
showLineNumbers: 'true',
useMonospaceFont: 'false',
};
// check the url
if (readonly) {
expect(url.indexOf('r.') > 0).to.be(true);
} else {
expect(url).to.be(helper.padChrome$.window.location.href);
}
// check if all parts of the url are like expected
expect(params).to.eql(expectedParams);
};
describe('read and write', function () {
// create a new pad before each test run
beforeEach(function (cb) {
helper.newPad(cb);
this.timeout(60000);
});
describe('the share link', function () {
it('is the actual pad url', function (done) {
const chrome$ = helper.padChrome$;
// open share dropdown
chrome$('.buttonicon-embed').click();
// get the link of the share field + the actual pad url and compare them
const shareLink = chrome$('#linkinput').val();
const padURL = chrome$.window.location.href;
expect(shareLink).to.be(padURL);
done();
});
});
describe('the embed as iframe code', function () {
it('is an iframe with the the correct url parameters and correct size', function (done) {
const chrome$ = helper.padChrome$;
// open share dropdown
chrome$('.buttonicon-embed').click();
// get the link of the share field + the actual pad url and compare them
const embedCode = chrome$('#embedinput').val();
checkiFrameCode(embedCode, false);
done();
});
});
});
describe('when read only option is set', function () {
beforeEach(function (cb) {
helper.newPad(cb);
this.timeout(60000);
});
describe('the share link', function () {
it('shows a read only url', function (done) {
const chrome$ = helper.padChrome$;
// open share dropdown
chrome$('.buttonicon-embed').click();
chrome$('#readonlyinput').click();
chrome$('#readonlyinput:checkbox:not(:checked)').attr('checked', 'checked');
// get the link of the share field + the actual pad url and compare them
const shareLink = chrome$('#linkinput').val();
const containsReadOnlyLink = shareLink.indexOf('r.') > 0;
expect(containsReadOnlyLink).to.be(true);
done();
});
});
describe('the embed as iframe code', function () {
it('is an iframe with the the correct url parameters and correct size', function (done) {
const chrome$ = helper.padChrome$;
// open share dropdown
chrome$('.buttonicon-embed').click();
// check read only checkbox, a bit hacky
chrome$('#readonlyinput').click();
chrome$('#readonlyinput:checkbox:not(:checked)').attr('checked', 'checked');
// get the link of the share field + the actual pad url and compare them
const embedCode = chrome$('#embedinput').val();
checkiFrameCode(embedCode, true);
done();
});
});
});
});