Skip to content

Commit 2b0200a

Browse files
authored
fix: context in pm.require (#1083)
1 parent 7433d6a commit 2b0200a

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/sandbox/pm-require.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const { LEGACY_GLOBS } = require('./postman-legacy-interface'),
22

33
MODULE_KEY = '__module_obj', // why not use `module`?
44
MODULE_WRAPPER = [
5-
'(function (exports, module) {\n',
5+
'((exports, module) => {\n',
66
`\n})(${MODULE_KEY}.exports, ${MODULE_KEY});`
77
];
88

test/unit/sandbox-libraries/pm-require.test.js

+22
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const { LEGACY_GLOBS } = require('../../../lib/sandbox/postman-legacy-interface');
2+
13
describe('sandbox library - pm.require api', function () {
24
this.timeout(1000 * 60);
35
var Sandbox = require('../../../'),
@@ -573,4 +575,24 @@ describe('sandbox library - pm.require api', function () {
573575
done();
574576
});
575577
});
578+
579+
it('should have access to complete context (expect legacy globals)', function (done) {
580+
context.execute(`
581+
const assert = require('assert');
582+
const test = pm.require('test');
583+
584+
outsideContext = Object.getOwnPropertyNames(this);
585+
586+
const diff = outsideContext.filter(x => !insideContext.includes(x));
587+
assert.ok(diff.every((key) => '${LEGACY_GLOBS.toString()}'.split(',').includes(key) ));
588+
589+
`, {
590+
context: sampleContextData,
591+
resolvedPackages: {
592+
test: {
593+
data: 'insideContext = Object.getOwnPropertyNames(this);'
594+
}
595+
}
596+
}, done);
597+
});
576598
});

0 commit comments

Comments
 (0)