scottohara / loot

An implementation of some of the core MS Money features in Ruby on Rails
MIT License
4 stars 3 forks source link

ES2019 target required for nullish coalescing in Cypress tests #185

Closed scottohara closed 1 year ago

scottohara commented 3 years ago

After upgrading from cypress@4.8.0 to cypress@6.8.0, the e2e suite started failing when compiling the following code (from support/schedules/index.ts):

cy.get(scheduleDebitAmount).should("contain.text", debitAmount ?? "");
cy.get(scheduleCreditAmount).should("contain.text", creditAmount ?? "");

The reason it started failing after the Cypress upgrade was that they fixed the issue of ignoring user-supplied tsconfig.json files.

This fix meant that the tests were now being compiled using target: ES2020 (from the tsconfig.json file in the project root).

Nullish coalescing should be supported in ES2020, however there is a bug in acorn 6.x (used by webpack 4), which is fixed in acorn 7.3.0 (used by webpack 5). It seems that webpack 4 is unlikely to be upgraded to the fixed version of acorn; so the issue should eventually be resolved once we can upgrade to webpack 5.

In the meantime, there is a somewhat odd workaround by setting target: ES2019 (in cypress/tsconfig.json).

https://stackoverflow.com/questions/58813176/webpack-cant-compile-ts-3-7-optional-chaining-nullish-coalescing

This is only a stop-gap measure while we wait to upgrade to webpack 5

eric-burel commented 2 years ago

Same issue here, works ok with ES2019 but not with ES2020. Also it won't work in the support folder, for instance for a before script, even with ES2019.

scottohara commented 1 year ago

This was resolved in Cypress 12.17.4, that upgraded the internal version of webpack that Cypress uses to bundle e2e tests from v4 to v5.