Skip to content

Commit

Permalink
feat: provide validate-skipped-stacks (#44)
Browse files Browse the repository at this point in the history
issues:
* feat: provide validate-skipped-stacks (#43)

commits:
* feat: provide validate-skipped-stacks (90faa6e)
  • Loading branch information
mnrendra authored Nov 13, 2024
1 parent 983c394 commit 2bdb68a
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 4 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
```
Expand Down
36 changes: 33 additions & 3 deletions __tests__/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { stackTrace } from '..'
import { stackTrace, validateSkippedStacks } from '..'

describe('Test all features:', () => {
describe('Test `stackTrace` feature:', () => {
Expand All @@ -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()
Expand All @@ -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!', () => {
Expand Down Expand Up @@ -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)
})
})
})
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import main from './main'

export {
type SkippedStacks,
type ValidSkippedStacks,
validateSkippedStacks
} from '@mnrendra/validate-skipped-stacks'

export type {
CallSite,
Options
Expand Down

0 comments on commit 2bdb68a

Please sign in to comment.