@effectionx/bdd 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +171 -0
- package/esm/_dnt.shims.d.ts +2 -0
- package/esm/_dnt.shims.d.ts.map +1 -0
- package/esm/_dnt.shims.js +57 -0
- package/esm/deps/jsr.io/@std/assert/1.0.14/assertion_error.d.ts +26 -0
- package/esm/deps/jsr.io/@std/assert/1.0.14/assertion_error.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.14/assertion_error.js +30 -0
- package/esm/deps/jsr.io/@std/internal/1.0.10/assertion_state.d.ts +150 -0
- package/esm/deps/jsr.io/@std/internal/1.0.10/assertion_state.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.10/assertion_state.js +237 -0
- package/esm/deps/jsr.io/@std/testing/1.0.15/_test_suite.d.ts +78 -0
- package/esm/deps/jsr.io/@std/testing/1.0.15/_test_suite.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/testing/1.0.15/_test_suite.js +385 -0
- package/esm/deps/jsr.io/@std/testing/1.0.15/bdd.d.ts +336 -0
- package/esm/deps/jsr.io/@std/testing/1.0.15/bdd.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/testing/1.0.15/bdd.js +1057 -0
- package/esm/mod.d.ts +13 -0
- package/esm/mod.d.ts.map +1 -0
- package/esm/mod.js +47 -0
- package/esm/package.json +3 -0
- package/package.json +31 -0
- package/script/_dnt.shims.d.ts +2 -0
- package/script/_dnt.shims.d.ts.map +1 -0
- package/script/_dnt.shims.js +60 -0
- package/script/deps/jsr.io/@std/assert/1.0.14/assertion_error.d.ts +26 -0
- package/script/deps/jsr.io/@std/assert/1.0.14/assertion_error.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.14/assertion_error.js +34 -0
- package/script/deps/jsr.io/@std/internal/1.0.10/assertion_state.d.ts +150 -0
- package/script/deps/jsr.io/@std/internal/1.0.10/assertion_state.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/internal/1.0.10/assertion_state.js +275 -0
- package/script/deps/jsr.io/@std/testing/1.0.15/_test_suite.d.ts +78 -0
- package/script/deps/jsr.io/@std/testing/1.0.15/_test_suite.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/testing/1.0.15/_test_suite.js +389 -0
- package/script/deps/jsr.io/@std/testing/1.0.15/bdd.d.ts +336 -0
- package/script/deps/jsr.io/@std/testing/1.0.15/bdd.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/testing/1.0.15/bdd.js +1068 -0
- package/script/mod.d.ts +13 -0
- package/script/mod.d.ts.map +1 -0
- package/script/mod.js +52 -0
- package/script/package.json +3 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export declare const globalSanitizersState: {
|
|
2
|
+
sanitizeExit: boolean | undefined;
|
|
3
|
+
sanitizeOps: boolean | undefined;
|
|
4
|
+
sanitizeResources: boolean | undefined;
|
|
5
|
+
};
|
|
6
|
+
/** The options for creating a test suite with the describe function. */
|
|
7
|
+
export interface DescribeDefinition<T> extends Omit<Deno.TestDefinition, "fn"> {
|
|
8
|
+
/** The body of the test suite */
|
|
9
|
+
fn?: () => void | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* The `describe` function returns a `TestSuite` representing the group of tests.
|
|
12
|
+
* If `describe` is called within another `describe` calls `fn`, the suite will default to that parent `describe` calls returned `TestSuite`.
|
|
13
|
+
* If `describe` is not called within another `describe` calls `fn`, the suite will default to the `TestSuite` representing the global group of tests.
|
|
14
|
+
*/
|
|
15
|
+
suite?: TestSuite<T>;
|
|
16
|
+
/** Run some shared setup before all of the tests in the suite. */
|
|
17
|
+
beforeAll?: ((this: T) => void | Promise<void>) | ((this: T) => void | Promise<void>)[];
|
|
18
|
+
/** Run some shared teardown after all of the tests in the suite. */
|
|
19
|
+
afterAll?: ((this: T) => void | Promise<void>) | ((this: T) => void | Promise<void>)[];
|
|
20
|
+
/** Run some shared setup before each test in the suite. */
|
|
21
|
+
beforeEach?: ((this: T) => void | Promise<void>) | ((this: T) => void | Promise<void>)[];
|
|
22
|
+
/** Run some shared teardown after each test in the suite. */
|
|
23
|
+
afterEach?: ((this: T) => void | Promise<void>) | ((this: T) => void | Promise<void>)[];
|
|
24
|
+
}
|
|
25
|
+
/** The options for creating an individual test case with the it function. */
|
|
26
|
+
export interface ItDefinition<T> extends Omit<Deno.TestDefinition, "fn"> {
|
|
27
|
+
/** The body of the test case */
|
|
28
|
+
fn: (this: T, t: Deno.TestContext) => void | Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* The `describe` function returns a `TestSuite` representing the group of tests.
|
|
31
|
+
* If `it` is called within a `describe` calls `fn`, the suite will default to that parent `describe` calls returned `TestSuite`.
|
|
32
|
+
* If `it` is not called within a `describe` calls `fn`, the suite will default to the `TestSuite` representing the global group of tests.
|
|
33
|
+
*/
|
|
34
|
+
suite?: TestSuite<T>;
|
|
35
|
+
}
|
|
36
|
+
/** The names of all the different types of hooks. */
|
|
37
|
+
export type HookNames = "beforeAll" | "afterAll" | "beforeEach" | "afterEach";
|
|
38
|
+
/**
|
|
39
|
+
* A group of tests.
|
|
40
|
+
*/
|
|
41
|
+
export interface TestSuite<T> {
|
|
42
|
+
/** The symbol to use for grouping the test suite */
|
|
43
|
+
symbol: symbol;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* An internal representation of a group of tests.
|
|
47
|
+
*/
|
|
48
|
+
export declare class TestSuiteInternal<T> implements TestSuite<T> {
|
|
49
|
+
symbol: symbol;
|
|
50
|
+
protected describe: DescribeDefinition<T>;
|
|
51
|
+
protected steps: (TestSuiteInternal<T> | ItDefinition<T>)[];
|
|
52
|
+
protected hasOnlyStep: boolean;
|
|
53
|
+
constructor(describe: DescribeDefinition<T>);
|
|
54
|
+
/** Stores how many test suites are executing. */
|
|
55
|
+
static runningCount: number;
|
|
56
|
+
/** If a test has been registered yet. Block adding global hooks if a test has been registered. */
|
|
57
|
+
static started: boolean;
|
|
58
|
+
/** A map of all test suites by symbol. */
|
|
59
|
+
static suites: Map<symbol, TestSuiteInternal<any>>;
|
|
60
|
+
/** The current test suite being registered. */
|
|
61
|
+
static current: TestSuiteInternal<any> | null;
|
|
62
|
+
/** The stack of tests that are actively running. */
|
|
63
|
+
static active: symbol[];
|
|
64
|
+
/** This is used internally for testing this module. */
|
|
65
|
+
static reset(): void;
|
|
66
|
+
/** This is used internally to register tests. */
|
|
67
|
+
static registerTest(options: Deno.TestDefinition): void;
|
|
68
|
+
/** Updates all steps within top level suite to have ignore set to true if only is not set to true on step. */
|
|
69
|
+
static addingOnlyStep<T>(suite: TestSuiteInternal<T>): void;
|
|
70
|
+
/** This is used internally to add steps to a test suite. */
|
|
71
|
+
static addStep<T>(suite: TestSuiteInternal<T>, step: TestSuiteInternal<T> | ItDefinition<T>): void;
|
|
72
|
+
/** This is used internally to add hooks to a test suite. */
|
|
73
|
+
static setHook<T>(suite: TestSuiteInternal<T>, name: HookNames, fn: (this: T) => void | Promise<void>): void;
|
|
74
|
+
/** This is used internally to run all steps for a test suite. */
|
|
75
|
+
static run<T>(suite: TestSuiteInternal<T>, context: T, t: Deno.TestContext): Promise<void>;
|
|
76
|
+
static runTest<T>(t: Deno.TestContext, fn: (this: T, t: Deno.TestContext) => void | Promise<void>, context: T, activeIndex?: number): Promise<void>;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=_test_suite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_test_suite.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/testing/1.0.15/_test_suite.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,qBAAqB;kBACL,OAAO,GAAG,SAAS;iBACpB,OAAO,GAAG,SAAS;uBACb,OAAO,GAAG,SAAS;CACpD,CAAC;AAGF,wEAAwE;AACxE,MAAM,WAAW,kBAAkB,CAAC,CAAC,CAAE,SAAQ,IAAI,CAAC,IAAI,CAAC,cAAc,EA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O,CAAC,CAAC,EACd,KAAK,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAC3B,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC;IAmB9C,4DAA4D;IAC5D,MAAM,CAAC,OAAO,CAAC,CAAC,EACd,KAAK,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAC3B,IAAI,EAAE,SAAS,EACf,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAcvC,iEAAiE;WACpD,GAAG,CAAC,CAAC,EAChB,KAAK,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAC3B,OAAO,EAAE,CAAC,EACV,CAAC,EAAE,IAAI,CAAC,WAAW;WA2ER,OAAO,CAAC,CAAC,EACpB,CAAC,EAAE,IAAI,CAAC,WAAW,EACnB,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,WAAW,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EAC1D,OAAO,EAAE,CAAC,EACV,WAAW,SAAI;CAiDlB"}
|
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
2
|
+
import { getAssertionState } from "../../internal/1.0.10/assertion_state.js";
|
|
3
|
+
import { AssertionError } from "../../assert/1.0.14/assertion_error.js";
|
|
4
|
+
export const globalSanitizersState = {
|
|
5
|
+
sanitizeExit: undefined,
|
|
6
|
+
sanitizeOps: undefined,
|
|
7
|
+
sanitizeResources: undefined,
|
|
8
|
+
};
|
|
9
|
+
const assertionState = getAssertionState();
|
|
10
|
+
/**
|
|
11
|
+
* An internal representation of a group of tests.
|
|
12
|
+
*/
|
|
13
|
+
export class TestSuiteInternal {
|
|
14
|
+
constructor(describe) {
|
|
15
|
+
Object.defineProperty(this, "symbol", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true,
|
|
19
|
+
value: void 0
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(this, "describe", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true,
|
|
25
|
+
value: void 0
|
|
26
|
+
});
|
|
27
|
+
Object.defineProperty(this, "steps", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
configurable: true,
|
|
30
|
+
writable: true,
|
|
31
|
+
value: void 0
|
|
32
|
+
});
|
|
33
|
+
Object.defineProperty(this, "hasOnlyStep", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true,
|
|
37
|
+
value: void 0
|
|
38
|
+
});
|
|
39
|
+
this.describe = describe;
|
|
40
|
+
this.steps = [];
|
|
41
|
+
this.hasOnlyStep = false;
|
|
42
|
+
const { suite } = describe;
|
|
43
|
+
if (suite && !TestSuiteInternal.suites.has(suite.symbol)) {
|
|
44
|
+
throw new Error("Cannot construct Test Suite: suite does not represent a registered test suite");
|
|
45
|
+
}
|
|
46
|
+
const testSuite = suite
|
|
47
|
+
? TestSuiteInternal.suites.get(suite.symbol)
|
|
48
|
+
: TestSuiteInternal.current;
|
|
49
|
+
this.symbol = Symbol();
|
|
50
|
+
TestSuiteInternal.suites.set(this.symbol, this);
|
|
51
|
+
const { fn, ignore } = describe;
|
|
52
|
+
if (ignore) {
|
|
53
|
+
const { name, only, permissions, sanitizeExit = globalSanitizersState.sanitizeExit, sanitizeOps = globalSanitizersState.sanitizeOps, sanitizeResources = globalSanitizersState.sanitizeResources, } = describe;
|
|
54
|
+
const options = {
|
|
55
|
+
name,
|
|
56
|
+
fn: async () => { },
|
|
57
|
+
ignore: true,
|
|
58
|
+
};
|
|
59
|
+
if (only !== undefined) {
|
|
60
|
+
options.only = only;
|
|
61
|
+
}
|
|
62
|
+
if (permissions !== undefined) {
|
|
63
|
+
options.permissions = permissions;
|
|
64
|
+
}
|
|
65
|
+
if (sanitizeExit !== undefined) {
|
|
66
|
+
options.sanitizeExit = sanitizeExit;
|
|
67
|
+
}
|
|
68
|
+
if (sanitizeOps !== undefined) {
|
|
69
|
+
options.sanitizeOps = sanitizeOps;
|
|
70
|
+
}
|
|
71
|
+
if (sanitizeResources !== undefined) {
|
|
72
|
+
options.sanitizeResources = sanitizeResources;
|
|
73
|
+
}
|
|
74
|
+
TestSuiteInternal.registerTest(options);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (fn) {
|
|
78
|
+
const temp = TestSuiteInternal.current;
|
|
79
|
+
TestSuiteInternal.current = this;
|
|
80
|
+
try {
|
|
81
|
+
// deno-lint-ignore no-explicit-any
|
|
82
|
+
const value = fn();
|
|
83
|
+
if (value instanceof Promise) {
|
|
84
|
+
throw new Error('Returning a Promise from "describe" is not supported: tests must be defined synchronously');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
TestSuiteInternal.current = temp;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (testSuite) {
|
|
92
|
+
TestSuiteInternal.addStep(testSuite, this);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
const { name, ignore, permissions, sanitizeExit = globalSanitizersState.sanitizeExit, sanitizeOps = globalSanitizersState.sanitizeOps, sanitizeResources = globalSanitizersState.sanitizeResources, } = describe;
|
|
96
|
+
let { only } = describe;
|
|
97
|
+
if (!ignore && this.hasOnlyStep) {
|
|
98
|
+
only = true;
|
|
99
|
+
}
|
|
100
|
+
const options = {
|
|
101
|
+
name,
|
|
102
|
+
fn: async (t) => {
|
|
103
|
+
TestSuiteInternal.runningCount++;
|
|
104
|
+
try {
|
|
105
|
+
const context = {};
|
|
106
|
+
const { beforeAll } = this.describe;
|
|
107
|
+
if (typeof beforeAll === "function") {
|
|
108
|
+
await beforeAll.call(context);
|
|
109
|
+
}
|
|
110
|
+
else if (beforeAll) {
|
|
111
|
+
for (const hook of beforeAll) {
|
|
112
|
+
await hook.call(context);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
try {
|
|
116
|
+
TestSuiteInternal.active.push(this.symbol);
|
|
117
|
+
await TestSuiteInternal.run(this, context, t);
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
TestSuiteInternal.active.pop();
|
|
121
|
+
const { afterAll } = this.describe;
|
|
122
|
+
if (typeof afterAll === "function") {
|
|
123
|
+
await afterAll.call(context);
|
|
124
|
+
}
|
|
125
|
+
else if (afterAll) {
|
|
126
|
+
for (const hook of afterAll) {
|
|
127
|
+
await hook.call(context);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
TestSuiteInternal.runningCount--;
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
if (ignore !== undefined) {
|
|
138
|
+
options.ignore = ignore;
|
|
139
|
+
}
|
|
140
|
+
if (only !== undefined) {
|
|
141
|
+
options.only = only;
|
|
142
|
+
}
|
|
143
|
+
if (permissions !== undefined) {
|
|
144
|
+
options.permissions = permissions;
|
|
145
|
+
}
|
|
146
|
+
if (sanitizeExit !== undefined) {
|
|
147
|
+
options.sanitizeExit = sanitizeExit;
|
|
148
|
+
}
|
|
149
|
+
if (sanitizeOps !== undefined) {
|
|
150
|
+
options.sanitizeOps = sanitizeOps;
|
|
151
|
+
}
|
|
152
|
+
if (sanitizeResources !== undefined) {
|
|
153
|
+
options.sanitizeResources = sanitizeResources;
|
|
154
|
+
}
|
|
155
|
+
TestSuiteInternal.registerTest(options);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/** This is used internally for testing this module. */
|
|
159
|
+
static reset() {
|
|
160
|
+
TestSuiteInternal.runningCount = 0;
|
|
161
|
+
TestSuiteInternal.started = false;
|
|
162
|
+
TestSuiteInternal.current = null;
|
|
163
|
+
TestSuiteInternal.active = [];
|
|
164
|
+
}
|
|
165
|
+
/** This is used internally to register tests. */
|
|
166
|
+
static registerTest(options) {
|
|
167
|
+
options = { ...options };
|
|
168
|
+
if (options.only === undefined) {
|
|
169
|
+
delete options.only;
|
|
170
|
+
}
|
|
171
|
+
if (options.permissions === undefined) {
|
|
172
|
+
delete options.permissions;
|
|
173
|
+
}
|
|
174
|
+
if (options.ignore === undefined) {
|
|
175
|
+
delete options.ignore;
|
|
176
|
+
}
|
|
177
|
+
if (options.sanitizeExit === undefined) {
|
|
178
|
+
delete options.sanitizeExit;
|
|
179
|
+
}
|
|
180
|
+
if (options.sanitizeOps === undefined) {
|
|
181
|
+
delete options.sanitizeOps;
|
|
182
|
+
}
|
|
183
|
+
if (options.sanitizeResources === undefined) {
|
|
184
|
+
delete options.sanitizeResources;
|
|
185
|
+
}
|
|
186
|
+
Deno.test(options);
|
|
187
|
+
}
|
|
188
|
+
/** Updates all steps within top level suite to have ignore set to true if only is not set to true on step. */
|
|
189
|
+
static addingOnlyStep(suite) {
|
|
190
|
+
if (!suite.hasOnlyStep) {
|
|
191
|
+
for (let i = 0; i < suite.steps.length; i++) {
|
|
192
|
+
const step = suite.steps[i];
|
|
193
|
+
if (!(step instanceof TestSuiteInternal) && !step.only) {
|
|
194
|
+
suite.steps.splice(i--, 1);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
suite.hasOnlyStep = true;
|
|
198
|
+
}
|
|
199
|
+
const parentSuite = suite.describe.suite;
|
|
200
|
+
const parentTestSuite = parentSuite &&
|
|
201
|
+
TestSuiteInternal.suites.get(parentSuite.symbol);
|
|
202
|
+
if (parentTestSuite) {
|
|
203
|
+
TestSuiteInternal.addingOnlyStep(parentTestSuite);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/** This is used internally to add steps to a test suite. */
|
|
207
|
+
static addStep(suite, step) {
|
|
208
|
+
if (!suite.hasOnlyStep) {
|
|
209
|
+
if (step instanceof TestSuiteInternal) {
|
|
210
|
+
if (step.hasOnlyStep || step.describe.only) {
|
|
211
|
+
TestSuiteInternal.addingOnlyStep(suite);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
if (step.only)
|
|
216
|
+
TestSuiteInternal.addingOnlyStep(suite);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (!(suite.hasOnlyStep && !(step instanceof TestSuiteInternal) && !step.only)) {
|
|
220
|
+
suite.steps.push(step);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/** This is used internally to add hooks to a test suite. */
|
|
224
|
+
static setHook(suite, name, fn) {
|
|
225
|
+
if (suite.describe[name]) {
|
|
226
|
+
if (typeof suite.describe[name] === "function") {
|
|
227
|
+
suite.describe[name] = [
|
|
228
|
+
suite.describe[name],
|
|
229
|
+
];
|
|
230
|
+
}
|
|
231
|
+
suite.describe[name].push(fn);
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
suite.describe[name] = fn;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/** This is used internally to run all steps for a test suite. */
|
|
238
|
+
static async run(suite, context, t) {
|
|
239
|
+
const hasOnly = suite.hasOnlyStep || suite.describe.only || false;
|
|
240
|
+
for (const step of suite.steps) {
|
|
241
|
+
if (hasOnly && step instanceof TestSuiteInternal &&
|
|
242
|
+
!(step.hasOnlyStep || step.describe.only || false)) {
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
const { name, fn, ignore, permissions, sanitizeExit = globalSanitizersState.sanitizeExit, sanitizeOps = globalSanitizersState.sanitizeOps, sanitizeResources = globalSanitizersState.sanitizeResources, } = step instanceof TestSuiteInternal ? step.describe : step;
|
|
246
|
+
const options = {
|
|
247
|
+
name,
|
|
248
|
+
fn: async (t) => {
|
|
249
|
+
if (permissions) {
|
|
250
|
+
throw new Error(
|
|
251
|
+
// deno-lint-ignore deno-style-guide/error-message
|
|
252
|
+
"permissions option not available for nested tests");
|
|
253
|
+
}
|
|
254
|
+
context = { ...context };
|
|
255
|
+
if (step instanceof TestSuiteInternal) {
|
|
256
|
+
const { beforeAll } = step.describe;
|
|
257
|
+
if (typeof beforeAll === "function") {
|
|
258
|
+
await beforeAll.call(context);
|
|
259
|
+
}
|
|
260
|
+
else if (beforeAll) {
|
|
261
|
+
for (const hook of beforeAll) {
|
|
262
|
+
await hook.call(context);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
try {
|
|
266
|
+
TestSuiteInternal.active.push(step.symbol);
|
|
267
|
+
await TestSuiteInternal.run(step, context, t);
|
|
268
|
+
}
|
|
269
|
+
finally {
|
|
270
|
+
TestSuiteInternal.active.pop();
|
|
271
|
+
const { afterAll } = step.describe;
|
|
272
|
+
if (typeof afterAll === "function") {
|
|
273
|
+
await afterAll.call(context);
|
|
274
|
+
}
|
|
275
|
+
else if (afterAll) {
|
|
276
|
+
for (const hook of afterAll) {
|
|
277
|
+
await hook.call(context);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
await TestSuiteInternal.runTest(t, fn, context);
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
};
|
|
287
|
+
if (ignore !== undefined) {
|
|
288
|
+
options.ignore = ignore;
|
|
289
|
+
}
|
|
290
|
+
if (sanitizeExit !== undefined) {
|
|
291
|
+
options.sanitizeExit = sanitizeExit;
|
|
292
|
+
}
|
|
293
|
+
if (sanitizeOps !== undefined) {
|
|
294
|
+
options.sanitizeOps = sanitizeOps;
|
|
295
|
+
}
|
|
296
|
+
if (sanitizeResources !== undefined) {
|
|
297
|
+
options.sanitizeResources = sanitizeResources;
|
|
298
|
+
}
|
|
299
|
+
await t.step(options);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
static async runTest(t, fn, context, activeIndex = 0) {
|
|
303
|
+
const suite = TestSuiteInternal.active[activeIndex];
|
|
304
|
+
const testSuite = suite && TestSuiteInternal.suites.get(suite);
|
|
305
|
+
if (testSuite) {
|
|
306
|
+
if (activeIndex === 0)
|
|
307
|
+
context = { ...context };
|
|
308
|
+
const { beforeEach } = testSuite.describe;
|
|
309
|
+
if (typeof beforeEach === "function") {
|
|
310
|
+
await beforeEach.call(context);
|
|
311
|
+
}
|
|
312
|
+
else if (beforeEach) {
|
|
313
|
+
for (const hook of beforeEach) {
|
|
314
|
+
await hook.call(context);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
try {
|
|
318
|
+
await TestSuiteInternal.runTest(t, fn, context, activeIndex + 1);
|
|
319
|
+
}
|
|
320
|
+
finally {
|
|
321
|
+
const { afterEach } = testSuite.describe;
|
|
322
|
+
if (typeof afterEach === "function") {
|
|
323
|
+
await afterEach.call(context);
|
|
324
|
+
}
|
|
325
|
+
else if (afterEach) {
|
|
326
|
+
for (const hook of afterEach) {
|
|
327
|
+
await hook.call(context);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
await fn.call(context, t);
|
|
334
|
+
}
|
|
335
|
+
try {
|
|
336
|
+
if (assertionState.checkAssertionErrorState()) {
|
|
337
|
+
throw new AssertionError("Expected at least one assertion to be called but received none");
|
|
338
|
+
}
|
|
339
|
+
if (assertionState.checkAssertionCountSatisfied()) {
|
|
340
|
+
throw new AssertionError(`Expected exactly ${assertionState.assertionCount} ${assertionState.assertionCount === 1 ? "assertion" : "assertions"} to be called, ` +
|
|
341
|
+
`but received ${assertionState.assertionTriggeredCount}`);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
finally {
|
|
345
|
+
assertionState.resetAssertionState();
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
/** Stores how many test suites are executing. */
|
|
350
|
+
Object.defineProperty(TestSuiteInternal, "runningCount", {
|
|
351
|
+
enumerable: true,
|
|
352
|
+
configurable: true,
|
|
353
|
+
writable: true,
|
|
354
|
+
value: 0
|
|
355
|
+
});
|
|
356
|
+
/** If a test has been registered yet. Block adding global hooks if a test has been registered. */
|
|
357
|
+
Object.defineProperty(TestSuiteInternal, "started", {
|
|
358
|
+
enumerable: true,
|
|
359
|
+
configurable: true,
|
|
360
|
+
writable: true,
|
|
361
|
+
value: false
|
|
362
|
+
});
|
|
363
|
+
/** A map of all test suites by symbol. */
|
|
364
|
+
// deno-lint-ignore no-explicit-any
|
|
365
|
+
Object.defineProperty(TestSuiteInternal, "suites", {
|
|
366
|
+
enumerable: true,
|
|
367
|
+
configurable: true,
|
|
368
|
+
writable: true,
|
|
369
|
+
value: new Map()
|
|
370
|
+
});
|
|
371
|
+
/** The current test suite being registered. */
|
|
372
|
+
// deno-lint-ignore no-explicit-any
|
|
373
|
+
Object.defineProperty(TestSuiteInternal, "current", {
|
|
374
|
+
enumerable: true,
|
|
375
|
+
configurable: true,
|
|
376
|
+
writable: true,
|
|
377
|
+
value: null
|
|
378
|
+
});
|
|
379
|
+
/** The stack of tests that are actively running. */
|
|
380
|
+
Object.defineProperty(TestSuiteInternal, "active", {
|
|
381
|
+
enumerable: true,
|
|
382
|
+
configurable: true,
|
|
383
|
+
writable: true,
|
|
384
|
+
value: []
|
|
385
|
+
});
|