MCPcopy Index your code
hub / github.com/rollup/plugins / testBundle

Function testBundle

util/test.js:68–90  ·  view source on GitHub ↗
(t, bundle, { inject = {}, options = {} } = {})

Source from the content-addressed store, hash-verified

66 * @param {object} args
67 */
68const testBundle = async (t, bundle, { inject = {}, options = {} } = {}) => {
69 const { output } = await bundle.generate({ format: 'cjs', exports: 'auto', ...options });
70 const [{ code }] = output;
71 const module = { exports: {} };
72 // as of 1/2/2020 Github Actions + Windows has changed in a way that we must now escape backslashes
73 const cwd = process.cwd().replace(/\\/g, '\\\\');
74 const params = ['module', 'exports', 'require', 't', ...Object.keys(inject)].concat(
75 `process.chdir('${cwd}'); let result;\n\n${code}\n\nreturn result;`
76 );
77
78 // eslint-disable-next-line no-new-func
79 const func = new Function(...params);
80 let error;
81 let result;
82
83 try {
84 result = func(...[module, module.exports, require, t, ...Object.values(inject)]);
85 } catch (e) {
86 error = e;
87 }
88
89 return { code, error, module, result };
90};
91
92const evaluateBundle = async (bundle) => {
93 const { module } = await testBundle(null, bundle);

Callers 1

evaluateBundleFunction · 0.70

Calls 2

keysMethod · 0.80
valuesMethod · 0.80

Tested by

no test coverage detected