Skip to content

Commit

Permalink
fix: support ESM packages (#144)
Browse files Browse the repository at this point in the history
* fix: support ESM packages

* chore: fix unit tests

* chore: fix e2e tests

* chore: README
  • Loading branch information
agoldis committed Jun 13, 2023
1 parent 1a504f2 commit 1d17d13
Show file tree
Hide file tree
Showing 47 changed files with 11,215 additions and 79 deletions.
26 changes: 20 additions & 6 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Install the package:
npm install cypress-cloud
```

- Create a new configuration file: `currents.config.js` in the Cypress project’s root
- Create a new configuration file: `currents.config.js|mjs|cjs` in the Cypress project’s root (Using ESM project? See the guide below).
- Set the `projectId` and the record key obtained from [Currents](https://app.currents.dev) or your self-hosted instance of Sorry Cypress:

```js
Expand Down Expand Up @@ -88,9 +88,15 @@ module.exports = {
};
```

`cypress-cloud` will search for `currents.config.js` at the project's root location (defined with `-P --project` CLI option).
`cypress-cloud` will search for a configuration file at the project's root location (defined with `-P --project` CLI option) in the following order:

Override the default configuration values via environment variables:
- `currents.config.js`
- `currents.config.cjs`
- `currents.config.mjs`

The configuration file will be read using [`import()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import) expression. Please make sure to use the correct syntax if you're using ESM modules (see the guide below).

You can override the configuration values via environment variables:

- `CURRENTS_API_URL` - sorry-cypress users - set the URL of your director service
- `CURRENTS_PROJECT_ID` - set the `projectId`
Expand All @@ -100,7 +106,7 @@ The configuration variables will resolve as follows:

- the corresponding CLI flag or `run` function parameter, otherwise
- environment variable if exist, otherwise
- `currents.config.js` value, otherwise
- `currents.config.js|cjs|mjs` value, otherwise
- the default value, otherwise throw

## Batched Orchestration
Expand Down Expand Up @@ -179,6 +185,16 @@ As an alternative, you can activate the `cloudPlugin` first, and then implement

Enable the debug mode to troubleshoot files discovery: `DEBUG=currents:specs npx cypress-cloud ...`

### Usage with ESM project

For ESM projects (`"type": "module"` in `package.json`) you can use one of the following formats:

- `currents.config.cjs` - CommonJS formatted file
- `currents.config.js` - ESM formatted file (i.e. no `require` statements)
- `currents.config.mjs` - ESM formatted file (i.e. no `require` statements)

Also, make sure that your `cypress.config.js|mjs|cjs|ts` is formatted accordingly. See examples at [`./e2e`](./e2e) directory.

## Troubleshooting

Enable the debug mode and run the command:
Expand Down Expand Up @@ -230,8 +246,6 @@ Using:
npm install cypress-cloud --registry http://localhost:4873
```



## Disclaimer

This software is not affilicated with Cypress.io Inc. All third party trademarks and materials (including logos, icons and labels) referenced herein are the property of their respective owners. The third party products or services that this software connects to are subject to their respective owners, please refer to their intellectual property and terms of service agreements.
50 changes: 50 additions & 0 deletions .github/workflows/e2e-config-esm-cjs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: e2e-config-esm-cjs

on:
push:

jobs:
e2e-config-esm-cjs:
if: "!contains(toJSON(github.event.commits.*.message), '[skip ci]')"
runs-on: ubuntu-latest
env:
DEBUG: currents:*

services:
director:
image: agoldis/sorry-cypress-director
ports:
- 1234:1234

strategy:
matrix:
node-version: ["18"]

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Link monorepo packages
run: npm install

- name: config-esm-cjs
working-directory: ./e2e/config-esm-cjs
env:
CURRENTS_API_URL: http://localhost:1234
run: >
npx cypress-cloud run
--record
--parallel
--key some-key
--browser chrome
--tag smoke,linux
--spec "./cypress/e2e/*.spec.js"
--ci-build-id "${{ github.repository }}-${{ github.run_id }}-${{ github.run_attempt}}"
50 changes: 50 additions & 0 deletions .github/workflows/e2e-config-esm-js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: e2e-config-esm-js

on:
push:

jobs:
e2e-config-esm-js:
if: "!contains(toJSON(github.event.commits.*.message), '[skip ci]')"
runs-on: ubuntu-latest
env:
DEBUG: currents:*

services:
director:
image: agoldis/sorry-cypress-director
ports:
- 1234:1234

strategy:
matrix:
node-version: ["18"]

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Link monorepo packages
run: npm install

- name: config-esm-js
working-directory: ./e2e/config-esm-js
env:
CURRENTS_API_URL: http://localhost:1234
run: >
npx cypress-cloud run
--record
--parallel
--key some-key
--browser chrome
--tag smoke,linux
--spec "./cypress/e2e/*.spec.js"
--ci-build-id "${{ github.repository }}-${{ github.run_id }}-${{ github.run_attempt}}"
50 changes: 50 additions & 0 deletions .github/workflows/e2e-config-esm-mjs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: e2e-config-esm-mjs

on:
push:

jobs:
e2e-config-esm-mjs:
if: "!contains(toJSON(github.event.commits.*.message), '[skip ci]')"
runs-on: ubuntu-latest
env:
DEBUG: currents:*

services:
director:
image: agoldis/sorry-cypress-director
ports:
- 1234:1234

strategy:
matrix:
node-version: ["18"]

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Link monorepo packages
run: npm install

- name: config-esm-mjs
working-directory: ./e2e/config-esm-mjs
env:
CURRENTS_API_URL: http://localhost:1234
run: >
npx cypress-cloud run
--record
--parallel
--key some-key
--browser chrome
--tag smoke,linux
--spec "./cypress/e2e/*.spec.js"
--ci-build-id "${{ github.repository }}-${{ github.run_id }}-${{ github.run_attempt}}"
50 changes: 50 additions & 0 deletions .github/workflows/e2e-config-noesm-js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: e2e-config-noesm-js

on:
push:

jobs:
e2e-config-noesm-js:
if: "!contains(toJSON(github.event.commits.*.message), '[skip ci]')"
runs-on: ubuntu-latest
env:
DEBUG: currents:*

services:
director:
image: agoldis/sorry-cypress-director
ports:
- 1234:1234

strategy:
matrix:
node-version: ["18"]

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Link monorepo packages
run: npm install

- name: config-noesm-js
working-directory: ./e2e/config-noesm-js
env:
CURRENTS_API_URL: http://localhost:1234
run: >
npx cypress-cloud run
--record
--parallel
--key some-key
--browser chrome
--tag smoke,linux
--spec "./cypress/e2e/*.spec.js"
--ci-build-id "${{ github.repository }}-${{ github.run_id }}-${{ github.run_attempt}}"
12 changes: 12 additions & 0 deletions e2e/config-esm-cjs/currents.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
e2e: {
batchSize: 3, // how many specs to send in one batch
},
component: {
batchSize: 5, // how many specs to send in one batch
},
projectId: !!(process.env.GITHUB_ACTION || process.env.CIRCLE_BRANCH)
? "Ij0RfK"
: "1OPP8c",
// cloudServiceUrl: "http://localhost:1234",
};
29 changes: 29 additions & 0 deletions e2e/config-esm-cjs/cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import grepPlugin from "@cypress/grep/src/plugin";
import { defineConfig } from "cypress";
import currents from "cypress-cloud/plugin";
import terminalPlugin from "cypress-terminal-report/src/installLogsPrinter";

export default defineConfig({
e2e: {
baseUrl: "https://todomvc.com/examples/vanillajs",
videoUploadOnPasses: false,
supportFile: "cypress/support/e2e.js",
specPattern: "cypress/*/**/*.spec.js",
setupNodeEvents(on, config) {
grepPlugin(config);
terminalPlugin(on);
return currents(on, config);
},
},

component: {
specPattern: ["pages/__tests__/*.spec.tsx"],
setupNodeEvents(on, config) {
return currents(on, config);
},
devServer: {
framework: "next",
bundler: "webpack",
},
},
});
10 changes: 10 additions & 0 deletions e2e/config-esm-cjs/cypress/e2e/smoke.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// type definitions for Cypress object "cy"
/// <reference types="cypress" />

describe("TodoMVC", function () {
// a very simple example helpful during presentations
it("adds 2 todos", function () {
cy.get(".new-todo").type("learn testing{enter}").type("be cool{enter}");
cy.get(".todo-list li").should("have.length", 2);
});
});
Loading

0 comments on commit 1d17d13

Please sign in to comment.