@rstest/core
Version:
The Rsbuild-based test tool.
39 lines (38 loc) • 1.72 kB
JavaScript
import 'module';
/*#__PURE__*/ import.meta.url;
import * as __rspack_external__rsbuild_core_1b356efc from "@rsbuild/core";
const check = (name)=>{
if (!globalThis.RSTEST_API?.[name]) throw new Error(`Rstest API '${name}' is not registered yet, please make sure you are running in a rstest environment.`);
};
const wrapRstestAPI = (name)=>{
const fn = (...args)=>{
check(name);
return globalThis.RSTEST_API[name].call(globalThis.RSTEST_API[name], ...args);
};
return new Proxy(fn, {
get (_target, key, receiver) {
if (!globalThis.RSTEST_API?.[name]) return Reflect.get(fn, key, receiver);
return Reflect.get(globalThis.RSTEST_API[name], key, receiver);
}
});
};
const wrapRstestUtilitiesAPI = (name)=>new Proxy({}, {
get (_target, key, receiver) {
check(name);
return Reflect.get(globalThis.RSTEST_API?.[name] || {}, key, receiver);
}
});
const expect = wrapRstestAPI('expect');
const assert = wrapRstestAPI('assert');
const it = wrapRstestAPI('it');
const test = wrapRstestAPI('test');
const describe = wrapRstestAPI('describe');
const beforeAll = wrapRstestAPI('beforeAll');
const afterAll = wrapRstestAPI('afterAll');
const beforeEach = wrapRstestAPI('beforeEach');
const afterEach = wrapRstestAPI('afterEach');
const rstest = wrapRstestUtilitiesAPI('rstest');
const rs = wrapRstestUtilitiesAPI('rs');
const onTestFinished = wrapRstestAPI('onTestFinished');
const onTestFailed = wrapRstestAPI('onTestFailed');
export { __rspack_external__rsbuild_core_1b356efc as rsbuild, afterAll, afterEach, assert, beforeAll, beforeEach, describe, expect, it, onTestFailed, onTestFinished, rs, rstest, test };