From acc928ad9d66e058ea1d7abfe012c9f1e34f8edd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Wr=C3=B3blewski?= Date: Fri, 26 May 2023 15:10:31 +0200 Subject: [PATCH] Update tests Revert changes in server.js --- tests/scriptlets/m3u-prune.test.js | 8 ++++---- tests/scriptlets/xml-prune.test.js | 8 ++++---- tests/server.js | 16 ---------------- 3 files changed, 8 insertions(+), 24 deletions(-) diff --git a/tests/scriptlets/m3u-prune.test.js b/tests/scriptlets/m3u-prune.test.js index dd8debec..0e1f9b02 100644 --- a/tests/scriptlets/m3u-prune.test.js +++ b/tests/scriptlets/m3u-prune.test.js @@ -701,7 +701,7 @@ if (!isSupported) { // This test is for issue with - Request with body": Failed to execute 'fetch' on 'Window': // Cannot construct a Request with a Request object that has already been used - test('fetch - Request with object as a body', async (assert) => { + test('fetch - Request with object as a body, do not match content', async (assert) => { const requestOptions = { method: 'POST', body: { @@ -709,7 +709,7 @@ if (!isSupported) { }, }; const request = new Request(M3U8_OBJECTS_PATH_01, requestOptions); - const MATCH_DATA = 'tvessaiprod.nbcuni.com/video/'; + const MATCH_DATA = 'do_not_match'; runScriptlet(name, [MATCH_DATA]); @@ -719,8 +719,8 @@ if (!isSupported) { const responseM3U8 = await response.text(); assert.ok( - responseM3U8.includes('[object Object]'), - 'Content of post request with body: {} return [object Object]', + responseM3U8.includes('tvessaiprod.nbcuni.com/video/'), + 'content should not been removed', ); assert.strictEqual(window.hit, undefined, 'should not hit'); done(); diff --git a/tests/scriptlets/xml-prune.test.js b/tests/scriptlets/xml-prune.test.js index 27aa68c1..43bca5c9 100644 --- a/tests/scriptlets/xml-prune.test.js +++ b/tests/scriptlets/xml-prune.test.js @@ -397,9 +397,9 @@ if (!isSupported) { }, }; const request = new Request(MPD_OBJECTS_PATH, requestOptions); - const MATCH_DATA = ["Period[id*='-ad-']"]; + const MATCH_DATA = 'do_not_match'; - runScriptlet(name, MATCH_DATA); + runScriptlet(name, [MATCH_DATA]); const done = assert.async(); @@ -407,8 +407,8 @@ if (!isSupported) { const responseMPD = await response.text(); assert.ok( - responseMPD.includes('[object Object]'), - 'Content of post request with body: {} return [object Object]', + responseMPD.includes('pre-roll-'), + 'content should not been removed', ); assert.strictEqual(window.hit, undefined, 'should not hit'); done(); diff --git a/tests/server.js b/tests/server.js index 33fe143a..91b84223 100644 --- a/tests/server.js +++ b/tests/server.js @@ -11,22 +11,6 @@ const server = { init() { return http.createServer((req, res) => { let filename = req.url; - - // It's required for m3u-prune and xml-prune tests to reproduce issue with - // Cannot construct a Request with a Request object that has already been used - // when POST method with object as a body is used - const FILES_USED_IN_TESTS_USING_POST = ['manifestM3U8', 'manifestMPD']; - const IS_TEST_USING_POST = FILES_USED_IN_TESTS_USING_POST.some((string) => filename.includes(string)); - if (req.method === 'POST' && IS_TEST_USING_POST) { - let body; - req.on('data', async (data) => { - body += data; - }); - req.on('end', () => { - res.writeHead(200); - res.end(body); - }); - } const queryPosition = filename.indexOf(TEST_QUERY_MARKER); if (queryPosition > -1) { filename = req.url.slice(0, queryPosition);