Skip to content
Merged
Changes from all commits
Commits
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
58 changes: 52 additions & 6 deletions src/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,55 @@ import type {
TestplaneGlobals,
} from "./types/globals";

export const it: GlobalItType = (globalThis as unknown as TestplaneGlobals).it;
export const describe: GlobalDescribeType = (globalThis as unknown as TestplaneGlobals).describe;
export const beforeEach: GlobalBeforeEachType = (globalThis as unknown as TestplaneGlobals).beforeEach;
export const afterEach: GlobalAfterEachType = (globalThis as unknown as TestplaneGlobals).afterEach;
export const testplane: GlobalTestplaneType = (globalThis as unknown as TestplaneGlobals).testplane;
export const hermione: GlobalHermioneType = (globalThis as unknown as TestplaneGlobals).hermione;
const typedGlobals = globalThis as unknown as TestplaneGlobals;

function itFunc(this: unknown, ...args: Parameters<GlobalItType>): ReturnType<GlobalItType> {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using module getters is not an option because its not supported in esm

return typedGlobals.it.apply(this, args);
}

itFunc.only = function (this: unknown, ...args: Parameters<GlobalItType["only"]>): ReturnType<GlobalItType["only"]> {
return typedGlobals.it.only.apply(this, args);
};

itFunc.skip = function (this: unknown, ...args: Parameters<GlobalItType["skip"]>): ReturnType<GlobalItType["skip"]> {
return typedGlobals.it.skip.apply(this, args);
};

function describeFunc(this: unknown, ...args: Parameters<GlobalDescribeType>): ReturnType<GlobalDescribeType> {
return typedGlobals.describe.apply(this, args);
}

describeFunc.only = function (
this: unknown,
...args: Parameters<GlobalDescribeType["only"]>
): ReturnType<GlobalDescribeType["only"]> {
return typedGlobals.describe.only.apply(this, args);
};

describeFunc.skip = function (
this: unknown,
...args: Parameters<GlobalDescribeType["skip"]>
): ReturnType<GlobalDescribeType["skip"]> {
return typedGlobals.describe.skip.apply(this, args);
};

function beforeEachFunc(this: unknown, ...args: Parameters<GlobalBeforeEachType>): ReturnType<GlobalBeforeEachType> {
return typedGlobals.beforeEach.apply(this, args);
}

function afterEachFunc(this: unknown, ...args: Parameters<GlobalAfterEachType>): ReturnType<GlobalAfterEachType> {
return typedGlobals.afterEach.apply(this, args);
}

const testplaneProxy = new Proxy(typedGlobals.testplane, {
get(_, prop: keyof GlobalTestplaneType): GlobalTestplaneType[keyof GlobalTestplaneType] {
return typedGlobals.testplane[prop];
},
});

export const it = itFunc as GlobalItType;
export const describe = describeFunc as GlobalDescribeType;
export const beforeEach = beforeEachFunc as GlobalBeforeEachType;
export const afterEach = afterEachFunc as GlobalAfterEachType;
export const testplane = testplaneProxy as GlobalTestplaneType;
export const hermione = testplaneProxy as GlobalHermioneType;
Loading