查找有关如何定位无效/意外令牌的实际源的建议。
我在用柏树运行测试,大多数时候(虽然不是一致的),我从所有的测试中得到了这个错误。
Uncaught SyntaxError: Invalid or unexpected token
This error originated from your application code, not from Cypress.
When Cypress detects uncaught errors originating from your application it will automatically fail the current test.
This behavior is configurable, and you can choose to turn this off by listening to the 'uncaught:exception' event.
https://on.cypress.io/uncaught-exception-from-application所以,让我们说清楚;我确实理解这是我的应用程序代码的问题,而不是我的测试代码。我的问题是,我还没有看到任何指向实际位置的语法错误。此外,我运行的铬 72应用程序(不是通过柏树),我有无问题。只有当我通过柏树运行应用程序时才会出现问题(也使用chrome 72,因为我运行柏树规范时使用的是--browser chrome )。
我已经将fail和uncaught:exception处理程序添加到我的测试中以捕获输出,尽管我仍然找不到任何东西来指导我找到错误的实际来源。
通过中断uncaught:exception处理程序,传递了两个arg: 1)错误(与上面相同);2) mocha(我认为)可运行:
Hook {title: ""before all" hook", fn: ƒ, body: "function () {↵ var _this = this;↵↵ debugger;… cy.visit("/#/account-management");↵ });↵ }", async: 0, sync: true, …}
$events: {error: Array(1)}
async: 0
body: "function () {↵ var _this = this;↵↵ debugger;↵ cy.on('fail', event_handler_functions_1.failHandler.bind(this));↵ cy.on('uncaught:exception', function (e, r) {↵ console.log(e, r);↵ debugger;↵ });↵ cy.fixture(Cypress.env("environmentSettings")).then(function (fixture) {↵ _this.environmentData = environmentData = fixture;↵ cy.launchApp(environmentData.baseUrl, environmentData.username, environmentData.password↵ /*, 300000*/↵ );↵ cy.visit("/#/account-management");↵ });↵ }"
callback: ƒ done(err)
ctx: Context {currentTest: Test, _runnable: Hook, test: Hook, environmentData: {…}}
fn: ƒ ()
hookId: "h1"
hookName: "before all"
id: "r3"
parent: Suite {title: "Account Management", ctx: Context, suites: Array(0), tests: Array(3), pending: false, …}
pending: false
sync: true
timedOut: false
timer: null
title: ""before all" hook"
type: "hook"
_currentRetry: 0
_enableTimeouts: false
_retries: -1
_slow: 75
_timeout: 4000
_trace: Error: done() called multiple times at Hook.Runnable (https://localhost:44399/__cypress/runner/cypress_runner.js:30161:17) at new Hook (https://localhost:44399/__cypress/runner/cypress_runner.js:26593:12) at Suite.beforeAll (https://localhost:44399/__cypress/runner/cypress_runner.js:31573:14) at before (https://localhost:44399/__cypress/runner/cypress_runner.js:26770:17) at context.describe.context.context (https://localhost:44399/__cypress/runner/cypress_runner.js:26666:10)
__proto__: Runnable在我的测试中,我已经通过了before(),在chrome调试器中启用了“暂停异常”。在我完成了before()中的所有内容并必须“恢复脚本执行”之后,才会出现任何错误。注意,我的测试中没有beforeAll()挂钩,只有一个before()。
我最近没有做过使用异常语法的更改(据我所知),而且我已经有几周没有在本地环境中运行测试套件了,因此有很多更改--太多的更改让我觉得一个接一个地筛选它们是值得的。
下面是来自错误实例的测试,以供参考,尽管它们都有相同的问题。
import { failHandler } from "..\\..\\support\\event-handler-functions"
describe('Account Management', function () {
var environmentData: CypressTypings.EnvrionmentSettings;
before(function () {
debugger;
cy.on('fail', failHandler.bind(this))
cy.on('uncaught:exception', (e, r) => {console.log(e, r); debugger;})
cy.fixture(Cypress.env("environmentSettings")).then((fixture) => {
(<any>this).environmentData = environmentData = fixture
cy.launchApp(environmentData.baseUrl, environmentData.username, environmentData.password/*, 300000*/);
cy.visit("/#/account-management");
});
})
beforeEach(() => {
Cypress.Cookies.preserveOnce(environmentData.cookieName)
})
it('Loads Governments', function () {
cy.get("[data-cy=government-panel]", { timeout: 20000 }).should("have.length.gte", 1);
})
it('Users Page Loads', function () {
cy.get("[data-cy=government-panel]").first().find(".fa-users").click();
cy.get("tbody", { timeout: 20000 }).find("tr").should("have.have.length.greaterThan", 0);
cy.get("[data-cy=return-to-organization-button]").click();
cy.get("[data-cy=government-panel]").should("exist");
})
it('Service Area Page Loads', function () {
cy.get("[data-cy=government-panel]").first().find(".fa-globe").click();
cy.get("tbody", { timeout: 20000 }).find("tr").should("have.have.length.greaterThan", 0);
cy.get("[data-cy=return-to-organization-button]").click();
cy.get("[data-cy=government-panel]").should("exist");
})
})还值得注意的是:launchApp()步骤实际上发生了--应用程序登录,然后在应用程序加载时,语法错误被引发,visit()步骤从未实际执行。
发布于 2019-02-28 21:56:47
我削减了我们的npm包,怀疑可能是添加了一个包可能引入了SyntaxError。我删除了大约1/4的npm包(无论如何,这些包早就过期了),并清理了我们的依赖关系。在那之后,Uncaught SyntaxError就消失了。
我怀疑这是导致错误的下列包之一,但我不能明确地说,因为我从来没有确切地指出错误的来源。
我已经删除的包(其中一些可能是我们最近更新的):
@types/plotly.js
aurelia-animator-css
@types/jest
@types/node
@types/pikaday
ajv
d3
jest
jest-cli
jquery-sparkline
nps-utils
opn
protractor
ts-jest
ts-node
uglify-js
vinyl-fs
wait-on发布于 2020-06-09 23:35:26
如果将来有其他人遇到这种情况,我的任务就是尝试加载一个不存在的JS文件(从我的索引页面)。
Cypress似乎隐藏了错误,所以记录它是有帮助的;
Cypress.on('uncaught:exception', (err, runnable) => {
console.log(err);
return false;
})https://stackoverflow.com/questions/54833962
复制相似问题