From 3d0338d38ddd1fcb0c91920b2366230f2e23b467 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Thu, 28 Nov 2024 21:48:40 +0000 Subject: [PATCH 1/4] chore(release): 1.1.1 [skip ci] # [@rxjs-collection/operators-v1.1.1](https://github.com/basics/rxjs-collection/compare/@rxjs-collection/operators-v1.1.0...@rxjs-collection/operators-v1.1.1) (2024-11-28) ### Bug Fixes * **vitest:** better config ([7df804a](https://github.com/basics/rxjs-collection/commit/7df804acd9df3b0013dcc5b92a285dcf352a843a)) * **vitest:** updated config - project separated test calls ([9b69b72](https://github.com/basics/rxjs-collection/commit/9b69b72393dd8d61e6f435c7294086132ca64afe)) --- packages/operators/CHANGELOG.md | 8 ++++++++ packages/operators/package.json | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/operators/CHANGELOG.md b/packages/operators/CHANGELOG.md index cdcb43e..6c7f1d8 100644 --- a/packages/operators/CHANGELOG.md +++ b/packages/operators/CHANGELOG.md @@ -1,5 +1,13 @@ # Project Changelog +# [@rxjs-collection/operators-v1.1.1](https://github.com/basics/rxjs-collection/compare/@rxjs-collection/operators-v1.1.0...@rxjs-collection/operators-v1.1.1) (2024-11-28) + + +### Bug Fixes + +* **vitest:** better config ([7df804a](https://github.com/basics/rxjs-collection/commit/7df804acd9df3b0013dcc5b92a285dcf352a843a)) +* **vitest:** updated config - project separated test calls ([9b69b72](https://github.com/basics/rxjs-collection/commit/9b69b72393dd8d61e6f435c7294086132ca64afe)) + # [@rxjs-collection/operators-v1.1.1-beta.1](https://github.com/basics/rxjs-collection/compare/@rxjs-collection/operators-v1.1.0...@rxjs-collection/operators-v1.1.1-beta.1) (2024-11-28) diff --git a/packages/operators/package.json b/packages/operators/package.json index cd80694..1938fc0 100644 --- a/packages/operators/package.json +++ b/packages/operators/package.json @@ -1,6 +1,6 @@ { "name": "@rxjs-collection/operators", - "version": "1.1.1-beta.1", + "version": "1.1.1", "description": "rxjs operators", "license": "MIT", "contributors": [ From bdf292d08f3435d7ca037da572de395e2d689167 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Thu, 28 Nov 2024 21:48:54 +0000 Subject: [PATCH 2/4] chore(release): 1.0.8 [skip ci] # [@rxjs-collection/observables-v1.0.8](https://github.com/basics/rxjs-collection/compare/@rxjs-collection/observables-v1.0.7...@rxjs-collection/observables-v1.0.8) (2024-11-28) ### Bug Fixes * **vitest:** updated config - project separated test calls ([9b69b72](https://github.com/basics/rxjs-collection/commit/9b69b72393dd8d61e6f435c7294086132ca64afe)) --- packages/observables/CHANGELOG.md | 7 +++++++ packages/observables/package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/observables/CHANGELOG.md b/packages/observables/CHANGELOG.md index abdcd4b..f169a3b 100644 --- a/packages/observables/CHANGELOG.md +++ b/packages/observables/CHANGELOG.md @@ -1,5 +1,12 @@ # Project Changelog +# [@rxjs-collection/observables-v1.0.8](https://github.com/basics/rxjs-collection/compare/@rxjs-collection/observables-v1.0.7...@rxjs-collection/observables-v1.0.8) (2024-11-28) + + +### Bug Fixes + +* **vitest:** updated config - project separated test calls ([9b69b72](https://github.com/basics/rxjs-collection/commit/9b69b72393dd8d61e6f435c7294086132ca64afe)) + # [@rxjs-collection/observables-v1.0.8-beta.1](https://github.com/basics/rxjs-collection/compare/@rxjs-collection/observables-v1.0.7...@rxjs-collection/observables-v1.0.8-beta.1) (2024-11-28) diff --git a/packages/observables/package.json b/packages/observables/package.json index 53f4d8d..ebfa8e1 100644 --- a/packages/observables/package.json +++ b/packages/observables/package.json @@ -1,6 +1,6 @@ { "name": "@rxjs-collection/observables", - "version": "1.0.8-beta.1", + "version": "1.0.8", "description": "rxjs observables", "license": "MIT", "contributors": [ From 0402eb15c2d05d53f291720623ff38786a9c1125 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Thu, 28 Nov 2024 21:49:12 +0000 Subject: [PATCH 3/4] chore(release): 1.0.0 [skip ci] # @rxjs-collection/playground-v1.0.0 (2024-11-28) ### Bug Fixes * **vitest:** updated config - project separated test calls ([9b69b72](https://github.com/basics/rxjs-collection/commit/9b69b72393dd8d61e6f435c7294086132ca64afe)) ### Features * **playground:** added playground ([d2a84ff](https://github.com/basics/rxjs-collection/commit/d2a84ffd4685a354a073ce1b888869ba13adb505)) --- packages/playground/CHANGELOG.md | 12 ++++++++++++ packages/playground/package.json | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/playground/CHANGELOG.md b/packages/playground/CHANGELOG.md index 68d2d99..d3505b1 100644 --- a/packages/playground/CHANGELOG.md +++ b/packages/playground/CHANGELOG.md @@ -1,5 +1,17 @@ # Project Changelog +# @rxjs-collection/playground-v1.0.0 (2024-11-28) + + +### Bug Fixes + +* **vitest:** updated config - project separated test calls ([9b69b72](https://github.com/basics/rxjs-collection/commit/9b69b72393dd8d61e6f435c7294086132ca64afe)) + + +### Features + +* **playground:** added playground ([d2a84ff](https://github.com/basics/rxjs-collection/commit/d2a84ffd4685a354a073ce1b888869ba13adb505)) + # @rxjs-collection/playground-v1.0.0-beta.1 (2024-11-28) diff --git a/packages/playground/package.json b/packages/playground/package.json index 5b68a5c..254f2c8 100644 --- a/packages/playground/package.json +++ b/packages/playground/package.json @@ -1,6 +1,6 @@ { "name": "@rxjs-collection/playground", - "version": "1.0.0-beta.1", + "version": "1.0.0", "description": "rxjs playground", "license": "MIT", "contributors": [ From df028a70547be7095e3cab9663dd9b45d29304e9 Mon Sep 17 00:00:00 2001 From: StephanGerbeth Date: Fri, 6 Dec 2024 10:44:05 +0100 Subject: [PATCH 4/4] fix(operators): log test completed --- package-lock.json | 37 ++++++------ packages/operators/package.json | 3 +- packages/operators/src/log.js | 67 ++++++++++++++++++---- packages/operators/src/log.test.js | 42 +++++++++----- packages/playground/src/demo/index.test.js | 2 +- vitest.config.js | 1 + 6 files changed, 109 insertions(+), 43 deletions(-) diff --git a/package-lock.json b/package-lock.json index 29f9217..40a3ee7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2738,6 +2738,17 @@ "node": ">=8" } }, + "node_modules/ascii-table3": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/ascii-table3/-/ascii-table3-0.9.0.tgz", + "integrity": "sha512-/JcvVCQRTVQHwLI8TCxSeOS9AcCV01MbCJC4plSP5ulygJH+D30lz85nvMcER5k+qoX2fJ1C/i13Zo1/eoMGTw==", + "dependencies": { + "printable-characters": "^1.0.42" + }, + "engines": { + "node": ">=11.14.0" + } + }, "node_modules/assertion-error": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz", @@ -3332,15 +3343,6 @@ "dev": true, "license": "ISC" }, - "node_modules/consola": { - "version": "3.2.3", - "resolved": "https://registry.npmjs.org/consola/-/consola-3.2.3.tgz", - "integrity": "sha512-I5qxpzLv+sJhTVEoLYNcTW+bThDCPsit0vLNKShZx6rLtpilNpmmeTPaeqJb9ZE9dV3DGaeby6Vuhrw38WjeyQ==", - "license": "MIT", - "engines": { - "node": "^14.18.0 || >=16.10.0" - } - }, "node_modules/conventional-changelog-angular": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/conventional-changelog-angular/-/conventional-changelog-angular-8.0.0.tgz", @@ -3592,8 +3594,6 @@ "version": "4.3.7", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz", "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==", - "dev": true, - "license": "MIT", "dependencies": { "ms": "^2.1.3" }, @@ -6657,7 +6657,6 @@ "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", - "dev": true, "license": "MIT" }, "node_modules/mz": { @@ -9977,6 +9976,11 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/printable-characters": { + "version": "1.0.42", + "resolved": "https://registry.npmjs.org/printable-characters/-/printable-characters-1.0.42.tgz", + "integrity": "sha512-dKp+C4iXWK4vVYZmYSd0KBH5F/h1HoZRsbJ82AVKRO3PEo8L4lBS/vLwhVtpwwuYcoIsVY+1JYKR268yn480uQ==" + }, "node_modules/process-nextick-args": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", @@ -12644,7 +12648,7 @@ }, "packages/observables": { "name": "@rxjs-collection/observables", - "version": "1.0.7", + "version": "1.0.8", "license": "MIT", "dependencies": { "@rxjs-collection/operators": "*", @@ -12653,12 +12657,13 @@ }, "packages/operators": { "name": "@rxjs-collection/operators", - "version": "1.0.13", + "version": "1.1.1", "license": "MIT", "dependencies": { "@rxjs-collection/observables": "*", "ansi-colors": "4.1.3", - "consola": "3.2.3", + "ascii-table3": "^0.9.0", + "debug": "^4.3.7", "fast-equals": "5.0.1", "rxjs": "7.8.1" }, @@ -12668,7 +12673,7 @@ }, "packages/playground": { "name": "@rxjs-collection/playground", - "version": "1.0.12", + "version": "1.0.0", "license": "MIT", "dependencies": { "@rxjs-collection/observables": "*", diff --git a/packages/operators/package.json b/packages/operators/package.json index 1938fc0..88641c5 100644 --- a/packages/operators/package.json +++ b/packages/operators/package.json @@ -24,7 +24,8 @@ "dependencies": { "@rxjs-collection/observables": "*", "ansi-colors": "4.1.3", - "consola": "3.2.3", + "ascii-table3": "^0.9.0", + "debug": "^4.3.7", "fast-equals": "5.0.1", "rxjs": "7.8.1" }, diff --git a/packages/operators/src/log.js b/packages/operators/src/log.js index 7bef0cd..dffcf8b 100644 --- a/packages/operators/src/log.js +++ b/packages/operators/src/log.js @@ -1,28 +1,74 @@ -import { bgGreen } from 'ansi-colors'; +import { AsciiTable3, AlignmentEnum } from 'ascii-table3'; +import chalk from 'chalk'; import debug from 'debug'; -import { connectable, finalize, Observable, Subject } from 'rxjs'; +import { connectable, finalize, Observable, Subject, tap, toArray } from 'rxjs'; +import util from 'util'; -export const enableLog = tag => debug.enable(tag); +const getAlignments = list => { + return list.map(v => { + switch (typeof v) { + case 'number': + return AlignmentEnum.RIGHT; + case 'string': + return AlignmentEnum.LEFT; + default: + return AlignmentEnum.LEFT; + } + }); +}; + +export const defaultLogger = tag => { + const logger = debug(tag); + logger.log = global.console.log.bind(console); + return { + default: logger, + error: debug(`${tag}:error`), + complete: () => logger(chalk.white.bgGreen.bold('complete!')) + }; +}; + +const tableLogger = tag => { + debug.formatters.t = data => { + if (!data.length) return; + const table = new AsciiTable3(); + table.setHeading.apply(table, ['index', ...Object.keys(data[0])]); + table.setAligns(getAlignments([0, ...Object.values(data[0])])); + table.addRowMatrix( + data.map((entry, index) => [ + index, + ...Object.values(entry).map(item => util.inspect(item, { colors: true, depth: 0 })) + ]) + ); + return table.toString(); + }; -export const log = tag => { const logger = debug(tag); logger.log = global.console.log.bind(console); - const error = debug(`${tag}:error`); + return { + default: val => logger('%t', val), + error: debug(`${tag}:error`), + complete: () => logger(chalk.bgGreen.bold('complete!')) + }; +}; + +export const enableLog = tag => debug.enable(tag); + +export const log = (tag, logger = defaultLogger(tag)) => { if (debug.enabled(tag)) { return source => { return new Observable(observer => { return source.subscribe({ next: val => { - logger(val); + logger.default(val); observer.next(val); }, error: err => { - error(err); + logger.error(err); observer.error(err); }, complete: () => { - logger(bgGreen.bold('complete!')); + logger.complete(); observer.complete(); } }); @@ -33,11 +79,12 @@ export const log = tag => { return source => source; }; -export const logResult = (tag, observable) => { +export const logResult = (tag, observable, logger = tableLogger) => { return new Promise(done => { connectable( observable.pipe( - log(tag), + toArray(), + log(tag, logger(tag)), finalize(() => done()) ), { connector: () => new Subject() } diff --git a/packages/operators/src/log.test.js b/packages/operators/src/log.test.js index 4b4aeb1..254d620 100644 --- a/packages/operators/src/log.test.js +++ b/packages/operators/src/log.test.js @@ -1,8 +1,9 @@ import { from, map } from 'rxjs'; import { TestScheduler } from 'rxjs/testing'; +import stripAnsi from 'strip-ansi'; import { afterAll, beforeEach, describe, expect, test, vi } from 'vitest'; -import { enableLog, log, logResult } from './log'; +import { defaultLogger, enableLog, log, logResult } from './log'; describe('log', () => { let testScheduler; @@ -39,7 +40,7 @@ describe('log', () => { const actual = []; vi.spyOn(console, 'log').mockImplementation(v => { - actual.push(replaceDateTimeISOString(stripAnsiCodes(v))); + actual.push(replaceDateTimeISOString(stripAnsi(v))); return v; }); @@ -55,36 +56,47 @@ describe('log', () => { }); }); - test('logResult', async () => { + test('logResult - defaultLogger', async () => { const actual = []; + vi.spyOn(console, 'log').mockImplementation(v => { - actual.push(replaceDateTimeISOString(stripAnsiCodes(v))); + actual.push(replaceDateTimeISOString(stripAnsi(v))); return v; }); const expectedVal = [ - ' operators:log:result content a', - ' operators:log:result content b', - ' operators:log:result content c', + " operators:log:result [ 'content a', 'content b', 'content c' ]", ' operators:log:result complete!' ]; const triggerVal = ['content a', 'content b', 'content c']; + enableLog('operators:log:result'); + await logResult('operators:log:result', from(triggerVal), defaultLogger); + expect(actual).deep.equal(expectedVal); + }); + + test('logResult - tableLogger', async () => { + const actual = []; + + vi.spyOn(console, 'log').mockImplementation(v => { + actual.push(replaceDateTimeISOString(stripAnsi(v))); + return v; + }); + + const expectedVal = [ + ` operators:log:result +-------+-------------+\n| index | text |\n+-------+-------------+\n| 0 | 'content a' |\n| 1 | 'content b' |\n| 2 | 'content c' |\n+-------+-------------+\n`, + ' operators:log:result complete!' + ]; + + const triggerVal = [{ text: 'content a' }, { text: 'content b' }, { text: 'content c' }]; + enableLog('operators:log:result'); await logResult('operators:log:result', from(triggerVal)); expect(actual).deep.equal(expectedVal); }); }); -const stripAnsiCodes = str => { - return str.replace( - // eslint-disable-next-line security/detect-unsafe-regex, no-control-regex - /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, - '' - ); -}; - const replaceDateTimeISOString = str => { return str.replace( /^[0-9]{4}-((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01])|(0[469]|11)-(0[1-9]|[12][0-9]|30)|(02)-(0[1-9]|[12][0-9]))T(0[0-9]|1[0-9]|2[0-3]):(0[0-9]|[1-5][0-9]):(0[0-9]|[1-5][0-9])\.[0-9]{3}Z/, diff --git a/packages/playground/src/demo/index.test.js b/packages/playground/src/demo/index.test.js index 6d32614..7ed7226 100644 --- a/packages/playground/src/demo/index.test.js +++ b/packages/playground/src/demo/index.test.js @@ -1,7 +1,7 @@ import { delay, from } from 'rxjs'; import { describe, test } from 'vitest'; -describe('playground stephan', () => { +describe.skip('playground stephan', () => { test('basics', async () => { const s = from([1, 2, 3, 4, 5, 6, 7, 8, 9]) .pipe(delay(4000)) diff --git a/vitest.config.js b/vitest.config.js index c904251..7b9dbd8 100644 --- a/vitest.config.js +++ b/vitest.config.js @@ -12,6 +12,7 @@ export default defineConfig({ 'commitlint.config.js', 'eslint.ignores.js', 'vitest.workspace.js', + './coverage/**/*.*', './packages/mocks/', './packages/*/src/index.js' ]