Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants