@applitools/autonomous-errors-builder
Advanced tools
Comparing version 1.0.10 to 1.1.4
{ | ||
"name": "@applitools/autonomous-errors-builder", | ||
"version": "1.0.10", | ||
"version": "1.1.4", | ||
"description": "", | ||
"main": "dist/index.js", | ||
"type": "module", | ||
"scripts": { | ||
"test": "npm run test", | ||
"lint": "eslint ." | ||
"test": "jest", | ||
"lint": "eslint .", | ||
"release": "standard-version --no-verify" | ||
}, | ||
@@ -35,4 +37,6 @@ "repository": { | ||
"jest": "^29.5.0", | ||
"jest-junit": "^16.0.0", | ||
"prettier": "^2.8.8", | ||
"prettier-config-standard": "^5.0.0", | ||
"standard-version": "^9.5.0", | ||
"ts-jest": "^29.1.0", | ||
@@ -39,0 +43,0 @@ "typescript": "^5.1.3" |
import { ErrorCode } from '../types/errorCode'; | ||
import { errorStatusCode } from '../types/statusCode'; | ||
import * as crypto from 'crypto'; | ||
export class AutonomousError { | ||
private readonly id: string; | ||
constructor( | ||
private code: ErrorCode, | ||
private message?: string, | ||
private params?: Record<string, string | undefined> | ||
private message: string, | ||
private params?: Record<string, string | undefined>, | ||
private isUniquePerExec: boolean = true | ||
) { | ||
this.id = crypto.randomUUID(); | ||
if (this.params) { | ||
@@ -22,8 +18,8 @@ this.params.statusCode = errorStatusCode[code] as string | undefined; | ||
resource.error = { | ||
id: this.id, | ||
code: this.code, | ||
message: this.message, | ||
params: this.params, | ||
isUniquePerExec: this.isUniquePerExec, | ||
}; | ||
} | ||
} |
@@ -7,7 +7,3 @@ import { ErrorCode } from './types/errorCode'; | ||
import { UrlNotFoundError } from './errors/UrlNotFoundError'; | ||
import { AbortedError } from './errors/AbortedError'; | ||
export * from './errors/AutonomousError'; | ||
export * from './types/errorCode'; | ||
export function getError( | ||
@@ -21,3 +17,3 @@ code: ErrorCode, | ||
case ErrorCode.Aborted: | ||
return new AbortedError(); | ||
return null; | ||
case ErrorCode.UrlNotFound: | ||
@@ -24,0 +20,0 @@ return new UrlNotFoundError(options); |
@@ -6,13 +6,6 @@ import { ErrorCode } from '../src/types/errorCode'; | ||
import { getError } from '../src'; | ||
import { Message } from '../src/message'; | ||
import crypto from 'crypto'; | ||
import { AbortedError } from '../src/errors/AbortedError'; | ||
describe('errors tests', () => { | ||
beforeEach(() => { | ||
jest.spyOn(crypto, 'randomUUID').mockReturnValue('1-1-1-1-1'); | ||
}); | ||
it.each([ | ||
[ErrorCode.Aborted, new AbortedError()], | ||
[ErrorCode.Aborted, null], | ||
[ErrorCode.Tunnel, new TunnelError({ tunnelName: 'someTunnel' })], | ||
@@ -32,47 +25,4 @@ [ErrorCode.Unexpected, new UnexpectedServerError()], | ||
// Assert | ||
expect(actual).toEqual(expected ? { ...expected, id: '1-1-1-1-1' } : null); | ||
expect(actual).toEqual(expected); | ||
}); | ||
it.each([ | ||
[ | ||
{ type: ErrorCode.Tunnel, options: { tunnelName: 'someTunnel' } }, | ||
{ | ||
id: '1-1-1-1-1', | ||
code: ErrorCode.Tunnel, | ||
message: Message.Tunnel, | ||
params: { statusCode: undefined, tunnelName: 'someTunnel' }, | ||
}, | ||
], | ||
[ | ||
{ type: ErrorCode.Unexpected, options: {} }, | ||
{ | ||
id: '1-1-1-1-1', | ||
code: ErrorCode.Unexpected, | ||
message: Message.Unexpected, | ||
params: undefined, | ||
}, | ||
], | ||
[ | ||
{ type: ErrorCode.UrlNotFound, options: { url: 'https://someUrl.com' } }, | ||
{ | ||
id: '1-1-1-1-1', | ||
code: ErrorCode.UrlNotFound, | ||
message: Message.PageNotFound, | ||
params: { | ||
statusCode: 404, | ||
url: 'https://someUrl.com', | ||
}, | ||
}, | ||
], | ||
])('should serialize the error $#', async ({ type, options }, expected) => { | ||
// Arrange | ||
const resource = {}; | ||
const error = getError(type, options); | ||
// Act | ||
error?.assign(resource); | ||
// Assert | ||
expect(resource).toStrictEqual({ error: expected }); | ||
}); | ||
}); |
@@ -37,5 +37,4 @@ { | ||
"exclude": [ | ||
"node_modules/**/*", | ||
"test" | ||
"node_modules/**/*" | ||
] | ||
} |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Yes
13430
20
19
201
1