🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@elementor/utils

Package Overview
Dependencies
Maintainers
7
Versions
865
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@elementor/utils - npm Package Compare versions

Comparing version
0.2.0
to
0.2.1
+6
-0
CHANGELOG.md

@@ -6,2 +6,8 @@ # Change Log

## [0.2.1](https://github.com/elementor/elementor-packages/compare/@elementor/utils@0.2.0...@elementor/utils@0.2.1) (2024-08-05)
### Bug Fixes
- publish only necessary files to npm ([#226](https://github.com/elementor/elementor-packages/issues/226)) ([d808e2f](https://github.com/elementor/elementor-packages/commit/d808e2f60eb7ca2d7b8560d0b79c0e62c2f969a8))
# [0.2.0](https://github.com/elementor/elementor-packages/compare/@elementor/utils@0.1.0...@elementor/utils@0.2.0) (2024-07-28)

@@ -8,0 +14,0 @@

+10
-3
{
"name": "@elementor/utils",
"description": "This package contains utility functions that are being used across the Elementor packages",
"version": "0.2.0",
"version": "0.2.1",
"private": false,

@@ -22,3 +22,3 @@ "author": "Elementor Team",

"type": "git",
"url": "https://github.com/elementor/elementor-packages.git",
"url": "git+https://github.com/elementor/elementor-packages.git",
"directory": "packages/libs/utils"

@@ -32,2 +32,9 @@ },

},
"files": [
"README.md",
"CHANGELOG.md",
"/dist",
"/src",
"!**/__tests__"
],
"scripts": {

@@ -37,3 +44,3 @@ "build": "tsup --config=../../tsup.build.ts",

},
"gitHead": "c2f7a53e5af66a39640eb0849065d07efd554690"
"gitHead": "f4ca33da0842a29d83736d0a173633085edddaee"
}
> @elementor/utils@0.1.0 build
> tsup --config=../../tsup.build.ts
CLI Building entry: src/index.ts
CLI Using tsconfig: ../../../tsconfig.json
CLI tsup v7.2.0
CLI Using tsup config: /home/runner/work/elementor-packages/elementor-packages/tsup.build.ts
CLI Target: esnext
CLI Cleaning output folder
ESM Build start
CJS Build start
ESM dist/index.mjs 922.00 B
ESM dist/index.mjs.map 2.13 KB
ESM ⚡️ Build success in 114ms
CJS dist/index.js 1.97 KB
CJS dist/index.js.map 2.35 KB
CJS ⚡️ Build success in 115ms
DTS Build start
DTS ⚡️ Build success in 22795ms
DTS dist/index.d.mts 1.24 KB
DTS dist/index.d.ts 1.24 KB
import { createError } from '../create-error';
import { ElementorError } from '../elementor-error';
import { ensureError } from '../ensure-error';
describe( 'createError', () => {
it( 'should return an error class with the correct code and message', () => {
type CustomErrorContext = {
customField: string;
};
// Arrange.
const code = 'test-error';
const message = 'This is a test error';
const CustomError = createError< CustomErrorContext >( { code, message } );
// Act.
const error = new CustomError( {
cause: new Error( 'internal' ),
context: { customField: 'customValue' },
} );
// Assert.
expect( error ).toBeInstanceOf( ElementorError );
expect( error.code ).toBe( code );
expect( error.message ).toBe( message );
expect( error.context ).toEqual( { customField: 'customValue' } );
expect( error.cause ).toEqual( new Error( 'internal' ) );
} );
} );
describe( 'ensureError', () => {
it( 'should return the same error instance when the input is an error', () => {
// Arrange.
const TestError = createError( { code: 'test-error', message: 'This is a test error' } );
const error = new TestError();
// Act.
const result = ensureError( error );
// Assert.
expect( result ).toBe( error );
} );
it( 'should return an error with the stringified input in the error message when the input is not an error', () => {
// Arrange.
const errorObject = { message: 'test error' };
const expectedMessage = JSON.stringify( errorObject );
// Act.
const result = ensureError( errorObject );
// Assert.
expect( result ).toBeInstanceOf( Error );
expect( result.message ).toContain( expectedMessage );
} );
it( "should return an error when the input can't be stringified", () => {
// Arrange.
const errorObject = { circular: {} };
errorObject.circular = errorObject;
// Act.
const result = ensureError( errorObject );
// Assert.
expect( result ).toBeInstanceOf( Error );
expect( result.cause ).toBeInstanceOf( TypeError );
} );
} );