From a19524a4a2918217cfeb9c53a6f7b7c742842cdf Mon Sep 17 00:00:00 2001 From: Bruno Pinto Date: Sun, 28 Nov 2021 22:45:34 +0000 Subject: [PATCH 1/6] kefir-test-utils@2.0.0 --- package-lock.json | 100 +++++++++++++++++++--------------------------- package.json | 2 +- 2 files changed, 43 insertions(+), 59 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5c41540..63f4793 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "@types/jest": "^27.0.3", "@types/kefir": "^3.0.0", "@types/node": "^14.0.1", - "kefir-test-utils": "^1.1.1" + "kefir-test-utils": "^2.0.0" }, "devDependencies": { "@babel/cli": "^7.2.3", @@ -2327,7 +2327,6 @@ "version": "1.8.3", "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.3.tgz", "integrity": "sha512-xkNcLAn/wZaX14RPlwizcKicDk9G3F8m2nU3L7Ukm5zBgTwiT0wsoFAHx9Jq56fJA1z/7uKGtCRu16sOUCLIHQ==", - "peer": true, "dependencies": { "type-detect": "4.0.8" } @@ -2336,7 +2335,6 @@ "version": "8.1.0", "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-8.1.0.tgz", "integrity": "sha512-OAPJUAtgeINhh/TAlUID4QTs53Njm7xzddaVlEs/SXwgtiD1tW22zAB/W1wdqfrpmikgaWQ9Fw6Ws+hsiRm5Vg==", - "peer": true, "dependencies": { "@sinonjs/commons": "^1.7.0" } @@ -2470,11 +2468,6 @@ "@types/node": "*" } }, - "node_modules/@types/lolex": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/@types/lolex/-/lolex-2.1.3.tgz", - "integrity": "sha512-nEipOLYyZJ4RKHCg7tlR37ewFy91oggmip2MBzPdVQ8QhTFqjcRhE8R0t4tfpDnSlxGWHoEGJl0UCC4kYhqoiw==" - }, "node_modules/@types/minimist": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.2.tgz", @@ -2498,6 +2491,11 @@ "integrity": "sha512-ekoj4qOQYp7CvjX8ZDBgN86w3MqQhLE1hczEJbEIjgFEumDy+na/4AJAbLXfgEWFNB2pKadM5rPFtuSGMWK7xA==", "peer": true }, + "node_modules/@types/sinonjs__fake-timers": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-8.1.0.tgz", + "integrity": "sha512-TZ3vsL7wvXRNTRehor/zKtyWX9Ew3TrT20QQHPx+rieOJivRntZntWhUu1/qKnC8FK4q++RiEl/kje+PAVHhfg==" + }, "node_modules/@types/stack-utils": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.1.tgz", @@ -3231,9 +3229,9 @@ } }, "node_modules/debug": { - "version": "4.3.2", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz", - "integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==", + "version": "4.3.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.3.tgz", + "integrity": "sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==", "dependencies": { "ms": "2.1.2" }, @@ -3376,9 +3374,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.3", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.3.tgz", - "integrity": "sha512-hfpppjYhqIZB8jrNb0rNceQRkSnBN7QJl3W26O1jUv3F3BkQknqy1YTqVXkFnIcFtBc3Qnv5M7r5Lez2iOLgZA==" + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.4.tgz", + "integrity": "sha512-teHtgwcmVcL46jlFvAaqjyiTLWuMrUQO1JqV303JKB4ysXG6m8fXSFhbjal9st0r9mNskI22AraJZorb1VcLVg==" }, "node_modules/emittery": { "version": "0.8.1", @@ -6123,23 +6121,23 @@ "integrity": "sha512-xWga7QCZsR2Wjy2vNL3Kq/irT+IwxwItEWycRRlT5yhqHZK2fmEhziP+LzcJBWSTAMranGKtGTQ6lFpyJS3+jA==" }, "node_modules/kefir-test-utils": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/kefir-test-utils/-/kefir-test-utils-1.2.1.tgz", - "integrity": "sha512-EsrtgRcHH1vv3mOXh5JZSd5zz47BwQ9MrSxa1+vDWBemVagbdgbxYantaTCVH/a9ZKkzbvSyMDboQwmN/jHN9g==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/kefir-test-utils/-/kefir-test-utils-2.0.0.tgz", + "integrity": "sha512-S1JLc2xsSQts5KM7WXKkh6JWpbX7Tvy1KB/sfHQLLEPi+qOliGt6rg5Em43x3/cN3AgncTetDtfsDDPxRubzMQ==", "dependencies": { + "@sinonjs/fake-timers": "^8.0.1", "@types/kefir": "^3.8.0", - "@types/lolex": "^2.0.0", - "@types/node": "^13.1.4", - "lolex": "^2.0.0" + "@types/node": "^16.11.9", + "@types/sinonjs__fake-timers": "^8.1.0" }, "peerDependencies": { "kefir": "^3.0.0" } }, "node_modules/kefir-test-utils/node_modules/@types/node": { - "version": "13.13.52", - "resolved": "https://registry.npmjs.org/@types/node/-/node-13.13.52.tgz", - "integrity": "sha512-s3nugnZumCC//n4moGGe6tkNMyYEdaDBitVjwPxXmR5lnMG5dHePinH2EdxkG3Rh1ghFHHixAG4NJhpJW1rthQ==" + "version": "16.11.10", + "resolved": "https://registry.npmjs.org/@types/node/-/node-16.11.10.tgz", + "integrity": "sha512-3aRnHa1KlOEEhJ6+CvyHKK5vE9BcLGjtUpwvqYLRvYNQKMfabu3BwfJaA/SLW8dxe28LsNDjtHwePTuzn3gmOA==" }, "node_modules/kind-of": { "version": "6.0.3", @@ -6296,11 +6294,6 @@ "node": ">=8" } }, - "node_modules/lolex": { - "version": "2.7.5", - "resolved": "https://registry.npmjs.org/lolex/-/lolex-2.7.5.tgz", - "integrity": "sha512-l9x0+1offnKKIzYVjyXU2SiwhXDLekRzKyhnbyldPHvC7BvLPVpdNUNR2KeMAiCN2D/kLNttZgQD5WjSxuBx3Q==" - }, "node_modules/lru-cache": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", @@ -7596,7 +7589,6 @@ "version": "4.0.8", "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", - "peer": true, "engines": { "node": ">=4" } @@ -9572,7 +9564,6 @@ "version": "1.8.3", "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.3.tgz", "integrity": "sha512-xkNcLAn/wZaX14RPlwizcKicDk9G3F8m2nU3L7Ukm5zBgTwiT0wsoFAHx9Jq56fJA1z/7uKGtCRu16sOUCLIHQ==", - "peer": true, "requires": { "type-detect": "4.0.8" } @@ -9581,7 +9572,6 @@ "version": "8.1.0", "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-8.1.0.tgz", "integrity": "sha512-OAPJUAtgeINhh/TAlUID4QTs53Njm7xzddaVlEs/SXwgtiD1tW22zAB/W1wdqfrpmikgaWQ9Fw6Ws+hsiRm5Vg==", - "peer": true, "requires": { "@sinonjs/commons": "^1.7.0" } @@ -9708,11 +9698,6 @@ "@types/node": "*" } }, - "@types/lolex": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/@types/lolex/-/lolex-2.1.3.tgz", - "integrity": "sha512-nEipOLYyZJ4RKHCg7tlR37ewFy91oggmip2MBzPdVQ8QhTFqjcRhE8R0t4tfpDnSlxGWHoEGJl0UCC4kYhqoiw==" - }, "@types/minimist": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.2.tgz", @@ -9736,6 +9721,11 @@ "integrity": "sha512-ekoj4qOQYp7CvjX8ZDBgN86w3MqQhLE1hczEJbEIjgFEumDy+na/4AJAbLXfgEWFNB2pKadM5rPFtuSGMWK7xA==", "peer": true }, + "@types/sinonjs__fake-timers": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-8.1.0.tgz", + "integrity": "sha512-TZ3vsL7wvXRNTRehor/zKtyWX9Ew3TrT20QQHPx+rieOJivRntZntWhUu1/qKnC8FK4q++RiEl/kje+PAVHhfg==" + }, "@types/stack-utils": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.1.tgz", @@ -10311,9 +10301,9 @@ } }, "debug": { - "version": "4.3.2", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz", - "integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==", + "version": "4.3.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.3.tgz", + "integrity": "sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==", "requires": { "ms": "2.1.2" } @@ -10419,9 +10409,9 @@ } }, "electron-to-chromium": { - "version": "1.4.3", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.3.tgz", - "integrity": "sha512-hfpppjYhqIZB8jrNb0rNceQRkSnBN7QJl3W26O1jUv3F3BkQknqy1YTqVXkFnIcFtBc3Qnv5M7r5Lez2iOLgZA==" + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.4.tgz", + "integrity": "sha512-teHtgwcmVcL46jlFvAaqjyiTLWuMrUQO1JqV303JKB4ysXG6m8fXSFhbjal9st0r9mNskI22AraJZorb1VcLVg==" }, "emittery": { "version": "0.8.1", @@ -12453,20 +12443,20 @@ "integrity": "sha512-xWga7QCZsR2Wjy2vNL3Kq/irT+IwxwItEWycRRlT5yhqHZK2fmEhziP+LzcJBWSTAMranGKtGTQ6lFpyJS3+jA==" }, "kefir-test-utils": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/kefir-test-utils/-/kefir-test-utils-1.2.1.tgz", - "integrity": "sha512-EsrtgRcHH1vv3mOXh5JZSd5zz47BwQ9MrSxa1+vDWBemVagbdgbxYantaTCVH/a9ZKkzbvSyMDboQwmN/jHN9g==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/kefir-test-utils/-/kefir-test-utils-2.0.0.tgz", + "integrity": "sha512-S1JLc2xsSQts5KM7WXKkh6JWpbX7Tvy1KB/sfHQLLEPi+qOliGt6rg5Em43x3/cN3AgncTetDtfsDDPxRubzMQ==", "requires": { + "@sinonjs/fake-timers": "^8.0.1", "@types/kefir": "^3.8.0", - "@types/lolex": "^2.0.0", - "@types/node": "^13.1.4", - "lolex": "^2.0.0" + "@types/node": "^16.11.9", + "@types/sinonjs__fake-timers": "^8.1.0" }, "dependencies": { "@types/node": { - "version": "13.13.52", - "resolved": "https://registry.npmjs.org/@types/node/-/node-13.13.52.tgz", - "integrity": "sha512-s3nugnZumCC//n4moGGe6tkNMyYEdaDBitVjwPxXmR5lnMG5dHePinH2EdxkG3Rh1ghFHHixAG4NJhpJW1rthQ==" + "version": "16.11.10", + "resolved": "https://registry.npmjs.org/@types/node/-/node-16.11.10.tgz", + "integrity": "sha512-3aRnHa1KlOEEhJ6+CvyHKK5vE9BcLGjtUpwvqYLRvYNQKMfabu3BwfJaA/SLW8dxe28LsNDjtHwePTuzn3gmOA==" } } }, @@ -12585,11 +12575,6 @@ } } }, - "lolex": { - "version": "2.7.5", - "resolved": "https://registry.npmjs.org/lolex/-/lolex-2.7.5.tgz", - "integrity": "sha512-l9x0+1offnKKIzYVjyXU2SiwhXDLekRzKyhnbyldPHvC7BvLPVpdNUNR2KeMAiCN2D/kLNttZgQD5WjSxuBx3Q==" - }, "lru-cache": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", @@ -13560,8 +13545,7 @@ "type-detect": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", - "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", - "peer": true + "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==" }, "type-fest": { "version": "0.21.3", diff --git a/package.json b/package.json index 49787a0..542ad11 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "@types/jest": "^27.0.3", "@types/kefir": "^3.0.0", "@types/node": "^14.0.1", - "kefir-test-utils": "^1.1.1" + "kefir-test-utils": "^2.0.0" }, "peerDependencies": { "jest": ">=24.0.0", From fd0a341120b42f32cdf5ceded096c1a357bddc23 Mon Sep 17 00:00:00 2001 From: Bruno Pinto Date: Sun, 28 Nov 2021 22:49:56 +0000 Subject: [PATCH 2/6] Replace lolex imports with @sinonsjs/fake-timers --- extend-expect.d.ts | 2 +- jest-kefir.d.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/extend-expect.d.ts b/extend-expect.d.ts index 24396f9..79193da 100644 --- a/extend-expect.d.ts +++ b/extend-expect.d.ts @@ -8,7 +8,7 @@ declare namespace jest { toEmit(events: import('kefir-test-utils').Event[], cb?: () => void): R toEmitInTime( events: import('kefir-test-utils').EventWithTime[], - cb?: (tick: (s: number) => void, clock: import('lolex').Clock) => void, + cb?: (tick: (s: number) => void, clock: import('@sinonjs/fake-timers').Clock) => void, opts?: {reverseSimultaneous?: boolean; timeLimit?: number} ): R toFlowErrors(source?: import('kefir').Observable): R diff --git a/jest-kefir.d.ts b/jest-kefir.d.ts index 1140e04..f5dbd58 100644 --- a/jest-kefir.d.ts +++ b/jest-kefir.d.ts @@ -1,6 +1,6 @@ import {Observable, Stream, Property} from 'kefir' import {Helpers as KHelpers, Event} from 'kefir-test-utils' -import {Clock} from 'lolex' +import {Clock} from '@sinonjs/fake-timers' export interface Helpers extends KHelpers { extensions: jest.ExpectExtendMap From 1b2f1fa7ff949ba51065d2f69cd479def1043eb5 Mon Sep 17 00:00:00 2001 From: Bruno Pinto Date: Sun, 28 Nov 2021 22:56:00 +0000 Subject: [PATCH 3/6] Update watchWithTime usage Prettier is formatting the line as: ```js ;({log, unwatch} = watchWithTime(received)) ``` so we are disabling prettier formatting for now. --- src/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index be38bad..eeedf56 100644 --- a/src/index.js +++ b/src/index.js @@ -79,13 +79,16 @@ export default function jestKefir(Kefir) { }, toEmitInTime(received, expected, cb = noop, {timeLimit = 10000, reverseSimultaneous = false} = {}) { - let log = null + let log, + unwatch = null withFakeTime((tick, clock) => { - log = watchWithTime(received) + // prettier-ignore + ({log, unwatch} = watchWithTime(received)) cb(tick, clock) tick(timeLimit) }, reverseSimultaneous) + unwatch() const options = { comment: 'Emitted values', From 199a7e64a3a90fe598576f7039a973b1c067d897 Mon Sep 17 00:00:00 2001 From: Bruno Pinto Date: Sun, 28 Nov 2021 23:04:17 +0000 Subject: [PATCH 4/6] a-Z --- src/index.js | 2 +- test/jest-kefir.spec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index eeedf56..31549af 100644 --- a/src/index.js +++ b/src/index.js @@ -4,7 +4,7 @@ const noop = () => {} export default function jestKefir(Kefir) { const helpers = createTestHelpers(Kefir) - const {activate, deactivate, send, error, watch, withFakeTime, watchWithTime} = helpers + const {activate, deactivate, error, send, watch, watchWithTime, withFakeTime} = helpers const extensions = { toBeObservable(received) { diff --git a/test/jest-kefir.spec.js b/test/jest-kefir.spec.js index 96b697a..ccb8594 100644 --- a/test/jest-kefir.spec.js +++ b/test/jest-kefir.spec.js @@ -1,6 +1,6 @@ import '../extend-expect' -const {prop, stream, pool, activate, deactivate, value, error, end, send} = KTU +const {activate, deactivate, end, error, pool, prop, send, stream, value} = KTU describe('jest-kefir', () => { describe('toBeObservable', () => { From 96e5ddd30bad47235ea27434ffdf7c7dffcc91c3 Mon Sep 17 00:00:00 2001 From: Bruno Pinto Date: Sun, 28 Nov 2021 23:06:42 +0000 Subject: [PATCH 5/6] Validate observables are unsubscribed during tests --- test/jest-kefir.spec.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/jest-kefir.spec.js b/test/jest-kefir.spec.js index ccb8594..f635afa 100644 --- a/test/jest-kefir.spec.js +++ b/test/jest-kefir.spec.js @@ -1,8 +1,16 @@ import '../extend-expect' -const {activate, deactivate, end, error, pool, prop, send, stream, value} = KTU +const {activate, deactivate, end, error, observables, pool, prop, send, stream, value} = KTU describe('jest-kefir', () => { + beforeEach(() => { + observables.clear() + }) + + afterEach(() => { + expect(observables.active.length).toEqual(0) + }) + describe('toBeObservable', () => { it('should match with stream', () => { expect(stream()).toBeObservable() @@ -83,12 +91,14 @@ describe('jest-kefir', () => { const a = stream() activate(a) expect(a).toBeActiveObservable() + deactivate(a) }) it('should match on active stream when called as method', () => { const a = stream() activate(a) expect(a).toBeActiveObservable() + deactivate(a) }) it('should negate on inactive property', () => { @@ -99,6 +109,7 @@ describe('jest-kefir', () => { const a = prop() activate(a) expect(a).toBeActiveObservable() + deactivate(a) }) it('should negate on activated and deactivated property', () => { From f5d4d7a659b872e7d192a92a90fee25af08e4451 Mon Sep 17 00:00:00 2001 From: Bruno Pinto Date: Sun, 28 Nov 2021 23:23:28 +0000 Subject: [PATCH 6/6] Always unwatch observable checked with toEmitInTime --- src/index.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/index.js b/src/index.js index 31549af..c3002b4 100644 --- a/src/index.js +++ b/src/index.js @@ -82,13 +82,18 @@ export default function jestKefir(Kefir) { let log, unwatch = null - withFakeTime((tick, clock) => { - // prettier-ignore - ({log, unwatch} = watchWithTime(received)) - cb(tick, clock) - tick(timeLimit) - }, reverseSimultaneous) - unwatch() + try { + withFakeTime((tick, clock) => { + // prettier-ignore + ({log, unwatch} = watchWithTime(received)) + cb(tick, clock) + tick(timeLimit) + }, reverseSimultaneous) + } catch (e) { + throw e + } finally { + unwatch() + } const options = { comment: 'Emitted values',