Skip to content
This repository was archived by the owner on Sep 1, 2024. It is now read-only.

Commit

Permalink
Add Cypress plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ramosbugs committed Jun 20, 2023
1 parent 8f2d407 commit 606e56d
Show file tree
Hide file tree
Showing 152 changed files with 15,441 additions and 323 deletions.
11 changes: 11 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# TypeScript uniques files that are included in a project twice via symlinks. eslint complains that
# the symlinked files aren't included in tsconfig.json (due to the deduping), so we ignore the
# symlinked copies and just lint the canonical location at:
# packages/cypress-plugin/test/integration-input/cypress/component
packages/cypress-plugin/test/integration-input*/cypress/e2e

# Cypress produces screenshot folders with names that match the *.ts glob, and eslint complains.
packages/cypress-plugin/test/**/cypress/screenshots/*.ts

# Don't lint output files.
packages/**/dist
115 changes: 103 additions & 12 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
- cron: 0 18 * * *

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch: { }
workflow_dispatch: {}

jobs:
check:
Expand All @@ -24,19 +24,32 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: '16'
node-version: "16"
cache: yarn

- uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('yarn.lock') }}

- id: install
run: yarn install --immutable

- run: yarn build

- run: yarn workspace @unflakable/cypress-plugin pack
- uses: actions/upload-artifact@v3
with:
name: cypress-plugin
path: packages/cypress-plugin/package.tgz

- run: yarn workspace @unflakable/jest-plugin pack
- uses: actions/upload-artifact@v3
with:
name: jest-plugin
path: packages/jest-plugin/package.tgz

- run: yarn workspace @unflakable/js-api pack
- uses: actions/upload-artifact@v3
with:
name: js-api
path: packages/js-api/package.tgz

- if: ${{ always() && steps.install.outcome == 'success' }}
run: yarn lint

Expand All @@ -56,6 +69,13 @@ jobs:
# it's ignored for PR events, but that's fine.
base: ${{ github.ref }}
filters: |
cypress:
- package.json
- tsconfig.json
- .github/workflows/ci.yaml
- packages/cypress-plugin/**
- packages/js-api/**
- packages/plugins-common/**
jest:
- package.json
- tsconfig.json
Expand All @@ -65,10 +85,86 @@ jobs:
- packages/plugins-common/**
- scripts/set-jest-version.ts
outputs:
affects_cypress: ${{ steps.affects_plugins.outputs.cypress }}
affects_jest: ${{ steps.affects_plugins.outputs.jest }}

cypress_integration_tests:
name: "Cypress Integration Tests: Cypress ${{ matrix.cypress }} + Node ${{ matrix.node }}"
# FIXME: also test on Windows
runs-on: ubuntu-latest
timeout-minutes: 45
needs:
# Don't incur the cost of the test matrix if the basic build fails.
- check
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || needs.check.outputs.affects_cypress == 'true'
strategy:
fail-fast: false
matrix:
node:
- 16
- 18
- 20
cypress:
# FIXME: support earlier versions
#- "10.0"
#- "10.11"
#- "11.0"
- "11.2"
- "12.0"
- "12.10"
- "12.14"
steps:
- uses: actions/checkout@v3

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

- name: Cache Cypress binary
uses: actions/cache@v3
with:
path: ~/.cache/Cypress
key: cypress-${{ runner.os }}-node${{ matrix.node }}-cypress${{ matrix.cypress }}-modules-${{ hashFiles('yarn.lock') }}

- id: install
run: yarn install --immutable

- name: Set Cypress version
run: |
yarn set resolution "cypress@npm:10 - 12" ${{ matrix.cypress }}
grep --after-context=1 "^\".*cypress.*" yarn.lock
- run: yarn build:plugins && yarn build:cypress-tests

- name: Test
env:
# Enable debug logs within the Jest tests that run Cypress. WARNING: these are very
# verbose but are useful for seeing the raw chalk terminal codes.
# DEBUG: unflakable:*

# Enable debug logs within the Cypress plugin.
# TEST_DEBUG: unflakable:*

# Enable terminal colors for debug() output.
DEBUG_COLORS: "1"

# Make chalk emit TTY colors.
FORCE_COLOR: "1"
run: |
if [ "${{ github.repository }}" == "unflakable/unflakable-javascript" ]; then
export UNFLAKABLE_SUITE_ID=2QwtGckRudLNUGBsdkVEoSknck1
else
export UNFLAKABLE_SUITE_ID=2Qwt9RyPIbOI95C6qjXCzcTelni
fi
UNFLAKABLE_API_KEY=${{ secrets.UNFLAKABLE_API_KEY }} \
yarn workspace cypress-integration test \
--reporters @unflakable/jest-plugin/dist/reporter \
--runner @unflakable/jest-plugin/dist/runner
jest_integration_tests:
name: "Jest Integration Tests: Jest ${{ matrix.jest }} + Node ${{ matrix.node }}"
# FIXME: also test on Windows
runs-on: ubuntu-latest
timeout-minutes: 15
needs:
Expand Down Expand Up @@ -118,11 +214,6 @@ jobs:
node-version: ${{ matrix.node }}
cache: yarn

- uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-node${{ matrix.node }}-jest${{ matrix.jest }}-modules-${{ hashFiles('yarn.lock') }}

- id: install
run: yarn install --immutable

Expand Down
127 changes: 127 additions & 0 deletions .github/workflows/cypress-realworld-app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
name: Cypress Real World App

# Controls when the workflow will run
on:
# Run daily so that we get continuous dogfooding.
schedule:
# Run at 7pm UTC/11am Pacific, which is after the CI pipeline runs so that we can use the
# latest build each day.
- cron: 0 19 * * *

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch: {}

jobs:
ui-chrome-tests:
timeout-minutes: 15
runs-on: ubuntu-latest
container:
image: cypress/browsers:node16.16.0-chrome105-ff104-edge
options: --user 1001
steps:
- name: Check out latest cypress-io/cypress-realworld-app
uses: actions/checkout@v3
with:
repository: cypress-io/cypress-realworld-app

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT

- uses: actions/cache@v3
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: |
${{ steps.yarn-cache-dir-path.outputs.dir }}
~/.cache/Cypress
key: yarn-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
yarn-${{ runner.os }}-
- name: Download latest cypress-realworld-app build
uses: dawidd6/action-download-artifact@v2
with:
repo: cypress-io/cypress-realworld-app
workflow: main.yml
branch: develop
name: build
path: build
search_artifacts: true

- name: Download latest Cypress plugin build
uses: dawidd6/action-download-artifact@v2
with:
workflow: ci.yaml
workflow_conclusion: success
branch: main

- run: yarn install --frozen-lockfile

- name: Install @unflakable/cypress-plugin
# We clean the Yarn cache here to make sure we're installing the package contents from the
# tarballs. Otherwise, Yarn may install the previously cached version from an earlier build
# with the same package version number.
run: |
curl -Lo jq https://github.com/jqlang/jq/releases/download/jq-1.6/jq-linux64
chmod +x jq
yarn cache clean @unflakable/js-api
yarn cache clean @unflakable/cypress-plugin
# See https://github.com/yarnpkg/yarn/issues/5357#issuecomment-748434801.
rm -rf "$(yarn cache dir)/.tmp"
# Make sure Yarn resolves @unflakable/js-api to the tarball. If we just try to install
# both packages at the same time, Yarn will complain if the js-api package version number
# doesn't exist in the public NPM registry.
cat package.json \
| ./jq '. + {"resolutions": (.resolutions + {"@unflakable/js-api": "file:./js-api/package.tgz"})}' \
> package-new.json
mv package-new.json package.json
yarn add --dev file:./cypress-plugin/package.tgz
- name: Cypress info
run: yarn cypress info

- name: Node info
run: node -v

- name: __e Dir
run: ls /__e

- name: "UI Tests - Chrome"
env:
DEBUG: "@cypress/github-action,unflakable:*"
UNFLAKABLE_SUITE_ID: 2RBwks266ZvV5jn9zR5Ula9XK7m
UNFLAKABLE_API_KEY: ${{ secrets.UNFLAKABLE_API_KEY }}
uses: cypress-io/github-action@v5
with:
install: false
command: yarn exec cypress-unflakable --
start: yarn start:ci
wait-on: "http://localhost:3000"
wait-on-timeout: 120
browser: chrome
record: true
parallel: true
group: "UI - Chrome"
spec: cypress/tests/ui/*
config-file: cypress.config.js

- name: Save screenshots
if: always()
uses: actions/upload-artifact@v3
# add the line below to store screenshots only on failures
# if: failure()
with:
name: cypress-screenshots
path: cypress/screenshots
if-no-files-found: ignore # 'warn' or 'error' are also available, defaults to `warn`

- name: Save videos
if: always()
uses: actions/upload-artifact@v3
with:
name: cypress-videos
path: cypress/videos
if-no-files-found: ignore # 'warn' or 'error' are also available, defaults to `warn`
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16.20.0
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.yarn
packages/cypress-plugin/**/cypress/screenshots/*.ts
packages/**/dist
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
yarnPath: .yarn/releases/yarn-3.5.1.cjs
nodeLinker: node-modules
nmMode: hardlinks-local

# By default, publish packages privately to GitHub for internal testing instead of to NPM.
npmScopes:
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ and TypeScript.
Refer to our [Getting Started](https://docs.unflakable.com/getting-started) documentation
for instructions on getting started using Unflakable.

## Cypress Plugin

This Unflakable plugin enables users of the [Cypress](https://cypress.io) JavaScript test framework
to quarantine flaky tests and track test results.

Refer to the [Cypress Plugin](https://docs.unflakable.com/plugins/cypress) documentation for
complete usage instructions.

### Compatibility

This plugin maintains compatibility with the Cypress and Node.js versions listed below:

[![11.2.0+ | 12.0.0+](https://img.shields.io/badge/Cypress-11.2.0%2B%20%7C%2012.0.0%2B-17202C?logo=cypress&labelColor=white&logoColor=17202C&style=flat)](https://cypress.io)
[![16 | 18 | 20](https://img.shields.io/badge/Node.js-16%20%7C%2018%20%7C%2020-339933?logo=node.js&labelColor=white&logoColor=339933&style=flat)](https://nodejs.org)

## Jest Plugin

The Jest plugin enables users of the [Jest](https://jestjs.io) JavaScript test framework
Expand Down
28 changes: 16 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
"@babel/core": "^7.21.5",
"@babel/preset-env": "^7.21.5",
"@babel/preset-typescript": "^7.21.5",
"@rollup/plugin-node-resolve": "^15.0.2",
"@rollup/plugin-typescript": "^11.1.0",
"@types/debug": "^4.1.7",
"@types/js-yaml": "^4.0.5",
"@types/node": "^14.18.43",
Expand All @@ -16,33 +14,39 @@
"debug": "^4.3.3",
"eslint": "^8.39.0",
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-cypress": "^2.13.3",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jest": "^27.2.1",
"js-yaml": "^4.1.0",
"prettier": "^2.5.1",
"rollup": "^3.21.1",
"semver": "^7.5.1",
"ts-node": "^10.7.0",
"typescript": "^4.9.5"
},
"scripts": {
"audit": "yarn npm audit --all --recursive",
"build": "yarn build:plugins && yarn typecheck:scripts && yarn typecheck:tests",
"build:plugins": "yarn build:js-api && yarn build:plugins-common && yarn build:jest-plugin",
"build": "yarn build:plugins && yarn typecheck:scripts && yarn build:tests",
"build:plugins": "yarn build:js-api && yarn build:plugins-common && yarn build:cypress-plugin && yarn build:jest-plugin",
"build:js-api": "yarn workspace @unflakable/js-api build",
"build:plugins-common": "yarn workspace @unflakable/plugins-common build",
"build:cypress-plugin": "yarn workspace @unflakable/cypress-plugin build",
"build:jest-plugin": "yarn workspace @unflakable/jest-plugin build",
"build:plugins-common": "yarn workspace @unflakable/plugins-common build",
"typecheck:scripts": "tsc --noEmit --types node -p scripts",
"typecheck:tests": "yarn workspace jest-integration typecheck && yarn workspace jest-integration-input typecheck",
"lint": "eslint packages/**/src/**/*.{ts,js} scripts/**/*.{ts,js}",
"prettier": "prettier --write packages/**/src/*.{ts,js}",
"prettier:check": "prettier --check packages/**/src/*.{ts,js}",
"build:tests": "yarn build:cypress-tests && yarn typecheck:jest-tests",
"build:cypress-tests": "yarn workspace cypress-integration-common build && yarn workspace cypress-integration typecheck && yarn workspace cypress-integration-input typecheck && yarn workspace cypress-integration-input-esm typecheck",
"typecheck:jest-tests": "yarn workspace jest-integration typecheck && yarn workspace jest-integration-input typecheck",
"lint": "eslint .",
"prettier": "prettier --write .",
"prettier:check": "prettier --check .",
"publish": "yarn workspace @unflakable/js-api npm publish --access public && yarn workspace @unflakable/jest-plugin npm publish --access public",
"set-jest-version": "ts-node scripts/set-jest-version.ts"
},
"workspaces": [
"packages/*",
"packages/jest-plugin/test/integration",
"packages/jest-plugin/test/integration-input"
"packages/*/test/integration",
"packages/*/test/integration-common",
"packages/*/test/integration-input",
"packages/*/test/integration-input-esm",
"packages/*/test/integration-input-manual"
]
}
Loading

0 comments on commit 606e56d

Please sign in to comment.