From 3d20b2e2daa5d64b708418dc7a694ad3ec47f0be Mon Sep 17 00:00:00 2001 From: StephanGerbeth Date: Thu, 24 Oct 2024 10:20:54 +0200 Subject: [PATCH] fix(fetch): cleanup tests --- .../src/fetch/autoPagination.test.js | 8 ++--- .../src/fetch/concurrentDownload.test.js | 5 +-- packages/operators/src/fetch/download.test.js | 6 ++-- .../operators/src/fetch/lazyPagination.js | 4 +-- .../src/fetch/lazyPagination.test.js | 13 ++++---- packages/operators/src/fetch/polling.test.js | 32 +++++++++---------- packages/operators/src/fetch/request.test.js | 3 +- packages/operators/src/fetch/upload.test.js | 12 ++++--- 8 files changed, 42 insertions(+), 41 deletions(-) diff --git a/packages/operators/src/fetch/autoPagination.test.js b/packages/operators/src/fetch/autoPagination.test.js index 5c36d15..f0b4664 100644 --- a/packages/operators/src/fetch/autoPagination.test.js +++ b/packages/operators/src/fetch/autoPagination.test.js @@ -1,6 +1,7 @@ import { concatAll, map, of } from 'rxjs'; import { beforeEach, describe, expect, test } from 'vitest'; +import { log } from '../log'; import { autoPagination } from './autoPagination'; import { resolveJSON } from './resolve'; @@ -26,16 +27,15 @@ describe('auto pagination', function () { } } }), + log(false), resolveJSON(), + log(false), map(({ products }) => products), concatAll() ) .subscribe({ next: e => console.log(e), - complete: () => { - console.log('COMPLETE'); - done(); - } + complete: () => done() }); }); }); diff --git a/packages/operators/src/fetch/concurrentDownload.test.js b/packages/operators/src/fetch/concurrentDownload.test.js index 3de0587..0510bb9 100644 --- a/packages/operators/src/fetch/concurrentDownload.test.js +++ b/packages/operators/src/fetch/concurrentDownload.test.js @@ -30,10 +30,7 @@ describe('multi fetch', function () { ) .subscribe({ next: e => console.log(e), - complete: () => { - console.log('COMPLETE'); - done(); - } + complete: () => done() }); }); }); diff --git a/packages/operators/src/fetch/download.test.js b/packages/operators/src/fetch/download.test.js index c11e1d2..6c098d2 100644 --- a/packages/operators/src/fetch/download.test.js +++ b/packages/operators/src/fetch/download.test.js @@ -2,6 +2,7 @@ import fetchMock from 'fetch-mock'; import { of } from 'rxjs'; import { afterEach, test, describe, beforeEach, expect } from 'vitest'; +import { log } from '../log.js'; import { download, downloadJSON } from './download.js'; describe('download operator', function () { @@ -27,13 +28,12 @@ describe('download operator', function () { test('successfull download', () => new Promise(done => { of('https://httpbin.org/my-url-fast') - .pipe(downloadJSON()) + .pipe(downloadJSON(), log(false)) .subscribe({ next: data => { expect(data).deep.equal({ hello: 'fast world' }); - done(); }, - complete: e => console.log('COMPLETE', e) + complete: e => done() }); })); }); diff --git a/packages/operators/src/fetch/lazyPagination.js b/packages/operators/src/fetch/lazyPagination.js index dae84cd..15115ea 100644 --- a/packages/operators/src/fetch/lazyPagination.js +++ b/packages/operators/src/fetch/lazyPagination.js @@ -2,12 +2,12 @@ import { concatMap, map } from 'rxjs'; import { concurrentDownload } from './concurrentDownload'; -export const lazyPagination = ({ createRoute }) => { +export const lazyPagination = ({ resolveRoute }) => { return source => source.pipe( concatMap(({ url, pager, concurrent }) => { return pager.pipe( - map(options => createRoute(url, options)), + map(options => resolveRoute(url, options)), concurrentDownload(concurrent) ); }) diff --git a/packages/operators/src/fetch/lazyPagination.test.js b/packages/operators/src/fetch/lazyPagination.test.js index 3233f8f..9bf49d9 100644 --- a/packages/operators/src/fetch/lazyPagination.test.js +++ b/packages/operators/src/fetch/lazyPagination.test.js @@ -1,6 +1,7 @@ import { concatAll, map, of, Subject } from 'rxjs'; import { beforeEach, describe, expect, test } from 'vitest'; +import { log } from '../log'; import { lazyPagination } from './lazyPagination'; import { resolveJSON } from './resolve'; @@ -16,7 +17,7 @@ describe('lazy pagination operator', function () { of({ url: new URL('https://dummyjson.com/products'), pager, concurrent: 4 }) .pipe( lazyPagination({ - createRoute: (url, { value, limit = 10 }) => { + resolveRoute: (url, { value, limit = 10 }) => { const newUrl = new URL(`${url}`); newUrl.searchParams.set('skip', value * limit); newUrl.searchParams.set('limit', limit); @@ -24,16 +25,16 @@ describe('lazy pagination operator', function () { return newUrl; } }), + log(false), resolveJSON(), + log(false), map(({ products }) => products), - concatAll() + concatAll(), + log(false) ) .subscribe({ next: e => console.log(e), - complete: () => { - console.log('COMPLETE'); - done(); - } + complete: () => done() }); pager.next({ value: 2 }); diff --git a/packages/operators/src/fetch/polling.test.js b/packages/operators/src/fetch/polling.test.js index 6096170..076c96a 100644 --- a/packages/operators/src/fetch/polling.test.js +++ b/packages/operators/src/fetch/polling.test.js @@ -9,21 +9,21 @@ describe('polling', function () { }); test('auto polling', async function () { - of({ url: new URL('https://dummyjson.com/products') }) - .pipe( - polling({ - validateResult: data => { - return data.total > data.skip + data.limit; - } - }) - // map(({ data: { products } }) => products), - // concatAll() - ) - .subscribe({ - next: e => console.log('aha'), - complete: () => console.log('COMPLETE') - }); - - await new Promise(resolve => setTimeout(resolve, 5000)); + return new Promise(done => { + of({ url: new URL('https://dummyjson.com/products') }) + .pipe( + polling({ + validateResult: data => { + return data.total > data.skip + data.limit; + } + }) + // map(({ data: { products } }) => products), + // concatAll() + ) + .subscribe({ + next: e => console.log('aha'), + complete: () => done() + }); + }); }); }); diff --git a/packages/operators/src/fetch/request.test.js b/packages/operators/src/fetch/request.test.js index bdc667f..4eb91a5 100644 --- a/packages/operators/src/fetch/request.test.js +++ b/packages/operators/src/fetch/request.test.js @@ -2,6 +2,7 @@ import fetchMock from 'fetch-mock'; import { of } from 'rxjs'; import { afterEach, test, describe, beforeEach, expect } from 'vitest'; +import { log } from '../log.js'; import { request } from './request.js'; describe('request observable with default operators', function () { @@ -26,7 +27,7 @@ describe('request observable with default operators', function () { test('successfull request', () => new Promise(done => { of('https://httpbin.org/my-url-fast') - .pipe(request()) + .pipe(request(), log(false)) .subscribe({ next: resp => { expect(resp).deep.includes({ ok: true }); diff --git a/packages/operators/src/fetch/upload.test.js b/packages/operators/src/fetch/upload.test.js index c8f7028..74b91fe 100644 --- a/packages/operators/src/fetch/upload.test.js +++ b/packages/operators/src/fetch/upload.test.js @@ -38,11 +38,13 @@ describe('request observable with default operators', function () { return new Promise(done => { of(req) .pipe(upload(), log(false), resolveJSON(), log(false)) - .subscribe(e => { - expect(e) - .deep.includes({ originalname: 'test_image.jpg' }) - .have.all.keys('filename', 'location'); - done(); + .subscribe({ + next: e => { + expect(e) + .deep.includes({ originalname: 'test_image.jpg' }) + .have.all.keys('filename', 'location'); + }, + complete: () => done() }); }); });