Javascript 使用Vue、Cypress和Cucumber进行测试时如何使用类?
我正在尝试实现一些简单的东西:我希望我的e2e测试使用Cypress和cucumber运行。Javascript 使用Vue、Cypress和Cucumber进行测试时如何使用类?,javascript,vue.js,cucumber,tdd,cypress,Javascript,Vue.js,Cucumber,Tdd,Cypress,我正在尝试实现一些简单的东西:我希望我的e2e测试使用Cypress和cucumber运行。 我使用Vue CLI 4.1.1创建了一个应用程序。我添加了NPM包:cypress Cumber预处理器(V1.19.0) 编辑: 经过大量的研究和测试,我想我找到了问题的根源,但我还不知道如何解决它: “@vue/cli plugin babel/preset”似乎无法使用 .功能文件 我的babel.config.js文件是: module.exports = { presets: [
我使用Vue CLI 4.1.1创建了一个应用程序。我添加了NPM包:cypress Cumber预处理器(V1.19.0) 编辑:
经过大量的研究和测试,我想我找到了问题的根源,但我还不知道如何解决它: “@vue/cli plugin babel/preset”似乎无法使用 .功能文件 我的babel.config.js文件是:
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
]
}
你知道如何使用cucumber cypress制作cli插件babel
原始信息:
我有一个Test.feature文件,执行Test.step.js文件中定义的步骤。
下面是我的test.spec.js的内容
import { When, Then } from 'cypress-cucumber-preprocessor/steps';
import { HomePage } from './pages/home.page';
When(/^I open the Home page$/, () => {
let homePage = new HomePage();
homePage.goTo();
});
Then(/^I see "([^"]*)" in the main heading$/, msg => {
cy.contains('h1', msg)
});
以及my PageObject home.page.js的内容:
export class HomePage {
goTo() {
cy.visit("/");
}
}
当我跑步时:
npm run test:e2e
我得到以下错误:
Oops...we found an error preparing this test file:
tests/e2e/features/Test.feature
The error was:
SyntaxError: 'import' and 'export' may appear only with 'sourceType: module'
This occurred while Cypress was compiling and bundling your test code. This is usually caused by:
- A missing file or dependency
- A syntax error in the file or one of its dependencies
Fix the error in your code and re-run your tests.
使用以下命令时不会出现这些错误:
export function goToHomePage() {
cy.visit("/");
}
您可以在Github上签出我的项目:(对于通过的案例,使用branch master,对于失败的案例,使用branch pageObject_模式)
我假设这与ES6和cypress有关。。。但我显然不知道这里发生了什么。除此之外,我在网上找到的所有东西都在谈论cypress Cumber和Typescript,我不使用它们
我遗漏了什么?我找到了答案。有关更多详细信息,请参阅此PR: 基本上,Babel 7和Cypress 3之间存在不兼容。我必须更改babel.config.js文件:
module.exports = process.env.CYPRESS_ENV
? {}
: {
presets: ["@vue/cli-plugin-babel/preset"]
};
这只是一个变通办法,不是真正的解决办法。我们在运行cypress时必须禁用babel
希望能帮助你