Troubleshooting Vue-Jest Module Not Found Error in Drone CI

When setting up unit tests in your Drone CI pipeline, you may encounter the following validation error:

Validation Error:

  Module <rootDir>/node_modules/vue-jest in the transform option was not found.

This error typically arises from an incorrect configuration in your Jest setup. Below, we will explore how to resolve this issue.

Understanding the Error

The error indicates that Jest cannot locate the vue-jest module specified in your configuration file. This can happen for several reasons, including incorrect paths or missing dependencies.

Example Jest Configuration

Here’s a sample configuration for your jest.config.js file:

module.exports = {
  transform: {
    "^.+\.js$": "babel-jest",
    ".*\.vue$": "vue-jest"
  },
  moduleFileExtensions: ["js", "json", "vue"],
};

Key Points:

  • Ensure that vue-jest is installed in your project. You can do this by running:
    npm install --save-dev vue-jest
  • The path to vue-jest should not include <rootDir>/node_modules/. Instead, simply use vue-jest as shown above.

Common Fixes

  1. Install the Correct Version: If you have upgraded your dependencies, make sure you are using the correct version of vue-jest. As of recent updates, you may need to switch to @vue/vue2-jest or @vue/vue3-jest depending on your Vue version.

  2. Check Your Node Modules: If you continue to face issues, verify that vue-jest is present in your node_modules directory. If not, reinstall your dependencies:

    npm install
  3. Update Your Configuration: If you are using a newer version of vue-jest, ensure your Jest configuration reflects any changes in the module name or structure.

Conclusion

By following these steps, you should be able to resolve the 'Module vue-jest in the transform option was not found' error in your Drone CI setup. Always refer to the Jest Configuration Documentation for the latest updates and best practices.