I searched through all the web and seems like no one ever had a problem with Pug while testing with Cypress. Anyone?
I'm using Pug with Vue 3.
The following error originated from your test code, not from Cypress.
> Module build failed (from ./node_modules/pug-plain-loader/index.js):
Error: Cannot find module 'pug'
/cypress/support/component.js
// ***********************************************************
// This example support/component.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************
// Import commands.js using ES2015 syntax:
import './commands'
// Alternatively you can use CommonJS syntax:
// require('./commands')
import { mount } from 'cypress/vue'
// Cypress.Commands.add('mount', mount)
import App from '@/App.vue'
import { h } from 'vue'
import pugPlainLoader from 'pug-plain-loader'
Cypress.Commands.add('mount', (component, ...args) => {
args.global = args.global || {}
args.global.plugins = args.global.plugins || []
args.global.plugins.push(pugPlainLoader())
return mount(() => {
return h(App, {}, component)
}, ...args)
})
// Example use:
// cy.mount(MyComponent)
package.json
"dependencies": {
"@cypress/vue": "^3.1.0",
"@cypress/webpack-dev-server": "^3.2.2",
"core-js": "^3.8.3",
"cypress": "^12.3.0",
"path": "^0.12.7",
"pug": "^3.0.2",
"pug-plain-loader": "^1.1.0",
"vue": "^3.2.13"
},
"devDependencies": {
"@babel/core": "^7.12.16",
"@babel/eslint-parser": "^7.12.16",
"@vue/cli-plugin-babel": "~5.0.0",
"@vue/cli-plugin-eslint": "~5.0.0",
"@vue/cli-plugin-unit-jest": "~5.0.0",
"@vue/cli-service": "~5.0.0",
"@vue/test-utils": "^2.0.0-0",
"@vue/vue3-jest": "^28.1.0",
"babel-jest": "^27.0.6",
"eslint": "^7.32.0",
"eslint-plugin-vue": "^8.0.3",
"jest": "^27.0.5",
"vue-cli-plugin-pug": "^2.0.0"
},