Skip to content

Commit

Permalink
Add fetch to default global
Browse files Browse the repository at this point in the history
PR-URL: #116
  • Loading branch information
tshemsedinov committed Oct 24, 2023
1 parent 02efc2d commit c530668
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions metavm.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const DEFAULT = {
CompressionStream,
DecompressionStream,
CountQueuingStrategy,
fetch,
};

const NODE = { global, console, process };
Expand Down
10 changes: 10 additions & 0 deletions test/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ test('Create common context', async () => {
assert.strictEqual(context.clearTimeout, clearTimeout);
assert.strictEqual(context.clearImmediate, clearImmediate);
assert.strictEqual(context.clearInterval, clearInterval);
assert.strictEqual(context.fetch, fetch);
});

test('Create nodejs context', async () => {
Expand Down Expand Up @@ -445,3 +446,12 @@ test('Erevent eval for Metarhia modules', async () => {
assert.strictEqual(error.constructor.name, 'EvalError');
}
});

test('Check native fetch', async () => {
const src = `fetch`;
const context = metavm.createContext(metavm.COMMON_CONTEXT);
const ms = metavm.createScript('Example', src, { context });
const proto = Object.getPrototypeOf(ms.exports);
assert.ok(proto);
assert.strictEqual(proto.constructor.name, 'AsyncFunction');
});

0 comments on commit c530668

Please sign in to comment.