(t, bundle, { inject = {}, options = {} } = {})
| 66 | * @param {object} args |
| 67 | */ |
| 68 | const 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 | |
| 92 | const evaluateBundle = async (bundle) => { |
| 93 | const { module } = await testBundle(null, bundle); |
no test coverage detected