jest icon indicating copy to clipboard operation
jest copied to clipboard

/* istanbul ignore next */ not working

Open rikisamurai opened this issue 2 years ago • 3 comments

I have added /* istanbul ignore next */ , but it doesn't work. here is my project: https://github.com/rikisamurai/swc-jest-issue. You can reproduce the issue by running the command pnpm test version:

    "@swc/cli": "^0.1.62",
    "@swc/core": "^1.3.68",
    "@swc/jest": "^0.2.26",
    "jest": "^29.5.0",

swc/jest doesn't ignore export const countAtom = atom(0);

source code

import React from 'react';
import { atom, useAtom } from 'jotai';

/* istanbul ignore next */
export const countAtom = atom(0);

export function Counter() {
    const [count, setCount] = useAtom(countAtom);

    return (
        <h1>
            <p>{count}</p>
            <button onClick={() => setCount(c => c + 1)}>one up</button>
        </h1>
    );
}

jest config:

const swcConfig: SWCConfig = {
  sourceMaps: true,
  jsc: {
    preserveAllComments: true,
  },
};
const config: JestConfig = {
    testEnvironment: 'jsdom',
    transform: {
        '^.+\\.(t|j)sx?$': ['@swc/jest', swcConfig as Record<string, unknown>],
    },
    rootDir: './',
    collectCoverage: true,
    coverageReporters: ['clover', 'json', 'lcov', 'text'],
    setupFilesAfterEnv: ['<rootDir>src/setupTests.ts'],
};

rikisamurai avatar Jul 16 '23 13:07 rikisamurai

But if i switch to ts-jest, it works well

const config: JestConfig = {
    // ...
    transform: {
        '^.+\\.(ts|tsx)?$': 'ts-jest',
        '^.+\\.(js|jsx)$': 'babel-jest',
        // '^.+\\.(t|j)sx?$': ['@swc/jest', swcConfig as Record<string, unknown>],
    },
    // ...
};

rikisamurai avatar Jul 17 '23 01:07 rikisamurai

I've also noticed this issue, it seems to affect export statements that aren't imported elsewhere in our codebase. Also seems to be a similar issue as #119.

Obviously in some cases a solution is to remove the export, but ideally we'd be able to ignore it.

Here's a screenshot of an example from the lcov output:

image

Even moving the comment to a different spot doesn't resolve it: image

The only way I'm able to resolve it is by removing the export: image

Or by /* istanbul ignore file */ but that's not ideal.

Happy to try and reproduce with a repo if needed

giancarlo88 avatar Aug 31 '23 10:08 giancarlo88

I'm the author of #119 and I guess export may be the reason it is not ignored. We are using nextjs so components have to be default exported to be picked up

k2xl avatar Dec 30 '23 14:12 k2xl