Skip to content

Fix jest coverage

Chad Woolley requested to merge caw-fix-jest-coverage into master

What does this MR do and why?

Fix jest coverage

Problem

I am trying to run a code coverage report using jest --coverage for a subset of files and it is failing.

When I run without coverage, it succeeds: yarn jest ee/spec/frontend/remote_development

But when I add the coverage argument it fails: yarn jest --coverage ee/spec/frontend/remote_development

The failures are all related to imports, with errors like this:

    SyntaxError: Cannot use import statement outside a module

      1 | import { GlDisclosureDropdownItem } from '@gitlab/ui';
    > 2 | import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
        | ^

Fix

I fixed this by following this stackoverflow answer.

In babel.config.js, in the const plugins, I added '@babel/plugin-transform-modules-commonjs',, which fixed the failures.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Before After
Jest failures No Jest Failures

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

See Problem section above for steps to reproduce.

Edited by Chad Woolley

Merge request reports