R
R
raynhour2020-02-08 00:10:33
JavaScript
raynhour, 2020-02-08 00:10:33

How to define alias path for jest-puppeteer?

When trying to run tests, jest swears that it cannot find files in which let it be registered through alias.
Example:

import ROUTER_NAMES from "@/app/auth/core/router-const"

Gives an error Cannot find module '@/app/auth/core/router-const' from 'middleware-auth.js'

jest.config.js has a moduleNameMapper and it works for unit tests.
moduleNameMapper: {
    "^@/(.*)$'": "<rootDir>/src/$1"
  ...

But now it doesn't work for integration ones.

Where do I need to specify aliases for jest-puppeteer?
// jest.config.js

const { defaults } = require(`jest-config`);

const puppeteerModes = [`acceptance`, `integration`];
const { TEST_MODE } = process.env;
const PUPPETEER_MODE = puppeteerModes.includes(TEST_MODE);

module.exports = {
  preset: PUPPETEER_MODE ? `jest-puppeteer` : '@vue/cli-plugin-unit-jest',
  setupFiles: [
    PUPPETEER_MODE ? '<rootDir>/tests/unit/integration/setup.js' : "<rootDir>/tests/unit/setup.js"
  ],
  setupFilesAfterEnv: [`<rootDir>/tests/unit/integration/after-env.js`],
  testMatch: TEST_MODE === `integration` ? [
    `**/?(*.)+(integration).[tj]s?(x)`,
  ] : defaults.testMatch,
  testURL: `http://localhost:8080`,
  testPathIgnorePatterns: [
    "node_modules/(?!(vuetify)/)"
  ],
  moduleNameMapper: {
    "^@/(.*)$'": "<rootDir>/src/$1",
    "^vuetify/lib$": "vuetify"
  }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question