Function to string without istanbul in runtime
Author: andrew-aladevCreated Jun 29, 2020Updated Jun 30, 2023
Hello, we are working with web workers:
function inlineWorker () { ... }
const data = `(${inlineWorker}) ...`
const worker = new Worker(URL.createObjectURL(new Blob(data, ....)))Istanbul is poisoning inlineWorker with cov_${id}++; and worker fails. So we have to add istanbul ignore But it means that inlineWorker will be uncovered. So we are using workaround: function copy.
// can be covered outside worker
export function inlineWorker () { ... }
// istanbul ignore next
function inlineWorkerCopy () { ... }
const data = `(${inlineWorkerCopy}) ...`
const worker = new Worker(URL.createObjectURL(new Blob(data, ....)))This workaround is ugly but works fine.
We can see here that istanbul ignore comments are not enough for everyday usage. Please add switch to disable istanbul in runtime. It may be inlineWorker.toString({ istanbul: false }) or inlineWorker_without_istanbul.toString(), etc. Thank you.
#310 may be related.
Source: gotwarlost/istanbul