2023-01-17

How to bypass test coverage for external/dependency vue components?

We have two vue3 projects. Project 1 has some components that use components from Project 2 as imported dependencies.

In Project 1, MyComponent.vue:

<template>
  <Project2Modal> Some html here </Project2Modal>
</template>

<script>
import { defineComponent } from 'vue';

import Project2Modal from 'project2/components/Project2Modal.vue';

export default defineComponent({
  components: {
    Project2Modal,
  },
  props: {
    title: {
      type: String,
      required: true,
    },
    ...
});
</script>

The problem we are having is that, when we try to test (using jest and vue-test-utils) those components from Project 1, the test coverage also includes coverage for the Project 2 dependency components (as demonstrated by the "uncovered" lines not being part of the MyComponent.vue file at all). Which makes the overall Project 1 test coverage way lower than it should be (it becomes 100% when we remove the project2Modal component from the template).

Project 1 test --coverage

------------------------------------------|---------|----------|---------|---------|-------------------
File                                      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
------------------------------------------|---------|----------|---------|---------|-------------------
All files                                 |   96.96 |    90.04 |   96.07 |   97.05 |                   
 src                                      |     100 |      100 |     100 |     100 |                   
  globals.js                              |     100 |      100 |     100 |     100 |                   
 src/components                           |   73.33 |       25 |      20 |   73.33 |                   
  MyComponent.vue                         |   73.33 |       25 |      20 |   73.33 | 118-136 

How can we tell jest from Project 1 to bypass the test coverage for Project 2 components? (as those are already tested in Project 2).

In jest.config.js we have already tried forbidding getting coverage from Project 2 but this does nothing:

  collectCoverageFrom: [
    '!<rootDir>/node-modules/project2',
  ],

We haven't found any related or already asked question for this problem, so any help would be much appreciated!



No comments:

Post a Comment