forked from Lilly-Protocol/lily-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgh-disc-43-Lilly-Protocol-lily-sdk.ts
More file actions
46 lines (40 loc) · 1.26 KB
/
Copy pathgh-disc-43-Lilly-Protocol-lily-sdk.ts
File metadata and controls
46 lines (40 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { jest } from '@jest/globals';
import * as fs from 'fs';
import * as path from 'path';
// Mock fetch globally before importing quickstart
const originalFetch = global.fetch;
beforeAll(() => {
global.fetch = jest.fn(() =>
Promise.resolve({
ok: true,
json: () => Promise.resolve({ data: 'stubbed response' }),
} as Response)
) as jest.Mock;
});
afterAll(() => {
global.fetch = originalFetch;
});
describe('quickstart.ts flow', () => {
it('executes without error and uses fetch', async () => {
const quickstartPath = path.join(__dirname, '..', 'examples', 'quickstart.ts');
const quickstartCode = fs.readFileSync(quickstartPath, 'utf8');
// Evaluate the quickstart code in a context with required globals
const vm = await import('vm');
const sandbox = {
fetch: global.fetch,
console,
process: { env: {} },
Buffer,
setImmediate,
clearImmediate,
require: (mod: string) => {
if (mod === 'node-fetch') return global.fetch;
throw new Error(`Mocked require for ${mod} not implemented`);
},
};
vm.createContext(sandbox);
vm.runInContext(quickstartCode, sandbox);
// Assert fetch was called at least once
expect(global.fetch).toHaveBeenCalled();
});
});