Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
Revert changes in server.js
  • Loading branch information
AdamWr committed May 26, 2023
1 parent 8ffe30c commit acc928a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 24 deletions.
8 changes: 4 additions & 4 deletions tests/scriptlets/m3u-prune.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,15 +701,15 @@ 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: {
0: 1,
},
};
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]);

Expand All @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions tests/scriptlets/xml-prune.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,18 +397,18 @@ 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();

const response = await fetch(request);
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();
Expand Down
16 changes: 0 additions & 16 deletions tests/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit acc928a

Please sign in to comment.