alchemy 0.8.1 → 0.9.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/lib/alchemy.d.ts +11 -18
- package/lib/alchemy.js +34 -39
- package/lib/apply.js +3 -1
- package/lib/cloudflare/index.d.ts +1 -0
- package/lib/cloudflare/index.js +1 -0
- package/lib/cloudflare/pipeline.js +0 -3
- package/lib/cloudflare/vite-site.d.ts +39 -0
- package/lib/cloudflare/vite-site.js +57 -0
- package/lib/cloudflare/wrangler.json.js +1 -1
- package/lib/destroy.js +14 -2
- package/lib/fs/file-system-state-store.d.ts +1 -0
- package/lib/fs/file-system-state-store.js +23 -13
- package/lib/scope.d.ts +1 -1
- package/lib/scope.js +5 -2
- package/lib/state.d.ts +2 -2
- package/lib/test/bun.d.ts +1 -6
- package/lib/test/bun.js +15 -37
- package/package.json +1 -1
- package/src/alchemy.ts +51 -45
- package/src/apply.ts +6 -2
- package/src/cloudflare/index.ts +1 -0
- package/src/cloudflare/pipeline.ts +0 -4
- package/src/cloudflare/vite-site.ts +111 -0
- package/src/cloudflare/wrangler.json.ts +1 -1
- package/src/destroy.ts +25 -8
- package/src/fs/file-system-state-store.ts +23 -14
- package/src/scope.ts +9 -5
- package/src/state.ts +3 -3
- package/src/test/bun.ts +22 -53
package/src/test/bun.ts
CHANGED
|
@@ -4,8 +4,7 @@ import { afterAll, beforeAll, it } from "bun:test";
|
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { alchemy } from "../alchemy";
|
|
6
6
|
import { R2RestStateStore } from "../cloudflare";
|
|
7
|
-
import {
|
|
8
|
-
import type { Scope } from "../scope";
|
|
7
|
+
import { Scope } from "../scope";
|
|
9
8
|
import type { StateStoreType } from "../state";
|
|
10
9
|
|
|
11
10
|
/**
|
|
@@ -26,12 +25,6 @@ alchemy.test = test;
|
|
|
26
25
|
* Options for configuring test behavior
|
|
27
26
|
*/
|
|
28
27
|
export interface TestOptions {
|
|
29
|
-
/**
|
|
30
|
-
* Whether to automatically destroy resources after test.
|
|
31
|
-
* @default true.
|
|
32
|
-
*/
|
|
33
|
-
destroy?: boolean;
|
|
34
|
-
|
|
35
28
|
/**
|
|
36
29
|
* Whether to suppress logging output.
|
|
37
30
|
* @default false.
|
|
@@ -121,7 +114,6 @@ type test = {
|
|
|
121
114
|
* ```
|
|
122
115
|
*/
|
|
123
116
|
export function test(meta: ImportMeta, defaultOptions?: TestOptions): test {
|
|
124
|
-
let isFailed = false;
|
|
125
117
|
defaultOptions = defaultOptions ?? {};
|
|
126
118
|
if (
|
|
127
119
|
defaultOptions.stateStore === undefined &&
|
|
@@ -146,37 +138,21 @@ export function test(meta: ImportMeta, defaultOptions?: TestOptions): test {
|
|
|
146
138
|
};
|
|
147
139
|
|
|
148
140
|
// Create local test scope based on filename
|
|
149
|
-
const
|
|
150
|
-
`${defaultOptions.prefix ? `${defaultOptions.prefix}-` : ""}${path.basename(meta.filename)}`,
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
);
|
|
156
|
-
test.scope = localTestScope;
|
|
141
|
+
const scope = new Scope({
|
|
142
|
+
scopeName: `${defaultOptions.prefix ? `${defaultOptions.prefix}-` : ""}${path.basename(meta.filename)}`,
|
|
143
|
+
// parent: globalTestScope,
|
|
144
|
+
stateStore: defaultOptions?.stateStore,
|
|
145
|
+
});
|
|
157
146
|
|
|
158
147
|
test.beforeAll = (fn: (scope: Scope) => Promise<void>) => {
|
|
159
|
-
return beforeAll(
|
|
160
|
-
test.scope.enter();
|
|
161
|
-
await fn(test.scope);
|
|
162
|
-
});
|
|
148
|
+
return beforeAll(() => scope.run(() => fn(scope)));
|
|
163
149
|
};
|
|
164
150
|
|
|
165
151
|
test.afterAll = (fn: (scope: Scope) => Promise<void>) => {
|
|
166
|
-
return afterAll(
|
|
167
|
-
test.scope.enter();
|
|
168
|
-
await fn(test.scope);
|
|
169
|
-
});
|
|
152
|
+
return afterAll(() => scope.run(() => fn(scope)));
|
|
170
153
|
};
|
|
171
154
|
|
|
172
|
-
|
|
173
|
-
afterAll(async () => {
|
|
174
|
-
if (defaultOptions?.destroy !== false && !isFailed) {
|
|
175
|
-
await alchemy.destroy(test.scope);
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
return test as any;
|
|
155
|
+
return test as test;
|
|
180
156
|
|
|
181
157
|
function test(
|
|
182
158
|
...args:
|
|
@@ -204,7 +180,6 @@ export function test(meta: ImportMeta, defaultOptions?: TestOptions): test {
|
|
|
204
180
|
|
|
205
181
|
// Merge options with defaults
|
|
206
182
|
const options: TestOptions = {
|
|
207
|
-
destroy: true,
|
|
208
183
|
quiet: false,
|
|
209
184
|
password: "test-password",
|
|
210
185
|
...spread(defaultOptions),
|
|
@@ -213,32 +188,26 @@ export function test(meta: ImportMeta, defaultOptions?: TestOptions): test {
|
|
|
213
188
|
|
|
214
189
|
const fn = typeof args[1] === "function" ? args[1] : args[2]!;
|
|
215
190
|
|
|
216
|
-
return
|
|
191
|
+
return it(
|
|
217
192
|
testName,
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
parent: localTestScope,
|
|
221
|
-
},
|
|
222
|
-
async (scope) => {
|
|
223
|
-
return it(
|
|
193
|
+
async () =>
|
|
194
|
+
alchemy.run(
|
|
224
195
|
testName,
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
scope
|
|
196
|
+
{
|
|
197
|
+
...options,
|
|
198
|
+
parent: scope,
|
|
199
|
+
},
|
|
200
|
+
async (scope) => {
|
|
228
201
|
try {
|
|
229
|
-
|
|
202
|
+
// Enter test scope since bun calls from different scope
|
|
203
|
+
await scope.run(() => fn(scope));
|
|
230
204
|
} catch (err) {
|
|
231
205
|
console.error(err);
|
|
232
206
|
throw err;
|
|
233
|
-
} finally {
|
|
234
|
-
if (options.destroy !== false) {
|
|
235
|
-
await destroy(scope);
|
|
236
|
-
}
|
|
237
207
|
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
}
|
|
208
|
+
}
|
|
209
|
+
),
|
|
210
|
+
timeout
|
|
242
211
|
);
|
|
243
212
|
}
|
|
244
213
|
}
|