From 2bdb68aa89bccec7de441d0834f5c982c6473b80 Mon Sep 17 00:00:00 2001 From: Muhammad Rendra Date: Wed, 13 Nov 2024 22:42:16 +0700 Subject: [PATCH] feat: provide validate-skipped-stacks (#44) issues: * feat: provide validate-skipped-stacks (#43) commits: * feat: provide validate-skipped-stacks (90faa6e) --- README.md | 17 ++++++++++++++++- __tests__/index.ts | 36 +++++++++++++++++++++++++++++++++--- package-lock.json | 10 ++++++++++ package.json | 3 +++ src/index.ts | 6 ++++++ 5 files changed, 68 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ff7f496..9d1f99a 100644 --- a/README.md +++ b/README.md @@ -54,11 +54,26 @@ stackTrace( ) ``` +## Utils +```javascript +import { + /** + * A utility to validate a name or a list of names of stack traces that need to be skipped. + * + * @see https://github.com/mnrendra/validate-skipped-stacks + */ + validateSkippedStacks +} from '@mnrendra/stack-trace' +``` + ## Types ```typescript import type { CallSite, // NodeJS.CallSite - Options // { limit?: number } + Options, // { limit?: number }, + // @mnrendra/validate-skipped-stacks + SkippedStacks, + ValidSkippedStacks } from '@mnrendra/stack-trace' ``` diff --git a/__tests__/index.ts b/__tests__/index.ts index 5ed077c..596a909 100644 --- a/__tests__/index.ts +++ b/__tests__/index.ts @@ -1,4 +1,4 @@ -import { stackTrace } from '..' +import { stackTrace, validateSkippedStacks } from '..' describe('Test all features:', () => { describe('Test `stackTrace` feature:', () => { @@ -18,13 +18,20 @@ describe('Test all features:', () => { ]) }) - it('Should only return the first default value when given an option with `limit` is set to `1`!', () => { + it('Should only return the first default value when given an option with `limit` is set to `1` and first argument is set to `undefined`!', () => { const result = stackTrace(undefined, { limit: 1 }) expect(result).toEqual([ expect.any(Object) ]) }) + it('Should only return the first default value when given an option with `limit` is set to `1` and first argument is set to `null`!', () => { + const result = stackTrace(null, { limit: 1 }) + expect(result).toEqual([ + expect.any(Object) + ]) + }) + describe('Test properties of the first default value from the `stackTrace` when given an empty argument:', () => { it('Should return a `string` (a type name) when invoke the `getTypeName` property!', () => { const result = stackTrace() @@ -38,7 +45,7 @@ describe('Test all features:', () => { it('Should return a `number` (a line number) when invoke the `getLineNumber` property!', () => { const result = stackTrace() - expect(result[0].getLineNumber()).toBe(37) + expect(result[0].getLineNumber()).toBe(43) }) it('Should return a `number` (a column number) when invoke the `getColumnNumber` property!', () => { @@ -92,4 +99,27 @@ describe('Test all features:', () => { }) }) }) + + describe('Test `validateSkippedStacks` feature:', () => { + it('Should return a valid skipped-stacks when given a skipped-stack!', () => { + const received = validateSkippedStacks('SKIPPED_STACK') + const expected = ['SKIPPED_STACK'] + + expect(received).toEqual(expected) + }) + + it('Should return a valid skipped-stacks when given a skipped-stack and a `skippedStacks` option with a string!', () => { + const received = validateSkippedStacks('SKIPPED_STACK', 'any') + const expected = ['SKIPPED_STACK', 'any'] + + expect(received).toEqual(expected) + }) + + it('Should return a valid skipped-stacks when given a skipped-stack and a `skippedStacks` option with a list of strings!', () => { + const received = validateSkippedStacks('SKIPPED_STACK', ['any']) + const expected = ['SKIPPED_STACK', 'any'] + + expect(received).toEqual(expected) + }) + }) }) diff --git a/package-lock.json b/package-lock.json index a012e68..56f16be 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,9 @@ "name": "@mnrendra/stack-trace", "version": "1.3.0", "license": "MIT", + "dependencies": { + "@mnrendra/validate-skipped-stacks": "^2.0.1" + }, "devDependencies": { "@semantic-release/exec": "^6.0.3", "@semantic-release/git": "^10.0.1", @@ -2144,6 +2147,12 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, + "node_modules/@mnrendra/validate-skipped-stacks": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@mnrendra/validate-skipped-stacks/-/validate-skipped-stacks-2.0.1.tgz", + "integrity": "sha512-XvpumivqFnPDAB7Q6fhKViO1+rU+eWu7puiTSKwiDoMekk0Y0WKa7wZvWcy/wvA2CoXfQAD+zOwe+nvEQlHYOA==", + "license": "MIT" + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -7754,6 +7763,7 @@ "integrity": "sha512-QQnnxNyfvmHFIsj7gkPcYymR8Jdw/o7mp5ZFihxn6h8Ci6fh3Dx4E1gPjpQEpIuPo9XVNY/ZUwh4BPMjGyL01g==", "dev": true, "license": "ISC", + "optional": true, "engines": { "node": "^14.17.0 || ^16.13.0 || >=18.0.0" } diff --git a/package.json b/package.json index 6e383c8..125cb77 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,9 @@ "url": "https://github.com/mnrendra/stack-trace/issues" }, "homepage": "https://github.com/mnrendra/stack-trace#readme", + "dependencies": { + "@mnrendra/validate-skipped-stacks": "^2.0.1" + }, "devDependencies": { "@semantic-release/exec": "^6.0.3", "@semantic-release/git": "^10.0.1", diff --git a/src/index.ts b/src/index.ts index 72548a9..ad14b6d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,11 @@ import main from './main' +export { + type SkippedStacks, + type ValidSkippedStacks, + validateSkippedStacks +} from '@mnrendra/validate-skipped-stacks' + export type { CallSite, Options