Skip to content

Commit

Permalink
fix(cypress): compatibility with esm bundlers
Browse files Browse the repository at this point in the history
Webpack does support `require.resolve` but other bundlers
like esbuild does not.

We improve the compatibility by using `require.resolve` only if
it is available.
  • Loading branch information
samtsai authored and gregberge committed Nov 3, 2023
1 parent 7aae22b commit fbf3d91
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/cypress/src/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ declare global {

function injectArgos() {
const fileName =
typeof require?.resolve === "function"
typeof require.resolve === "function"
? require.resolve("@argos-ci/browser/global.js")
: "node_modules/@argos-ci/browser/dist/global.js";
cy.readFile<string>(fileName).then((source) =>
Expand All @@ -43,7 +43,7 @@ function injectArgos() {

function readArgosCypressVersion() {
const fileName =
typeof require?.resolve === "function"
typeof require.resolve === "function"
? require.resolve("@argos-ci/cypress/package.json")
: "node_modules/@argos-ci/cypress/package.json";
return cy.readFile(fileName).then((source) => {
Expand Down

0 comments on commit fbf3d91

Please sign in to comment.