|
1 | 1 | const { isNonLegacySandbox } = require('./non-legacy-codemarkers');
|
2 | 2 | const _ = require('lodash'),
|
3 |
| - legacy = require('./postman-legacy-interface'), |
4 |
| - |
5 |
| - DEPRECATED_LIBS = { |
6 |
| - atob: 'global "atob" function', |
7 |
| - btoa: 'global "btoa" function', |
8 |
| - 'crypto-js': 'global "crypto" object', |
9 |
| - tv4: '"ajv" library', |
10 |
| - backbone: null |
11 |
| - }; |
| 3 | + legacy = require('./postman-legacy-interface'); |
12 | 4 |
|
13 | 5 | module.exports = function (scope, code, execution, console, timers, pmapi, onAssertion, options) {
|
14 | 6 | // if there is no code, then no point bubbling anything up
|
@@ -52,21 +44,36 @@ module.exports = function (scope, code, execution, console, timers, pmapi, onAss
|
52 | 44 | setImmediate: timers.setImmediate,
|
53 | 45 | clearTimeout: timers.clearTimeout,
|
54 | 46 | clearInterval: timers.clearInterval,
|
55 |
| - clearImmediate: timers.clearImmediate, |
| 47 | + clearImmediate: timers.clearImmediate |
| 48 | + }); |
56 | 49 |
|
57 |
| - require: (...args) => { |
58 |
| - const key = args?.[0], |
| 50 | + const wrappedCode = ` |
| 51 | + ;((originalRequire) => { |
| 52 | + require = (...args) => { |
| 53 | + const key = args?.[0], |
| 54 | + DEPRECATED_LIBS = { |
| 55 | + atob: 'global "atob" function', |
| 56 | + btoa: 'global "btoa" function', |
| 57 | + 'crypto-js': 'global "crypto" object', |
| 58 | + tv4: '"ajv" library', |
| 59 | + backbone: null |
| 60 | + }, |
59 | 61 | alt = DEPRECATED_LIBS[key];
|
60 | 62 |
|
61 |
| - if (alt !== undefined) { |
62 |
| - console.warn(`Using "${key}" library is deprecated.${alt !== null ? ` Use ${alt} instead.` : ''}`); |
63 |
| - } |
| 63 | + if (alt !== undefined) { |
| 64 | + console.warn( |
| 65 | + \`Using "\${key}" library is deprecated.\${alt !== null ? \` Use \${alt} instead.\` : ''}\` |
| 66 | + ); |
| 67 | + } |
64 | 68 |
|
65 |
| - return require(...args); |
66 |
| - } |
67 |
| - }); |
68 | 69 |
|
69 |
| - scope.exec(code, { async: true }, function (err) { |
| 70 | + return originalRequire(...args); |
| 71 | + } |
| 72 | + })(require); |
| 73 | + ${code} |
| 74 | + `; |
| 75 | + |
| 76 | + scope.exec(wrappedCode, { async: true }, function (err) { |
70 | 77 | // we check if the execution went async by determining the timer queue length at this time
|
71 | 78 | execution.return.async = (timers.queueLength() > 0);
|
72 | 79 |
|
|
0 commit comments