Skip to content
This repository has been archived by the owner on Dec 8, 2024. It is now read-only.

Function to string without istanbul in runtime #935

Open
andrew-aladev opened this issue Jun 29, 2020 · 1 comment
Open

Function to string without istanbul in runtime #935

andrew-aladev opened this issue Jun 29, 2020 · 1 comment

Comments

@andrew-aladev
Copy link

andrew-aladev commented Jun 29, 2020

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.

@andrew-aladev andrew-aladev changed the title Function to string without istanbul runtime switch Function to string without istanbul in runtime Jun 29, 2020
@fatemeh-fo
Copy link

let useIstanbul = true; // Set this flag to enable or disable Istanbul

export function inlineWorker() {
// Your inline worker code here
if (useIstanbul) {
// Instrumentation for Istanbul coverage
cov_${id}++;
}
}

function inlineWorkerCopy() {
// Your copy of the inline worker code without Istanbul instrumentation
}

const data = (${useIstanbul ? inlineWorker : inlineWorkerCopy}) ...;
const worker = new Worker(URL.createObjectURL(new Blob([data])));

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants