Skip to content

Commit fb8ee4a

Browse files
committed
Switch to metavm for are loading configs
1 parent dd31d8c commit fb8ee4a

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

test/utils.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
'use strict';
22

3-
const fs = require('node:fs').promises;
4-
const vm = require('node:vm');
53
const http = require('node:http');
4+
const metavm = require('metavm');
65

7-
const RUN_OPTIONS = { timeout: 5000, displayErrors: false };
86
const INTERVAL = 500;
97

10-
const load = async (filePath, sandbox) => {
11-
// TODO Use metavm
12-
const src = await fs.readFile(filePath, 'utf8');
13-
const code = `'use strict';\n${src}`;
14-
const script = new vm.Script(code);
15-
const context = vm.createContext(Object.freeze({ ...sandbox }));
16-
const exports = script.runInContext(context, RUN_OPTIONS);
8+
const load = async (filePath) => {
9+
const { exports } = await metavm.readScript(filePath);
1710
return exports;
1811
};
1912

@@ -79,8 +72,7 @@ const apiReady = async ({ url, timeout }) => {
7972
};
8073

8174
const loadConfig = async (configName) => {
82-
const sandbox = { Map: class PseudoMap {} };
83-
return load(`./application/config/${configName}.js`, sandbox);
75+
return load(`./application/config/${configName}.js`);
8476
};
8577

8678
const getUrl = async () => {

0 commit comments

Comments
 (0)