最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Cypress 组件测试抛出“process is not defined”

网站源码admin51浏览0评论

Cypress 组件测试抛出“process is not defined”

Cypress 组件测试抛出“process is not defined”

我正在尝试在使用 Vue 2 和 Webpack 制作的 PWA 上运行组件测试。当我尝试运行它们时,我收到一条错误消息说

process is not defined
,这使我无法进行我想要的测试。 我的项目具有以下依赖项:

"dependencies": {
    "compressorjs": "^1.1.1",
    "dotenv": "^16.0.3",
    "jquery": "^3.4.1",
    "lodash": "^4.17.21",
    "npm": "^6.10.0",
    "register-service-worker": "^1.5.2",
    "vue": "^2.6.14",
    "vue-router": "^3.0.1",
    "vuex": "^3.0.1",
    "vuex-persist": "^3.1.3"
  },
  "devDependencies": {
    "@babel/cli": "^7.2.3",
    "@babel/core": "^7.12.16",
    "@babel/polyfill": "^7.2.5",
    "@babel/preset-env": "^7.21.4",
    "@vue/cli-plugin-babel": "~5.0.0",
    "@vue/cli-plugin-eslint": "~5.0.0",
    "@vue/cli-plugin-pwa": "^3.1.1",
    "@vue/cli-service": "~5.0.0",
    "babel-helper-vue-jsx-merge-props": "^2.0.3",
    "babel-plugin-syntax-jsx": "^6.18.0",
    "babel-plugin-transform-vue-jsx": "^3.7.0",
    "babel-preset-env": "^1.7.0",
    "copyfiles": "^1.2.0",
    "css-loader": "^6.7.3",
    "cypress": "^12.11.0",
    "node-sass": "^4.12.0",
    "sass-loader": "^7.1.0",
    "vue-cli-plugin-vuetify": "^0.1.6",
    "vue-loader": "^15.10.1",
    "vue-template-compiler": "^2.7.14",
    "web-push": "^3.3.3",
    "webpack": "^5.80.0",
    "workbox-cli": "^3.5.0"
  }

我的 webpack 配置文件如下所示:

const { VueLoaderPlugin } = require('vue-loader')

module.exports = {
  entry: ["@babel/polyfill", "./app.vue"],
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          'css-loader'
        ]
      },
      {
        test: /\.vue$/,
        loader: 'vue-loader'
      }
    ]
  },
  plugins: [
    new VueLoaderPlugin()
  ]
};

我的赛普拉斯配置文件如下所示:

const { defineConfig } = require("cypress");
const webpackConfig = require('./src/webpack.config');

module.exports = defineConfig({
  component: {
    devServer: {
      framework: "vue",
      bundler: "webpack",
      webpackConfig
    },
  },
});

我的测试文件是这样的:

import Loading from './Loading.vue'

describe('<Loading />', () => {
  it('renders', () => {
    cy.mount(Loading)
  })
})

我想这是依赖关系之间的冲突或某些加载程序库的问题。

我尝试实施论坛中提出的所有解决方案,但没有一个对我有用。我也用vue 2创建了一个新项目,测试运行完美,但我找不到问题的原因。

回答如下:
发布评论

评论列表(0)

  1. 暂无评论