Improve logging of provider unit tests

This commit is contained in:
mrjvs
2024-01-17 18:54:42 +01:00
parent 616c8a1e1b
commit 03a628ea34
2 changed files with 102 additions and 97 deletions

View File

@@ -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);
})
}
});
})
})
}