@@ -5,15 +5,38 @@ import {existsSync, writeFileSync, mkdirSync, rmSync} from 'fs';
55import { tmpdir } from 'os' ;
66import * as path from 'path' ;
77import { join } from 'path' ;
8- import { VMScript } from 'vm2' ;
8+ import { NodeVM , VMScript } from 'vm2' ;
99import { NodeConfig } from '../configure/NodeConfig' ;
1010import { IndexerSandbox , TestSandbox } from './sandbox' ;
1111
1212describe ( 'sandbox for subql-node' , ( ) => {
1313 let vm : IndexerSandbox ;
1414
1515 afterEach ( ( ) => {
16- vm . removeAllListeners ( ) ;
16+ vm ?. removeAllListeners ( ) ;
17+ } ) ;
18+
19+ // This was caused by vm2@3.10.0 changes that were breaking in a minor release.
20+ it ( 'Can use older libraries that use prototypes to set properties' , ( ) => {
21+ const script = `
22+ const util = require('util');
23+ const EventEmitter = require('events');
24+
25+ function MyStream() {
26+ console.log("This is sha1");
27+ }
28+
29+ util.inherits(MyStream, EventEmitter);
30+ ` ;
31+
32+ const vmScript = new VMScript ( script ) ;
33+ const vm = new NodeVM ( {
34+ console : 'inherit' ,
35+ require : {
36+ builtin : [ 'util' , 'events' ] ,
37+ } ,
38+ } ) ;
39+ expect ( ( ) => vm . run ( vmScript ) ) . not . toThrow ( ) ;
1740 } ) ;
1841
1942 it ( 'wait until promise resolved' , async ( ) => {
@@ -232,7 +255,7 @@ describe('Sandbox Environment Variable Support', () => {
232255 apiKey: process.env.API_KEY,
233256 hasProcess: typeof process !== 'undefined'
234257 };
235-
258+
236259 global.subqlTests = [result];
237260 ` ;
238261 const testPath = join ( srcDir , 'test.js' ) ;
@@ -269,7 +292,7 @@ describe('Sandbox Environment Variable Support', () => {
269292 hasProcess: typeof process !== 'undefined',
270293 processType: typeof process
271294 };
272-
295+
273296 global.subqlTests = [result];
274297 ` ;
275298 const testPath = join ( srcDir , 'test.js' ) ;
0 commit comments