我目前使用 Remix 的独立堆栈,但尝试使用 cypress 运行测试时,在 cypress 浏览器中向我发送了该错误,有人有类似的问题吗?我从头开始使用独立堆栈
https://github.com/remix-run/indie-stack
这是完整的错误。
Error: Webpack Compilation Error
./node_modules/@testing-library/dom/dist/@testing-library/dom.esm.js 429:27
Module parse failed: Unexpected token (429:27)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- types are not aware of older browsers that don't implement `labels`
| if (element.labels !== undefined) {
> return element.labels ?? [];
| }
|
@ ./node_modules/@testing-library/cypress/dist/index.js 9:11-42
@ ./node_modules/@testing-library/cypress/dist/add-commands.js
@ ./node_modules/@testing-library/cypress/add-commands.js …Run Code Online (Sandbox Code Playgroud) 我有一个网址https://www.xxx/xxxx/xxx/1234。我只需要数字 1234 并将它们存储在我的全局变量中。
cy.log(this.href.substring(this.href.lastIndexOf('/') + 1));
Run Code Online (Sandbox Code Playgroud) 我通过commands.js下的命令loginByGoogleApi访问我的Gmail帐户,然后获取请求的电子邮件正文并从正文中提取所需的数据,并将其保存在const变量代码中,在我的testFile.cy中输入提取的电子邮件数据(代码) .js。我可以在此之后登录,但 cypress 向我抛出错误cy.type() 失败,因为它针对的是禁用元素。
命令.js
/// <reference types="cypress"
import { parseString } from "xml2js";
Cypress.Commands.add('loginByGoogleApi', () => {
cy.request({
method: 'POST',
url: 'https://www.googleapis.com/oauth2/v4/token',
body: {
grant_type: 'refresh_token',
client_id: Cypress.env('googleClientId'),
client_secret: Cypress.env('googleClientSecret'),
refresh_token: Cypress.env('googleRefreshToken'),
},
}).then(({ body }) => {
const { access_token, id_token } = body
cy.log('Opening emails including code to verify')
cy.request({
method: 'GET',
url: 'https://mail.google.com/mail/feed/atom/verifyCode',
headers: { Authorization: Bearer ${access_token} },
}).then(({ body }) => {
parseString(body, function (err, results) {
let data = JSON.stringify(results)
let …Run Code Online (Sandbox Code Playgroud)