Skip to content

Add test filtering #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7919709
swapped minimist for yargs
teo-nikolov Feb 3, 2025
64a10e0
added filter environment variables and logic to obtain them from cli
teo-nikolov Feb 3, 2025
3a9e601
added test filtering logic to vitest
teo-nikolov Feb 3, 2025
d57b074
Added category decorator
teo-nikolov Feb 3, 2025
c07ef98
added category in CI test (still order dependent)
teo-nikolov Feb 3, 2025
8872e60
updated logic for filters
teo-nikolov Feb 3, 2025
dea9397
added test category
teo-nikolov Feb 3, 2025
2a7c516
fixed duplicate line
teo-nikolov Feb 3, 2025
8e138ad
updated vitest from version 1 to 2, added @Debug for isolationg speci…
teo-nikolov Feb 3, 2025
8c18b44
limit debug to methods
teo-nikolov Feb 3, 2025
d49790e
fixing flaky tests
teo-nikolov Feb 3, 2025
86c9877
update vitest from 2 to 3
teo-nikolov Feb 3, 2025
5791eba
minor cleanup
teo-nikolov Feb 3, 2025
679c75c
remove unused code
Feb 4, 2025
2c18c12
remove comment
Feb 4, 2025
542dd7a
updated root path to be the project/config location and updated vites…
teo-nikolov Feb 4, 2025
80596ce
Merge branch 'add-test-filtering' of https://github.com/AutomateThePl…
Feb 6, 2025
5576372
Changed hooks to use this instead of the instance as first argument
teo-nikolov Feb 6, 2025
e7bcc3a
vitest update and fix playwright child process debugging
teo-nikolov Feb 6, 2025
7e2b4a7
revert config and runner changes
teo-nikolov Feb 6, 2025
8b201d9
added wait to flaky test
teo-nikolov Feb 6, 2025
ba39f20
removed 'run tests' as it will wait for debugger indefinitely in play…
teo-nikolov Feb 6, 2025
7c4595c
Merge branch 'add-test-filtering' of https://github.com/AutomateThePl…
Feb 6, 2025
afaf23a
Merge branch 'add-test-filtering' of https://github.com/AutomateThePl…
Feb 6, 2025
8e164ef
added test timeout to playwright
teo-nikolov Feb 6, 2025
09f5884
updated other test runners
teo-nikolov Feb 6, 2025
2dada89
fixed debug for jest, jasmine and mocha
teo-nikolov Feb 6, 2025
7870b47
fixed issue with test run hanging indefinitely if not in debug
teo-nikolov Feb 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"type": "node",
"request": "launch",
"name": "Run Tests",
"name": "example: debug main process",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run",
Expand All @@ -15,7 +15,35 @@
],
"cwd": "${workspaceFolder}/example",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
"internalConsoleOptions": "neverOpen",
"presentation": {
"hidden": true
},
},
{
"type": "node",
"request": "attach",
"name": "try debug child process",
"port": 12016,
"skipFiles": [
"<node_internals>/**"
],
"timeout": 5000,
"restart": false,
"presentation": {
"hidden": true
},
},
],
"compounds": [
{
"name": "(example) debug tests",
"configurations": ["example: debug main process", "try debug child process"],
"presentation": {
"hidden": false,
"group": "",
"order": 1
},
}
]
}
}
2,923 changes: 1,550 additions & 1,373 deletions @bellatrix/core/package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions @bellatrix/core/package.build.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"USE THIS REGEX TO SELECT THE EXPORTS, THEN CHANGE THEM WITH JS OR STH": "YOU ARE AN IDIOT, JUST IMPORT, MODIFY THE JS OBJECT AND STRINGIFY",
"USE THIS REGEX TO SELECT THE EXPORTS, THEN CHANGE THEM WITH JS OR STH": "JUST IMPORT, MODIFY THE JS OBJECT AND STRINGIFY",
"######": ".*\"exports\": (?=\\{((?:[^{}]++)++)\\})",
"name": "@bellatrix/core",
"version": "0.0.1",
Expand Down Expand Up @@ -44,7 +44,7 @@
"jasmine-core": "^5.1.1",
"mocha": "^10.2.0",
"reflect-metadata": "^0.2.1",
"vitest": "^1.2.1"
"vitest": "^3.0.5"
},
"devDependencies": {
"fix-esm-import-path": "^1.5.0"
Expand Down
5 changes: 3 additions & 2 deletions @bellatrix/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"./test": "./src/test/index.ts",
"./test/props": "./src/test/props.ts",
"./settings": "./src/settings/index.ts",
"./assertions": "./src/assertions/index.ts"
"./assertions": "./src/assertions/index.ts",
"./decorators": "./src/decorators/index.ts"
},
"peerDependencies": {
"typescript": "^5.0.0"
Expand All @@ -24,7 +25,7 @@
"jasmine-core": "^5.1.1",
"mocha": "^10.2.0",
"reflect-metadata": "^0.2.1",
"vitest": "^1.2.1"
"vitest": "^3.0.5"
},
"devDependencies": {
"c8": "^9.1.0",
Expand Down
43 changes: 43 additions & 0 deletions @bellatrix/core/src/decorators/Category.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Symbols } from '@bellatrix/core/constants';
import { BellatrixTest } from '@bellatrix/core/infrastructure';
import { getTestMetadata } from '@bellatrix/core/test/props';
import { ParameterlessCtor } from '@bellatrix/core/types';

export function Category<T extends BellatrixTest>(name: string): (target: ParameterlessCtor<T>) => void {
return (target: ParameterlessCtor<T>) => {
const testClass = target.prototype;
const testMethods = Object.getOwnPropertyNames(testClass).filter(method => typeof testClass[method] === 'function' && Reflect.hasMetadata(Symbols.TEST, testClass[method]));

for (const testMethod of testMethods) {
const metadata = getTestMetadata(testClass[testMethod], testClass);

if (metadata.customData.has('category')) {
const categories = metadata.customData.get('category');
if (!Array.isArray(categories)) {
metadata.customData.set('category', [categories, name]);
} else {
categories.push(name);
}
} else {
metadata.customData.set('category', name);
}
}
};
}

export function TestCategory<T extends BellatrixTest>(name: string): (testClass: T, methodName: string) => void {
return (testClass: T, methodName: string) => {
const metadata = getTestMetadata(testClass[methodName as keyof T] as (...args: unknown[]) => (Promise<void> | void), testClass.constructor as ParameterlessCtor<T>);

if (metadata.customData.has('category')) {
const categories = metadata.customData.get('category');
if (!Array.isArray(categories)) {
metadata.customData.set('category', [categories, name]);
} else {
categories.push(name);
}
} else {
metadata.customData.set('category', name);
}
};
}
8 changes: 8 additions & 0 deletions @bellatrix/core/src/decorators/Debug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { BellatrixTest } from '@bellatrix/core/infrastructure';
import { getTestMetadata } from '@bellatrix/core/test/props';
import { ParameterlessCtor } from '@bellatrix/core/types';

export function Debug<T extends BellatrixTest>(target: T, methodName?: string): void {
const metadata = getTestMetadata(target[methodName as keyof T] as (...args: unknown[]) => (Promise<void> | void), target.constructor as ParameterlessCtor<T>);
metadata.only = true;
}
21 changes: 21 additions & 0 deletions @bellatrix/core/src/decorators/Ignore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Symbols } from '@bellatrix/core/constants';
import { BellatrixTest } from '@bellatrix/core/infrastructure';
import { getTestMetadata } from '@bellatrix/core/test/props';
import { ParameterlessCtor } from '@bellatrix/core/types';

export function Ignore<T extends BellatrixTest>(target: T, methodName: string): void;
export function Ignore<T extends BellatrixTest>(target: ParameterlessCtor<T>): void;
export function Ignore<T extends BellatrixTest>(target: T | ParameterlessCtor<T>, methodName?: string): void {
if (typeof target === 'function') {
const testClass = target.prototype;
const testMethods = Object.getOwnPropertyNames(testClass).filter(method => typeof testClass[method] === 'function' && Reflect.hasMetadata(Symbols.TEST, testClass[method]));

for (const testMethod of testMethods) {
const metadata = getTestMetadata(testClass[testMethod], testClass);
metadata.shouldSkip = true;
}
} else {
const metadata = getTestMetadata(target[methodName as keyof T] as (...args: unknown[]) => (Promise<void> | void), target.constructor as ParameterlessCtor<T>);
metadata.shouldSkip = true;
}
}
3 changes: 3 additions & 0 deletions @bellatrix/core/src/decorators/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './Category';
export * from './Debug';
export * from './Ignore';
6 changes: 3 additions & 3 deletions @bellatrix/core/src/infrastructure/PluginExecutionEngine.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TestMetadata, getCurrentTest, getSuiteMetadata, getTestMetadata } from '@bellatrix/core/test/props';
import { getCurrentTest, getSuiteMetadata, getTestMetadata } from '@bellatrix/core/test/props';
import { ServiceLocator } from '@bellatrix/core/utilities';
import { BellatrixTest, Plugin } from '.';

Expand Down Expand Up @@ -27,7 +27,7 @@ export class PluginExecutionEngine {
}

static async executeBeforeTestHook<T>(beforeTestFn: Function | undefined, testClass: typeof BellatrixTest): Promise<T> {
const testMetadata = getTestMetadata(getCurrentTest(testClass).method);
const testMetadata = getTestMetadata(getCurrentTest(testClass).method, testClass);
try {
await PluginExecutionEngine.executeAll(plugin => plugin.preBeforeTest(testMetadata));
const result = await beforeTestFn?.();
Expand All @@ -40,7 +40,7 @@ export class PluginExecutionEngine {
}

static async executeAfterTestHook<T>(afterTestFn: Function | undefined, testClass: typeof BellatrixTest): Promise<T> {
const testMetadata = getTestMetadata(getCurrentTest(testClass).method);
const testMetadata = getTestMetadata(getCurrentTest(testClass).method, testClass);
try {
await PluginExecutionEngine.executeAll(plugin => plugin.preAfterTest(testMetadata));
const result = await afterTestFn?.();
Expand Down
Loading