Skip to content
This repository was archived by the owner on Jun 8, 2022. It is now read-only.

Commit 734a38e

Browse files
authored
Add gh workflow with several different implementations (#89)
* add github workflow * add another test job using cy gh action * add actions cache test job * move env to the right place * new cache * describe workflow in README
1 parent 4815f8e commit 734a38e

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

.github/workflows/ci.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: ci
2+
on: [push]
3+
jobs:
4+
e2e:
5+
runs-on: ubuntu-20.04
6+
steps:
7+
- name: Checkout 🛎
8+
uses: actions/checkout@v2
9+
10+
- name: Install and run Cypress tests 🌲
11+
uses: cypress-io/github-action@v2
12+
13+
unit:
14+
runs-on: ubuntu-20.04
15+
steps:
16+
- name: Checkout 🛎
17+
uses: actions/checkout@v2
18+
19+
# we are only interested in installing and caching dependencies,
20+
# without installing the Cypress binary
21+
- name: Install NPM dependencies 📦
22+
uses: bahmutov/npm-install@v1
23+
env:
24+
# we do not need to install Cypress itself
25+
# as we do not plan to run tests
26+
CYPRESS_INSTALL_BINARY: 0
27+
28+
- name: Run Jest tests 🧪
29+
run: npm test
30+
31+
unit-using-cypress-gh-action:
32+
runs-on: ubuntu-20.04
33+
steps:
34+
- name: Checkout 🛎
35+
uses: actions/checkout@v2
36+
37+
# we are only interested in installing and caching dependencies,
38+
# without installing the Cypress binary
39+
- name: Install NPM dependencies 📦
40+
uses: cypress-io/github-action@v2
41+
# we do not want to accidentally overwrite
42+
# the full cache created in the e2e test job
43+
# because this job does not cache Cypress binary
44+
# thus we use custom cache key
45+
with:
46+
cache-key: unit-cache-v1-${{ runner.os }}-hash-${{ hashFiles('package-lock.json') }}
47+
env:
48+
# we do not need to install Cypress itself
49+
# as we do not plan to run tests
50+
CYPRESS_INSTALL_BINARY: 0
51+
52+
- name: Run Jest tests 🧪
53+
run: npm test
54+
55+
unit-without-any-helpers:
56+
runs-on: ubuntu-20.04
57+
steps:
58+
- name: Checkout 🛎
59+
uses: actions/checkout@v2
60+
61+
# use actions/cache to restore / save cache
62+
- name: Cache dependencies 💎
63+
uses: actions/cache@v2
64+
with:
65+
path: ~/.npm
66+
# use key string with "v1" for simple cache invalidation
67+
key: dependencies-v1-${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
68+
69+
- name: Install dependencies 📦
70+
run: npm ci
71+
env:
72+
# we do not need to install Cypress itself
73+
# as we do not plan to run tests
74+
CYPRESS_INSTALL_BINARY: 0
75+
76+
- name: Run Jest tests 🧪
77+
run: npm test

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@ See the excellent advice on setting TypeScript for Jest and Cypress in [TypeScri
3333

3434
If you hit a problem using Jest and Cypress in the same project, please open an issue in this repository. Include a fork of this repository that shows the problem.
3535

36+
## CircleCI workflow
37+
38+
The file [.circleci/config.yml](./.circleci/config.yml) shows how to run Cypress and Jest tests using [Cypress CircleCI Orb](https://github.com/cypress-io/circleci-orb)
39+
40+
## GitHub Actions workflow
41+
42+
This repo shows how to install dependencies and how to run Jest test in separate jobs on GitHub Actions. See the workflow file [.github/workflows/ci.yml](./.github/workflows/ci.yml) for several different approaches
43+
44+
- install and cache dependencies yourself using [actions/cache](http://github.com/actions/cache)
45+
- install and cache NPM dependencies using [bahmutov/npm-install](https://github.com/bahmutov/npm-install) helper
46+
- install and cache NPM dependencies using [cypress-io/github-action](https://github.com/cypress-io/github-action)
47+
48+
**Tip:** you can learn more about running Cypress tests on continuous integration services from [Cypress CI guide](https://on.cypress.io/ci) and [Cypress on CI workshop](https://github.com/cypress-io/cypress-workshop-ci).
49+
3650
## License
3751

3852
This project is licensed under the terms of the [MIT license](/LICENSE.md).

0 commit comments

Comments
 (0)