From 364bf166ae22a2666f5cb4331b4f6f8725bf9563 Mon Sep 17 00:00:00 2001 From: WebStreamr <210764791+webstreamr@users.noreply.github.com> Date: Sun, 8 Jun 2025 18:50:36 +0000 Subject: [PATCH] test(handler): avoid side-effects by using a fresh handler for each test --- src/handler/CineHDPlus.test.ts | 7 ++++++- src/handler/Eurostreaming.test.ts | 7 ++++++- src/handler/Frembed.test.ts | 15 +++++++-------- src/handler/FrenchCloud.test.ts | 7 ++++++- src/handler/KinoKiste.test.ts | 7 ++++++- src/handler/MeineCloud.test.ts | 7 ++++++- src/handler/MostraGuarda.test.ts | 7 ++++++- src/handler/Soaper.test.ts | 15 +++++++-------- src/handler/VerHdLink.test.ts | 7 ++++++- src/handler/__snapshots__/Frembed.test.ts.snap | 3 +++ src/handler/__snapshots__/Soaper.test.ts.snap | 1 + 11 files changed, 60 insertions(+), 23 deletions(-) diff --git a/src/handler/CineHDPlus.test.ts b/src/handler/CineHDPlus.test.ts index d4e5917..ac0a762 100644 --- a/src/handler/CineHDPlus.test.ts +++ b/src/handler/CineHDPlus.test.ts @@ -8,10 +8,15 @@ jest.mock('../utils/Fetcher'); const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] }); // @ts-expect-error No constructor args needed const fetcher = new Fetcher(); -const handler = new CineHDPlus(fetcher, new ExtractorRegistry(logger, fetcher)); const ctx: Context = { id: 'id', ip: '127.0.0.1', config: { es: 'on', mx: 'on' } }; describe('CineHDPlus', () => { + let handler: CineHDPlus; + + beforeEach(() => { + handler = new CineHDPlus(fetcher, new ExtractorRegistry(logger, fetcher)); + }); + test('handles non-existent series gracefully', async () => { const streams = await handler.handle(ctx, 'series', new ImdbId('tt12345678', 1, 1)); expect(streams).toHaveLength(0); diff --git a/src/handler/Eurostreaming.test.ts b/src/handler/Eurostreaming.test.ts index d42de6e..7eeb0e0 100644 --- a/src/handler/Eurostreaming.test.ts +++ b/src/handler/Eurostreaming.test.ts @@ -8,10 +8,15 @@ jest.mock('../utils/Fetcher'); const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] }); // @ts-expect-error No constructor args needed const fetcher = new Fetcher(); -const handler = new Eurostreaming(fetcher, new ExtractorRegistry(logger, fetcher)); const ctx: Context = { id: 'id', ip: '127.0.0.1', config: { it: 'on' } }; describe('Eurostreaming', () => { + let handler: Eurostreaming; + + beforeEach(() => { + handler = new Eurostreaming(fetcher, new ExtractorRegistry(logger, fetcher)); + }); + test('handles non-existent series gracefully', async () => { const streams = await handler.handle(ctx, 'series', new ImdbId('tt12345678', 1, 1)); expect(streams).toHaveLength(0); diff --git a/src/handler/Frembed.test.ts b/src/handler/Frembed.test.ts index 22055fa..6075484 100644 --- a/src/handler/Frembed.test.ts +++ b/src/handler/Frembed.test.ts @@ -8,10 +8,15 @@ jest.mock('../utils/Fetcher'); const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] }); // @ts-expect-error No constructor args needed const fetcher = new Fetcher(); -const handler = new Frembed(fetcher, new ExtractorRegistry(logger, fetcher)); const ctx: Context = { id: 'id', ip: '127.0.0.1', config: { fr: 'on' } }; describe('Frembed', () => { + let handler: Frembed; + + beforeEach(() => { + handler = new Frembed(fetcher, new ExtractorRegistry(logger, fetcher)); + }); + test('handle imdb black mirror s4e2', async () => { const streams = (await handler.handle(ctx, 'series', new ImdbId('tt2085059', 4, 2))).filter(stream => stream !== undefined); expect(streams).toMatchSnapshot(); @@ -19,12 +24,6 @@ describe('Frembed', () => { test('handle tmdb black mirror s4e2', async () => { const streams = (await handler.handle(ctx, 'series', new TmdbId(42009, 4, 2))).filter(stream => stream !== undefined); - - const streamsWithoutTtl = streams.map((stream) => { - delete stream.ttl; - return stream; - }); // to avoid flakyness because this is served from cache with lower ttl :) - - expect(streamsWithoutTtl).toMatchSnapshot(); + expect(streams).toMatchSnapshot(); }); }); diff --git a/src/handler/FrenchCloud.test.ts b/src/handler/FrenchCloud.test.ts index ee3462f..b01e26d 100644 --- a/src/handler/FrenchCloud.test.ts +++ b/src/handler/FrenchCloud.test.ts @@ -8,10 +8,15 @@ jest.mock('../utils/Fetcher'); const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] }); // @ts-expect-error No constructor args needed const fetcher = new Fetcher(); -const handler = new FrenchCloud(fetcher, new ExtractorRegistry(logger, fetcher)); const ctx: Context = { id: 'id', ip: '127.0.0.1', config: { fr: 'on' } }; describe('FrenchCloud', () => { + let handler: FrenchCloud; + + beforeEach(() => { + handler = new FrenchCloud(fetcher, new ExtractorRegistry(logger, fetcher)); + }); + test('handles non-existent movies gracefully', async () => { const streams = await handler.handle(ctx, 'movie', new ImdbId('tt12345678', undefined, undefined)); expect(streams).toHaveLength(0); diff --git a/src/handler/KinoKiste.test.ts b/src/handler/KinoKiste.test.ts index 290b012..78773fb 100644 --- a/src/handler/KinoKiste.test.ts +++ b/src/handler/KinoKiste.test.ts @@ -8,10 +8,15 @@ jest.mock('../utils/Fetcher'); const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] }); // @ts-expect-error No constructor args needed const fetcher = new Fetcher(); -const handler = new KinoKiste(fetcher, new ExtractorRegistry(logger, fetcher)); const ctx: Context = { id: 'id', ip: '127.0.0.1', config: { de: 'on' } }; describe('KinoKiste', () => { + let handler: KinoKiste; + + beforeEach(() => { + handler = new KinoKiste(fetcher, new ExtractorRegistry(logger, fetcher)); + }); + test('handles non-existent series gracefully', async () => { const streams = await handler.handle(ctx, 'series', new ImdbId('tt12345678', 1, 1)); expect(streams).toHaveLength(0); diff --git a/src/handler/MeineCloud.test.ts b/src/handler/MeineCloud.test.ts index 6ff6dc8..d23ca9a 100644 --- a/src/handler/MeineCloud.test.ts +++ b/src/handler/MeineCloud.test.ts @@ -8,10 +8,15 @@ jest.mock('../utils/Fetcher'); const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] }); // @ts-expect-error No constructor args needed const fetcher = new Fetcher(); -const handler = new MeineCloud(fetcher, new ExtractorRegistry(logger, fetcher)); const ctx: Context = { id: 'id', ip: '127.0.0.1', config: { de: 'on' } }; describe('MeineCloud', () => { + let handler: MeineCloud; + + beforeEach(() => { + handler = new MeineCloud(fetcher, new ExtractorRegistry(logger, fetcher)); + }); + test('handles non-existent movies gracefully', async () => { const streams = await handler.handle(ctx, 'movie', new ImdbId('tt12345678', undefined, undefined)); expect(streams).toHaveLength(0); diff --git a/src/handler/MostraGuarda.test.ts b/src/handler/MostraGuarda.test.ts index 9ed29d6..57ac50c 100644 --- a/src/handler/MostraGuarda.test.ts +++ b/src/handler/MostraGuarda.test.ts @@ -8,10 +8,15 @@ jest.mock('../utils/Fetcher'); const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] }); // @ts-expect-error No constructor args needed const fetcher = new Fetcher(); -const handler = new MostraGuarda(fetcher, new ExtractorRegistry(logger, fetcher)); const ctx: Context = { id: 'id', ip: '127.0.0.1', config: { it: 'on' } }; describe('MostraGuarda', () => { + let handler: MostraGuarda; + + beforeEach(() => { + handler = new MostraGuarda(fetcher, new ExtractorRegistry(logger, fetcher)); + }); + test('handles non-existent movies gracefully', async () => { const streams = await handler.handle(ctx, 'movie', new ImdbId('tt12345678', undefined, undefined)); expect(streams).toHaveLength(0); diff --git a/src/handler/Soaper.test.ts b/src/handler/Soaper.test.ts index fb17011..c8a9d5e 100644 --- a/src/handler/Soaper.test.ts +++ b/src/handler/Soaper.test.ts @@ -8,10 +8,15 @@ jest.mock('../utils/Fetcher'); const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] }); // @ts-expect-error No constructor args needed const fetcher = new Fetcher(); -const handler = new Soaper(fetcher, new ExtractorRegistry(logger, fetcher)); const ctx: Context = { id: 'id', ip: '127.0.0.1', config: { en: 'on' } }; describe('Soaper', () => { + let handler: Soaper; + + beforeEach(() => { + handler = new Soaper(fetcher, new ExtractorRegistry(logger, fetcher)); + }); + test('handles non-existent movies gracefully', async () => { const streams = await handler.handle(ctx, 'movie', new ImdbId('tt12345678', undefined, undefined)); expect(streams).toHaveLength(0); @@ -34,13 +39,7 @@ describe('Soaper', () => { test('handle tmdb black mirror s4e2', async () => { const streams = (await handler.handle(ctx, 'series', new TmdbId(42009, 4, 2))).filter(stream => stream !== undefined); - - const streamsWithoutTtl = streams.map((stream) => { - delete stream.ttl; - return stream; - }); // to avoid flakyness because this is served from cache with lower ttl :) - - expect(streamsWithoutTtl).toMatchSnapshot(); + expect(streams).toMatchSnapshot(); }); test('handle imdb full metal jacket', async () => { diff --git a/src/handler/VerHdLink.test.ts b/src/handler/VerHdLink.test.ts index 7629470..eb50871 100644 --- a/src/handler/VerHdLink.test.ts +++ b/src/handler/VerHdLink.test.ts @@ -8,10 +8,15 @@ jest.mock('../utils/Fetcher'); const logger = winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] }); // @ts-expect-error No constructor args needed const fetcher = new Fetcher(); -const handler = new VerHdLink(fetcher, new ExtractorRegistry(logger, fetcher)); const ctx: Context = { id: 'id', ip: '127.0.0.1', config: { es: 'on', mx: 'on' } }; describe('VerHdLink', () => { + let handler: VerHdLink; + + beforeEach(() => { + handler = new VerHdLink(fetcher, new ExtractorRegistry(logger, fetcher)); + }); + test('handles non-existent movies gracefully', async () => { const streams = await handler.handle(ctx, 'movie', new ImdbId('tt12345678', undefined, undefined)); expect(streams).toHaveLength(0); diff --git a/src/handler/__snapshots__/Frembed.test.ts.snap b/src/handler/__snapshots__/Frembed.test.ts.snap index 39aa991..35cad7d 100644 --- a/src/handler/__snapshots__/Frembed.test.ts.snap +++ b/src/handler/__snapshots__/Frembed.test.ts.snap @@ -63,6 +63,7 @@ exports[`Frembed handle tmdb black mirror s4e2 1`] = ` "Referer": "http://dood.to/", }, "sourceId": "doodstream_fr", + "ttl": 900000, "url": "https://ee317r.cloudatacdn.com/u5kj63yvxddlsdgge7qremqqka27irwiupc4k7o5cikbh7fdq4j4mwzraf7q/1y4sn4ndoi~mocked-random-string?token=fh3rdlhjvao7chgxndsi3ra7&expiry=639837296000", }, { @@ -73,6 +74,7 @@ exports[`Frembed handle tmdb black mirror s4e2 1`] = ` "title": "Black Mirror 4x2", }, "sourceId": "external_fr", + "ttl": 3600000, "url": "https://netu.fanstream.us/e/0DFgfkcXOsDP", }, { @@ -83,6 +85,7 @@ exports[`Frembed handle tmdb black mirror s4e2 1`] = ` "title": "Black Mirror 4x2", }, "sourceId": "external_fr", + "ttl": 3600000, "url": "https://johnalwayssame.com/e/cqy9oue7sv0g", }, { diff --git a/src/handler/__snapshots__/Soaper.test.ts.snap b/src/handler/__snapshots__/Soaper.test.ts.snap index 098ca6b..4f2f4d5 100644 --- a/src/handler/__snapshots__/Soaper.test.ts.snap +++ b/src/handler/__snapshots__/Soaper.test.ts.snap @@ -42,6 +42,7 @@ exports[`Soaper handle tmdb black mirror s4e2 1`] = ` "title": "Black Mirror 4x2", }, "sourceId": "soaper_en", + "ttl": 900000, "url": "https://soaper.live/home/index/TVM3U8?key=zoeyOo54b7s8NAPnOW0div4OdvmbYxIzpE2RnmAoSXqMAm7eZKs79V4lxEnZsvQ6qYNrOEiqKO4dAwdBiYx3KmwyVRc9oPzLWoOYcLQVArr2j0.m3u8", }, ]