diff --git a/package.json b/package.json index 9bb36e9..d8a8680 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "cli": "ts-node ./src/dev-cli/index.ts", "test": "vitest run", "test:watch": "vitest", - "test:providers": "cross-env MW_TEST_PROVIDERS=true vitest run", + "test:providers": "cross-env MW_TEST_PROVIDERS=true vitest run --reporter verbose", "test:integration": "node ./tests/cjs && node ./tests/esm && node ./tests/browser", "test:coverage": "vitest run --coverage", "lint": "eslint --ext .ts,.js src/", diff --git a/src/__test__/providers/providerUtils.ts b/src/__test__/providers/providerUtils.ts index 4675f86..f50d53f 100644 --- a/src/__test__/providers/providerUtils.ts +++ b/src/__test__/providers/providerUtils.ts @@ -53,62 +53,65 @@ export function testSource(ops: TestSourceOptions) { if (ops.testSuite.length === 0) throw new Error("Test suite must have at least one test"); describe(`source:${ops.source.id}`, () => { ops.testSuite.forEach((test, i) => { - async function runTest(providers: ProviderControls) { - let hasNotFound = false; - let hasError = false; - let streamCount = 0; - let embedCount = 0; - try { - const result = await providers.runSourceScraper({ - id: ops.source.id, - media: test, - }) - if (ops.debug) console.log(result); - streamCount = (result.stream ?? []).length; - embedCount = result.embeds.length; - } catch (err) { - if (ops.debug) console.log(err); - if (err instanceof NotFoundError) - hasNotFound = true; - else - hasError = true; + describe(`test ${i}`, () => { + async function runTest(providers: ProviderControls) { + let hasNotFound = false; + let hasError = false; + let streamCount = 0; + let embedCount = 0; + try { + const result = await providers.runSourceScraper({ + id: ops.source.id, + media: test, + }) + if (ops.debug) console.log(result); + streamCount = (result.stream ?? []).length; + embedCount = result.embeds.length; + } catch (err) { + if (ops.debug) console.log(err); + if (err instanceof NotFoundError) + hasNotFound = true; + else + hasError = true; + } + expect(ops.expect.error ?? false).toBe(hasError); + expect(ops.expect.notfound ?? false).toBe(hasNotFound); + expect(ops.expect.streams ?? 0).toBe(streamCount); + expect(ops.expect.embeds ?? 0).toBe(embedCount); } - expect(ops.expect.error ?? false).toBe(hasError); - expect(ops.expect.notfound ?? false).toBe(hasNotFound); - expect(ops.expect.streams ?? 0).toBe(streamCount); - expect(ops.expect.embeds ?? 0).toBe(embedCount); - } - if (ops.types.includes('standard')) { - it(`Should pass test ${i} - standard`, async () => { - const providers = makeBaseProviders() - .addSource(ops.source) - .build(); - await runTest(providers); - }) - } + if (ops.types.includes('standard')) { + it(`Should pass test ${i} - standard`, async () => { + const providers = makeBaseProviders() + .addSource(ops.source) + .build(); + await runTest(providers); + }) + } - if (ops.types.includes('ip:standard')) { - it(`Should pass test ${i} - standard:ip`, async () => { - const providers = makeBaseProviders() - .addSource(ops.source) - .enableConsistentIpForRequests() - .build(); - await runTest(providers); - }) - } + if (ops.types.includes('ip:standard')) { + it(`Should pass test ${i} - standard:ip`, async () => { + const providers = makeBaseProviders() + .addSource(ops.source) + .enableConsistentIpForRequests() + .build(); + await runTest(providers); + }) + } - if (ops.types.includes('proxied')) { - it(`Should pass test ${i} - proxied`, async () => { - if (!process.env.MOVIE_WEB_PROXY_URL) - throw new Error("Cant use proxied test without setting MOVIE_WEB_PROXY_URL env"); - const providers = makeBaseProviders() - .addSource(ops.source) - .setProxiedFetcher(makeSimpleProxyFetcher(process.env.MOVIE_WEB_PROXY_URL, fetch)) - .build(); - await runTest(providers); - }) - } + if (ops.types.includes('proxied')) { + it(`Should pass test ${i} - proxied`, async () => { + if (!process.env.MOVIE_WEB_PROXY_URL) + throw new Error("Cant use proxied test without setting MOVIE_WEB_PROXY_URL env"); + const providers = makeBaseProviders() + .addSource(ops.source) + .setProxiedFetcher(makeSimpleProxyFetcher(process.env.MOVIE_WEB_PROXY_URL, fetch)) + .build(); + await runTest(providers); + }) + } + + }) }) }) } @@ -117,54 +120,56 @@ export function testEmbed(ops: TestEmbedOptions) { if (ops.testUrls.length === 0) throw new Error("Test urls must have at least one url"); describe(`embed:${ops.embed.id}`, () => { ops.testUrls.forEach((test, i) => { - async function runTest(providers: ProviderControls) { - let hasError = false; - let streamCount = 0; - try { - const result = await providers.runEmbedScraper({ - id: ops.embed.id, - url: test, - }) - if (ops.debug) console.log(result); - streamCount = (result.stream ?? []).length; - } catch (err) { - if (ops.debug) console.log(err); - hasError = true; + describe(`test ${i}`, () => { + async function runTest(providers: ProviderControls) { + let hasError = false; + let streamCount = 0; + try { + const result = await providers.runEmbedScraper({ + id: ops.embed.id, + url: test, + }) + if (ops.debug) console.log(result); + streamCount = (result.stream ?? []).length; + } catch (err) { + if (ops.debug) console.log(err); + hasError = true; + } + expect(ops.expect.error ?? false).toBe(hasError); + expect(ops.expect.streams ?? 0).toBe(streamCount); } - expect(ops.expect.error ?? false).toBe(hasError); - expect(ops.expect.streams ?? 0).toBe(streamCount); - } - if (ops.types.includes('standard')) { - it(`Should pass test ${i} - standard`, async () => { - const providers = makeBaseEmbedProviders() - .addEmbed(ops.embed) - .build(); - await runTest(providers); - }) - } + if (ops.types.includes('standard')) { + it(`Should pass test ${i} - standard`, async () => { + const providers = makeBaseEmbedProviders() + .addEmbed(ops.embed) + .build(); + await runTest(providers); + }) + } - if (ops.types.includes('ip:standard')) { - it(`Should pass test ${i} - standard:ip`, async () => { - const providers = makeBaseEmbedProviders() - .addEmbed(ops.embed) - .enableConsistentIpForRequests() - .build(); - await runTest(providers); - }) - } + if (ops.types.includes('ip:standard')) { + it(`Should pass test ${i} - standard:ip`, async () => { + const providers = makeBaseEmbedProviders() + .addEmbed(ops.embed) + .enableConsistentIpForRequests() + .build(); + await runTest(providers); + }) + } - if (ops.types.includes('proxied')) { - it(`Should pass test ${i} - proxied`, async () => { - if (!process.env.MOVIE_WEB_PROXY_URL) - throw new Error("Cant use proxied test without setting MOVIE_WEB_PROXY_URL env"); - const providers = makeBaseEmbedProviders() - .addEmbed(ops.embed) - .setProxiedFetcher(makeSimpleProxyFetcher(process.env.MOVIE_WEB_PROXY_URL, fetch)) - .build(); - await runTest(providers); - }) - } + if (ops.types.includes('proxied')) { + it(`Should pass test ${i} - proxied`, async () => { + if (!process.env.MOVIE_WEB_PROXY_URL) + throw new Error("Cant use proxied test without setting MOVIE_WEB_PROXY_URL env"); + const providers = makeBaseEmbedProviders() + .addEmbed(ops.embed) + .setProxiedFetcher(makeSimpleProxyFetcher(process.env.MOVIE_WEB_PROXY_URL, fetch)) + .build(); + await runTest(providers); + }) + } + }); }) }) }