From 3de6dc9f68a32fb5f0b517d61bc4543cdd9275d6 Mon Sep 17 00:00:00 2001 From: rugk Date: Tue, 3 Mar 2026 11:01:30 +0000 Subject: [PATCH] test: use cleanup function everywhere instead of jsdom manually --- js/test/AttachmentViewer.js | 4 ++-- js/test/Check.js | 6 ++--- js/test/CopyToClipboard.js | 12 +++++----- js/test/CryptTool.js | 8 +++---- js/test/DiscussionViewer.js | 2 +- js/test/Editor.js | 2 +- js/test/Helper.js | 16 +++++++------- js/test/I18n.js | 14 ++++++------ js/test/Model.js | 16 +++++++------- js/test/PasteStatus.js | 43 ++++++++++++++++++------------------ js/test/PasteViewer.js | 9 ++++---- js/test/Prompt.js | 2 +- js/test/ServerInteraction.js | 2 +- js/test/TopNav.js | 32 +++++++++++---------------- js/test/UiHelper.js | 8 +++---- 15 files changed, 84 insertions(+), 92 deletions(-) diff --git a/js/test/AttachmentViewer.js b/js/test/AttachmentViewer.js index 4ee5df85..37d9a873 100644 --- a/js/test/AttachmentViewer.js +++ b/js/test/AttachmentViewer.js @@ -14,7 +14,7 @@ describe('AttachmentViewer', function () { 'string', // eslint-disable-next-line complexity function (mimeType, rawdata, filename, prefix, postfix) { - let clean = jsdom(), + let clean = globalThis.cleanup(), data = 'data:' + mimeType + ';base64,' + common.btoa(rawdata), mimePrefix = mimeType.substring(0, 6), previewSupported = ( @@ -133,7 +133,7 @@ describe('AttachmentViewer', function () { it( 'sanitizes file names in attachments', function() { - const clean = jsdom(); + const clean = globalThis.cleanup(); $('body').html( '' + '' + diff --git a/js/test/Check.js b/js/test/Check.js index 79fdfc26..011db36a 100644 --- a/js/test/Check.js +++ b/js/test/Check.js @@ -12,7 +12,7 @@ describe('Check', function () { jsc.elements(['Bot', 'bot']), 'string', function (prefix, botBit, suffix) { - const clean = jsdom( + const clean = globalThis.cleanup( '' + '', { 'userAgent': prefix + botBit + suffix @@ -36,7 +36,7 @@ describe('Check', function () { function (secureProtocol, localhost, domain, tld) { const isDomain = localhost === '', isSecureContext = secureProtocol || !isDomain || tld.length > 0, - clean = jsdom( + clean = globalThis.cleanup( '' + '' + '', @@ -63,7 +63,7 @@ describe('Check', function () { 'bool', jsc.nearray(common.jscA2zString()), function (secureProtocol, domain) { - const clean = jsdom( + const clean = globalThis.cleanup( '' + '', { diff --git a/js/test/CopyToClipboard.js b/js/test/CopyToClipboard.js index 692b700c..e91ad50c 100644 --- a/js/test/CopyToClipboard.js +++ b/js/test/CopyToClipboard.js @@ -9,7 +9,7 @@ describe('CopyToClipboard', function() { common.jscFormats(), 'nestring', async function (format, text) { - var clean = jsdom(); + var clean = globalThis.cleanup(); common.enableClipboard(); $('body').html( @@ -46,7 +46,7 @@ describe('CopyToClipboard', function() { common.jscFormats(), 'nestring', async function (format, text) { - var clean = jsdom(); + var clean = globalThis.cleanup(); common.enableClipboard(); $('body').html( @@ -80,7 +80,7 @@ describe('CopyToClipboard', function() { jsc.property('Copy link to clipboard', 'nestring', async function (text) { - var clean = jsdom(); + var clean = globalThis.cleanup(); common.enableClipboard(); $('body').html(''); @@ -103,7 +103,7 @@ describe('CopyToClipboard', function() { jsc.property('Show hint', 'nestring', function (text) { - var clean = jsdom(); + var clean = globalThis.cleanup(); $('body').html(''); @@ -121,7 +121,7 @@ describe('CopyToClipboard', function() { jsc.property('Hide hint', 'nestring', function (text) { - var clean = jsdom(); + var clean = globalThis.cleanup(); $('body').html('' + text + ''); @@ -136,4 +136,4 @@ describe('CopyToClipboard', function() { } ); }); -}); \ No newline at end of file +}); diff --git a/js/test/CryptTool.js b/js/test/CryptTool.js index 4db3ef90..f217b426 100644 --- a/js/test/CryptTool.js +++ b/js/test/CryptTool.js @@ -15,7 +15,7 @@ describe('CryptTool', function () { 'string', 'string', async function (key, password, message) { - const clean = jsdom(); + const clean = globalThis.cleanup(); // ensure zlib is getting loaded PrivateBin.Controller.initZ(); Object.defineProperty(window, 'crypto', { @@ -42,7 +42,7 @@ describe('CryptTool', function () { it('does not truncate messages', async function () { const message = fs.readFileSync('test/compression-sample.txt', 'ascii').trim(), - clean = jsdom(); + clean = globalThis.cleanup(); Object.defineProperty(window, 'crypto', { value: new WebCrypto(), writeable: false @@ -91,7 +91,7 @@ isWhile : interp (while expr sBody) (MemElem mem) = ======================== ( 1 / 1 ) conseq_or_bottom inv (interp (nth_iterate sBody n) (MemElem mem)) `; - const clean = jsdom(); + const clean = globalThis.cleanup(); // ensure zlib is getting loaded PrivateBin.Controller.initZ(); Object.defineProperty(window, 'crypto', { @@ -123,7 +123,7 @@ conseq_or_bottom inv (interp (nth_iterate sBody n) (MemElem mem)) jsc.assert(jsc.forall( 'integer', function(counter) { - const clean = jsdom(); + const clean = globalThis.cleanup(); Object.defineProperty(window, 'crypto', { value: new WebCrypto(), writeable: false diff --git a/js/test/DiscussionViewer.js b/js/test/DiscussionViewer.js index 0203ddd5..a44b7cac 100644 --- a/js/test/DiscussionViewer.js +++ b/js/test/DiscussionViewer.js @@ -26,7 +26,7 @@ describe('DiscussionViewer', function () { jsc.elements(['loading', 'danger', 'other']), 'nestring', function (comments, commentKey, fadeOut, nickname, message, alertType, alert) { - var clean = jsdom(), + var clean = globalThis.cleanup(), results = []; $('body').html( '

Discussion

' + diff --git a/js/test/Editor.js b/js/test/Editor.js index b7e5d1e5..fd38eb7c 100644 --- a/js/test/Editor.js +++ b/js/test/Editor.js @@ -9,7 +9,7 @@ describe('Editor', function () { 'returns text fed into the textarea, handles editor tabs', 'string', function (text) { - var clean = jsdom(), + var clean = globalThis.cleanup(), results = []; $('body').html( '
'; }); @@ -75,7 +75,7 @@ describe('Helper', function () { describe('urls2links', function () { this.timeout(30000); before(function () { - cleanup = jsdom(); + cleanup = globalThis.cleanup(); }); jsc.property( @@ -84,7 +84,7 @@ describe('Helper', function () { function (content) { // eslint-disable-next-line no-control-regex content = content.replace(/\r|\f/g, '\n').replace(/\u0000|\u000b/g, ''); - let clean = jsdom(); + let clean = globalThis.cleanup(); $('body').html('
'); let e = $('#foo'); e.text(content); @@ -107,7 +107,7 @@ describe('Helper', function () { postfix = ' ' + postfix.replace(/\r/g, '\n').replace(/\u0000/g, ''); url.fragment = fragment.join(''); let urlString = common.urlToString(url), - clean = jsdom(); + clean = globalThis.cleanup(); $('body').html('
'); let e = $('#foo'); @@ -140,7 +140,7 @@ describe('Helper', function () { // eslint-disable-next-line no-control-regex postfix = ' ' + postfix.replace(/\r/g, '\n').replace(/\u0000/g, ''); let url = 'magnet:?' + query.join('').replace(/^&+|&+$/gm, ''), - clean = jsdom(); + clean = globalThis.cleanup(); $('body').html('
'); let e = $('#foo'); e.text(prefix + url + postfix); @@ -241,7 +241,7 @@ describe('Helper', function () { jsc.nearray(jsc.nearray(common.jscAlnumString())), function (labels, values) { let selectedKey = '', selectedValue = ''; - const clean = jsdom(); + const clean = globalThis.cleanup(); labels.forEach(function(item, i) { const key = item.join(''), value = (values[i] || values[0]).join(''); @@ -273,7 +273,7 @@ describe('Helper', function () { delete(url.fragment); PrivateBin.Helper.reset(); const expected = common.urlToString(url), - clean = jsdom('', {url: fullUrl}), + clean = globalThis.cleanup('', {url: fullUrl}), result = PrivateBin.Helper.baseUri(); clean(); return expected === result; @@ -283,7 +283,7 @@ describe('Helper', function () { describe('htmlEntities', function () { before(function () { - cleanup = jsdom(); + cleanup = globalThis.cleanup(); }); jsc.property( diff --git a/js/test/I18n.js b/js/test/I18n.js index e8921445..af7fad23 100644 --- a/js/test/I18n.js +++ b/js/test/I18n.js @@ -102,14 +102,14 @@ describe('I18n', function () { const translation = $('