Clean comments (#6420)

* Add script to trigger test on utils

* Add new function to remove the comments from the settings file.
It reduces the size of the payload when we save on the admin page `.../admin/settings`

* Add     font-family: monospace; to the settings
This commit is contained in:
Helder Sepulveda 2024-06-04 13:32:21 -04:00 committed by GitHub
parent 2e2fb13268
commit 13e160cbe4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 53 additions and 6 deletions

View file

@ -0,0 +1,38 @@
'use strict';
import {strict as assert} from "assert";
import {cleanComments, minify} from "../../../../admin/src/utils/utils.js";
const fs = require('fs');
const fsp = fs.promises;
let template:string;
describe(__filename, function () {
before(async function () {
template = await fsp.readFile('../settings.json.template', 'utf8')
});
describe('adminUtils', function () {
it('cleanComments function empty', async function () {
assert.equal(cleanComments(""), "");
});
it('cleanComments function HelloWorld no comment', async function () {
assert.equal(cleanComments("HelloWorld"), "HelloWorld");
});
it('cleanComments function HelloWorld with comment', async function () {
assert.equal(cleanComments("Hello/*abc*/World/*def*/"), "HelloWorld");
});
it('cleanComments function HelloWorld with comment and multiline', async function () {
assert.equal(cleanComments("Hello \n/*abc\nxyz*/World/*def*/"), "Hello\nWorld");
});
it('cleanComments function HelloWorld with multiple line breaks', async function () {
assert.equal(cleanComments(" \nHello \n \n \nWorld/*def*/"), "Hello\nWorld");
});
it('cleanComments function same after minified', async function () {
assert.equal(minify(template), minify(cleanComments(template)!));
});
it('minified results are smaller', async function () {
assert.equal(minify(template).length < template.length, true);
});
});
});