Skip to content

Commit 6a10cb2

Browse files
committed
removed 'static' classes in favour of module import, moved extras project to web as it has dependency on it
1 parent 0b2110c commit 6a10cb2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2843
-1226
lines changed

@bellatrix/core/package-lock.json

Lines changed: 870 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

@bellatrix/core/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
"vitest": "^3.0.5"
2323
},
2424
"devDependencies": {
25+
"@types/mocha": "^10.0.10",
2526
"c8": "^9.1.0",
2627
"chai": "^4.4.1",
2728
"cross-env": "^7.0.3",
28-
"fix-esm-import-path": "^1.5.0"
29+
"fix-esm-import-path": "^1.5.0",
30+
"mocha": "^11.1.0"
2931
},
3032
"scripts": {
3133
"build": "tsc",

@bellatrix/core/src/assertions/Assertions.ts

Lines changed: 57 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-namespace */
12
export type EqualityOptions = {
23
strict: boolean;
34
}
@@ -60,16 +61,12 @@ class BellatrixAssertionError extends Error {
6061
}
6162
}
6263

63-
export class Assert {
64-
private constructor() {
65-
throw new Error('PluginExecutionEngine is static and cannot be instantiated');
66-
}
67-
68-
static areEqual(expected: unknown, actual: unknown, message?: string): void
69-
static areEqual(expected: unknown, actual: unknown, options?: EqualityOptions, message?: string): void
70-
static areEqual(expected: unknown, actual: unknown, options?: EqualityOptions | string, message?: string) {
64+
export namespace Assert {
65+
export function areEqual(expected: unknown, actual: unknown, message?: string): void
66+
export function areEqual(expected: unknown, actual: unknown, options?: EqualityOptions, message?: string): void
67+
export function areEqual(expected: unknown, actual: unknown, options?: EqualityOptions | string, message?: string) {
7168
if (typeof options === 'string') {
72-
return this.areEqual(expected, actual, undefined, options);
69+
return areEqual(expected, actual, undefined, options);
7370
}
7471

7572
options ??= { strict: false };
@@ -83,11 +80,11 @@ export class Assert {
8380
}
8481
}
8582

86-
static areDeepEqual(expected: unknown, actual: unknown, message?: string): void
87-
static areDeepEqual(expected: unknown, actual: unknown, options?: EqualityOptions, message?: string): void
88-
static areDeepEqual(expected: unknown, actual: unknown, options?: EqualityOptions | string, message?: string) {
83+
export function areDeepEqual(expected: unknown, actual: unknown, message?: string): void
84+
export function areDeepEqual(expected: unknown, actual: unknown, options?: EqualityOptions, message?: string): void
85+
export function areDeepEqual(expected: unknown, actual: unknown, options?: EqualityOptions | string, message?: string) {
8986
if (typeof options === 'string') {
90-
return this.areDeepEqual(expected, actual, undefined, options);
87+
return areDeepEqual(expected, actual, undefined, options);
9188
}
9289

9390
options ??= { strict: false };
@@ -97,11 +94,11 @@ export class Assert {
9794
}
9895
}
9996

100-
static areApproximatelyEqual(expected: number, actual: number, decimalPlaces: number, message?: string): void
101-
static areApproximatelyEqual(expected: number, actual: number, decimalPlaces: number, options?: ApproximateEqualityOptions, message?: string): void
102-
static areApproximatelyEqual(expected: number, actual: number, decimalPlaces: number, options?: ApproximateEqualityOptions | string, message?: string) {
97+
export function areApproximatelyEqual(expected: number, actual: number, decimalPlaces: number, message?: string): void
98+
export function areApproximatelyEqual(expected: number, actual: number, decimalPlaces: number, options?: ApproximateEqualityOptions, message?: string): void
99+
export function areApproximatelyEqual(expected: number, actual: number, decimalPlaces: number, options?: ApproximateEqualityOptions | string, message?: string) {
103100
if (typeof options === 'string') {
104-
return this.areApproximatelyEqual(expected, actual, decimalPlaces, undefined, options);
101+
return areApproximatelyEqual(expected, actual, decimalPlaces, undefined, options);
105102
}
106103

107104
options ??= { method: 'round' };
@@ -114,11 +111,11 @@ export class Assert {
114111
}
115112
}
116113

117-
static areNotEqual(expected: unknown, actual: unknown, message?: string): void
118-
static areNotEqual(expected: unknown, actual: unknown, options?: EqualityOptions, message?: string): void
119-
static areNotEqual(expected: unknown, actual: unknown, options?: EqualityOptions | string, message?: string) {
114+
export function areNotEqual(expected: unknown, actual: unknown, message?: string): void
115+
export function areNotEqual(expected: unknown, actual: unknown, options?: EqualityOptions, message?: string): void
116+
export function areNotEqual(expected: unknown, actual: unknown, options?: EqualityOptions | string, message?: string) {
120117
if (typeof options === 'string') {
121-
return this.areNotEqual(expected, actual, undefined, options);
118+
return areNotEqual(expected, actual, undefined, options);
122119
}
123120

124121
options ??= { strict: false };
@@ -134,11 +131,11 @@ export class Assert {
134131
}
135132
}
136133

137-
static areNotDeepEqual(expected: unknown, actual: unknown, message?: string): void
138-
static areNotDeepEqual(expected: unknown, actual: unknown, options?: EqualityOptions, message?: string): void
139-
static areNotDeepEqual(expected: unknown, actual: unknown, options?: EqualityOptions | string, message?: string) {
134+
export function areNotDeepEqual(expected: unknown, actual: unknown, message?: string): void
135+
export function areNotDeepEqual(expected: unknown, actual: unknown, options?: EqualityOptions, message?: string): void
136+
export function areNotDeepEqual(expected: unknown, actual: unknown, options?: EqualityOptions | string, message?: string) {
140137
if (typeof options === 'string') {
141-
return this.areNotDeepEqual(expected, actual, undefined, options);
138+
return areNotDeepEqual(expected, actual, undefined, options);
142139
}
143140

144141
options ??= { strict: false };
@@ -148,11 +145,11 @@ export class Assert {
148145
}
149146
}
150147

151-
static areNotApproximatelyEqual(expected: number, actual: number, decimalPlaces: number, message?: string): void
152-
static areNotApproximatelyEqual(expected: number, actual: number, decimalPlaces: number, options?: ApproximateEqualityOptions, message?: string): void
153-
static areNotApproximatelyEqual(expected: number, actual: number, decimalPlaces: number, options?: ApproximateEqualityOptions | string, message?: string) {
148+
export function areNotApproximatelyEqual(expected: number, actual: number, decimalPlaces: number, message?: string): void
149+
export function areNotApproximatelyEqual(expected: number, actual: number, decimalPlaces: number, options?: ApproximateEqualityOptions, message?: string): void
150+
export function areNotApproximatelyEqual(expected: number, actual: number, decimalPlaces: number, options?: ApproximateEqualityOptions | string, message?: string) {
154151
if (typeof options === 'string') {
155-
return this.areNotApproximatelyEqual(expected, actual, decimalPlaces, undefined, options);
152+
return areNotApproximatelyEqual(expected, actual, decimalPlaces, undefined, options);
156153
}
157154

158155
options ??= { method: 'round' };
@@ -165,112 +162,112 @@ export class Assert {
165162
}
166163
}
167164

168-
static isFalse(value: boolean, message?: string) {
165+
export function isFalse(value: boolean, message?: string) {
169166
const result = value === false;
170167
if (result === false) {
171168
throw new BellatrixAssertionError('false', String(value), message);
172169
}
173170
}
174171

175-
static isFalsy(value: unknown, message?: string) {
172+
export function isFalsy(value: unknown, message?: string) {
176173
const result = value == false;
177174
if (result === false) {
178175
throw new BellatrixAssertionError('falsy', quoteString(value), message);
179176
}
180177
}
181178

182-
static isTrue(value: boolean, message?: string) {
179+
export function isTrue(value: boolean, message?: string) {
183180
const result = value === true;
184181
if (result === false) {
185182
throw new BellatrixAssertionError('true', String(value), message);
186183
}
187184
}
188185

189-
static isTruthy(value: unknown, message?: string) {
186+
export function isTruthy(value: unknown, message?: string) {
190187
const result = value == true;
191188
if (result === false) {
192189
throw new BellatrixAssertionError('truthy', quoteString(value), message);
193190
}
194191
}
195192

196-
static isNaN(value: unknown, message?: string): void
197-
static isNaN(value: unknown, options?: EqualityOptions, message?: string): void
198-
static isNaN(value: unknown, options?: EqualityOptions | string, message?: string) {
193+
export function isNaN(value: unknown, message?: string): void
194+
export function isNaN(value: unknown, options?: EqualityOptions, message?: string): void
195+
export function isNaN(value: unknown, options?: EqualityOptions | string, message?: string) {
199196
if (typeof options === 'string') {
200-
return this.isNaN(value, undefined, options);
197+
return isNaN(value, undefined, options);
201198
}
202199

203200
options ??= { strict: false };
204-
const result = isNaN(value as number) && options.strict ? typeof value === 'number' : true;
201+
const result = globalThis.isNaN(value as number) && options.strict ? typeof value === 'number' : true;
205202
if (result === false) {
206203
throw new BellatrixAssertionError('NaN', quoteString(value), message);
207204
}
208205
}
209206

210-
static isNull(value: unknown, message?: string) {
207+
export function isNull(value: unknown, message?: string) {
211208
const result = value === null;
212209
if (result === false) {
213210
throw new BellatrixAssertionError('null', quoteString(value), message);
214211
}
215212
}
216213

217-
static isNotNull(value: unknown, message?: string) {
214+
export function isNotNull(value: unknown, message?: string) {
218215
const result = value !== null;
219216
if (result === false) {
220217
throw new BellatrixAssertionError('not null', undefined, message);
221218
}
222219
}
223220

224-
static isDefined(value: unknown, message?: string) {
221+
export function isDefined(value: unknown, message?: string) {
225222
const result = value !== undefined;
226223
if (result === false) {
227224
throw new BellatrixAssertionError('not undefined', undefined, message);
228225
}
229226
}
230227

231-
static isUndefined(value: unknown, message?: string) {
228+
export function isUndefined(value: unknown, message?: string) {
232229
const result = value === undefined;
233230
if (result === false) {
234231
throw new BellatrixAssertionError('undefined', quoteString(value), message);
235232
}
236233
}
237234

238-
static stringContains(substring: string, value: string, message?: string) {
235+
export function stringContains(substring: string, value: string, message?: string) {
239236
const result = value.includes(substring);
240237
if (result === false) {
241238
throw new BellatrixAssertionError(`contains ${substring}`, quoteString(value), message);
242239
}
243240
}
244241

245-
static arrayIsEmpty(array: unknown[], message?: string) {
242+
export function arrayIsEmpty(array: unknown[], message?: string) {
246243
const result = Array.isArray(array) && array.length === 0;
247244
if (result === false) {
248245
throw new BellatrixAssertionError('[]', quoteString(array), message);
249246
}
250247
}
251248

252-
static arrayIsNotEmpty(array: unknown[], message?: string) {
249+
export function arrayIsNotEmpty(array: unknown[], message?: string) {
253250
const result = Array.isArray(array) && array.length > 0;
254251
if (result === false) {
255252
throw new BellatrixAssertionError('[]', quoteString(array), message);
256253
}
257254
}
258255

259-
static isInstanceOf(instanceOf: Function, value: unknown, message?: string) {
256+
export function isInstanceOf(instanceOf: Function, value: unknown, message?: string) {
260257
const result = value instanceof instanceOf;
261258
if (result === false) {
262259
throw new BellatrixAssertionError(`instance of ${instanceOf.name}`, (value as object).constructor.name, message);
263260
}
264261
}
265262

266-
static isNotInstanceOf(instanceOf: Function, value: unknown, message?: string) {
263+
export function isNotInstanceOf(instanceOf: Function, value: unknown, message?: string) {
267264
const result = !(value instanceof instanceOf);
268265
if (result === false) {
269266
throw new BellatrixAssertionError(`not instance of ${instanceOf.name}`, value.constructor.name, message);
270267
}
271268
}
272269

273-
static arrayIsSubsetOf(subsetOf: unknown[], array: unknown[], message?: string) {
270+
export function arrayIsSubsetOf(subsetOf: unknown[], array: unknown[], message?: string) {
274271
const result = array.every((item) => subsetOf.includes(item));
275272

276273
const arraySet = new Set(array);
@@ -289,15 +286,15 @@ export class Assert {
289286
}
290287
}
291288

292-
static arrayIsNotSubsetOf(subsetOf: unknown[], array: unknown[], message?: string) {
289+
export function arrayIsNotSubsetOf(subsetOf: unknown[], array: unknown[], message?: string) {
293290
const result = array.every((item) => subsetOf.includes(item));
294291

295292
if (result === false) {
296293
throw new BellatrixAssertionError(`not subset of ${quoteString(subsetOf)}`, quoteString(array), message);
297294
}
298295
}
299296

300-
static arrayIsSupersetOf(supersetOf: unknown[], array: unknown[], message?: string) {
297+
export function arrayIsSupersetOf(supersetOf: unknown[], array: unknown[], message?: string) {
301298
const result = supersetOf.every((item) => array.includes(item));
302299

303300
const arraySet = new Set(array);
@@ -316,19 +313,19 @@ export class Assert {
316313
}
317314
}
318315

319-
static arrayIsNotSupersetOf(supersetOf: unknown[], array: unknown[], message?: string) {
316+
export function arrayIsNotSupersetOf(supersetOf: unknown[], array: unknown[], message?: string) {
320317
const result = !supersetOf.every((item) => array.includes(item));
321318

322319
if (result === false) {
323320
throw new BellatrixAssertionError(`not be superset of ${quoteString(supersetOf)}`, quoteString(array), message);
324321
}
325322
}
326323

327-
static that<T>(value: T, ...expressions: AssertExpression<T>[]): void
328-
static that<T>(value: T, options: AssertMultipleOptions, ...expressions: AssertExpression<T>[]): void
329-
static that<T>(value: T, options?: AssertMultipleOptions | AssertExpression<T>, ...expressions: AssertExpression<T>[]) {
324+
export function that<T>(value: T, ...expressions: AssertExpression<T>[]): void
325+
export function that<T>(value: T, options: AssertMultipleOptions, ...expressions: AssertExpression<T>[]): void
326+
export function that<T>(value: T, options?: AssertMultipleOptions | AssertExpression<T>, ...expressions: AssertExpression<T>[]) {
330327
if (typeof options !== 'object') {
331-
return this.that(value, {}, options!, ...expressions);
328+
return that(value, {}, options!, ...expressions);
332329
}
333330

334331
if (expressions[0] === undefined) {
@@ -358,11 +355,11 @@ export class Assert {
358355
}
359356
}
360357

361-
static async multiple(...expressions: Function[]): Promise<void>
362-
static async multiple(options: AssertMultipleOptions, ...expressions: Function[]): Promise<void>
363-
static async multiple(options?: AssertMultipleOptions | Function, ...expressions: Function[]) {
358+
export async function multiple(...expressions: Function[]): Promise<void>
359+
export async function multiple(options: AssertMultipleOptions, ...expressions: Function[]): Promise<void>
360+
export async function multiple(options?: AssertMultipleOptions | Function, ...expressions: Function[]) {
364361
if (typeof options !== 'object') {
365-
return this.multiple({}, options!, ...expressions);
362+
return multiple({}, options!, ...expressions);
366363
}
367364

368365
if (expressions[0] === undefined) {
@@ -581,7 +578,7 @@ export const is = {
581578
};
582579
},
583580
},
584-
} as const;
581+
};
585582

586583
function deepEquals(obj1: unknown, obj2: unknown, strict: boolean) {
587584
if (obj1 === obj2) return true;

@bellatrix/core/src/decorators/Category.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BellatrixTest } from '@bellatrix/core/infrastructure';
22
import { Method, ParameterlessCtor } from '@bellatrix/core/types';
3-
import { DecoratorUtilities } from '@bellatrix/core/utilities';
4-
import { BellatrixSymbol } from '../test/_common';
3+
import { getMetadataFor } from '@bellatrix/core/utilities';
4+
import { Internal } from '../test/_common';
55

66
const categoryKeyword = 'category';
77

@@ -15,10 +15,10 @@ function Category<
1515
const testClass = testMethodOrClass as Class;
1616
const testMethods = Object.getOwnPropertyNames(testClass.prototype)
1717
.filter(method => typeof testClass.prototype[method] === 'function' &&
18-
DecoratorUtilities.getMetadata(testClass.prototype[method])?.[BellatrixSymbol.hasTestDecorator]);
18+
getMetadataFor(testClass.prototype[method])?.[Internal.hasTestDecorator]);
1919

2020
for (const testMethod of testMethods) {
21-
const testMetadata = DecoratorUtilities.getMetadata(testClass.prototype[testMethod]);
21+
const testMetadata = getMetadataFor(testClass.prototype[testMethod]);
2222

2323
if (!testMetadata.customData.has(categoryKeyword)) {
2424
testMetadata.customData.set(categoryKeyword, []);
@@ -37,7 +37,7 @@ function Category<
3737

3838
if (context.kind === 'method') {
3939
const testMethod = testMethodOrClass as ClassMethod;
40-
const testMetadata = DecoratorUtilities.getMetadata(testMethod);
40+
const testMetadata = getMetadataFor(testMethod);
4141

4242
if (!testMetadata.customData.has(categoryKeyword)) {
4343
testMetadata.customData.set(categoryKeyword, []);

@bellatrix/core/src/decorators/Ignore.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BellatrixTest } from '@bellatrix/core/infrastructure';
22
import { Method, ParameterlessCtor } from '@bellatrix/core/types';
3-
import { DecoratorUtilities } from '@bellatrix/core/utilities';
4-
import { BellatrixSymbol } from '../test/_common';
3+
import { getMetadataFor } from '@bellatrix/core/utilities';
4+
import { Internal } from '../test/_common';
55

66
function Ignore<
77
ClassMethod extends (this: This, ...args: never) => void,
@@ -12,21 +12,21 @@ function Ignore<
1212
const testClass = testMethodOrClass as Class;
1313
const testMethods = Object.getOwnPropertyNames(testClass.prototype)
1414
.filter(method => typeof testClass.prototype[method] === 'function' &&
15-
DecoratorUtilities.getMetadata(testClass.prototype[method])?.[BellatrixSymbol.hasTestDecorator]);
15+
getMetadataFor(testClass.prototype[method])?.[Internal.hasTestDecorator]);
1616

1717
for (const testMethod of testMethods) {
18-
const testMetadata = DecoratorUtilities.getMetadata(testClass.prototype[testMethod]);
18+
const testMetadata = getMetadataFor(testClass.prototype[testMethod]);
1919

20-
testMetadata[BellatrixSymbol.shouldSkip] = true;
20+
testMetadata[Internal.shouldSkip] = true;
2121
return;
2222
}
2323
}
2424

2525
if (context.kind === 'method') {
2626
const testMethod = testMethodOrClass as ClassMethod;
27-
const testMetadata = DecoratorUtilities.getMetadata(testMethod);
27+
const testMetadata = getMetadataFor(testMethod);
2828

29-
testMetadata[BellatrixSymbol.shouldSkip] = true;
29+
testMetadata[Internal.shouldSkip] = true;
3030
return;
3131
}
3232

0 commit comments

Comments
 (0)