Skip to content

Commit bbdc1fc

Browse files
committed
chore: add cypress and GitHub workflows
1 parent 7f6c67d commit bbdc1fc

File tree

16 files changed

+1012
-48
lines changed

16 files changed

+1012
-48
lines changed

.eslintrc.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@
77
"plugin:react/recommended",
88
"airbnb",
99
"plugin:@typescript-eslint/recommended",
10-
"prettier"
10+
"prettier",
11+
"plugin:cypress/recommended"
1112
],
13+
"globals": {
14+
"cy": true,
15+
"Cypress": true
16+
},
1217
"parser": "@typescript-eslint/parser",
1318
"parserOptions": {
1419
"ecmaFeatures": {
@@ -19,6 +24,7 @@
1924
},
2025
"plugins": ["react", "react-hooks", "@typescript-eslint", "prettier"],
2126
"rules": {
27+
"import/prefer-default-export": "off",
2228
"prettier/prettier": "error",
2329
"import/extensions": [
2430
"error",

.github/workflows/cypress.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: cypress tests
2+
on: [push]
3+
jobs:
4+
cypress-run:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- name: checkout
8+
uses: actions/checkout@v2
9+
10+
- name: set up node
11+
uses: actions/setup-node@v2
12+
with:
13+
node-version: '14'
14+
cache: 'yarn'
15+
16+
- name: install yarn
17+
# avoid checksum errors with github packages
18+
run: YARN_CHECKSUM_BEHAVIOR=update yarn
19+
20+
- name: cypress run
21+
uses: cypress-io/github-action@v2
22+
env:
23+
REACT_APP_API_HOST: http://localhost:3636
24+
REACT_APP_GRAASP_DOMAIN: localhost
25+
REACT_APP_GRAASP_APP_ID: id-1234567890
26+
REACT_APP_MOCK_API: true
27+
NODE_ENV: test
28+
with:
29+
install: false
30+
config: baseUrl=http://localhost:3000
31+
start: yarn start:ci
32+
wait-on: 'http://localhost:3000'
33+
wait-on-timeout: 180
34+
browser: chrome
35+
headless: true
36+
quiet: true
37+
38+
# after the test run completes
39+
# store videos and any screenshots
40+
# NOTE: screenshots will be generated only if E2E test failed
41+
# thus we store screenshots only on failures
42+
# Alternative: create and commit an empty cypress/screenshots folder
43+
# to always have something to upload
44+
- uses: actions/upload-artifact@v2
45+
if: failure()
46+
with:
47+
name: cypress-screenshots
48+
path: cypress/screenshots
49+
# Test run video was always captured, so this action uses "always()" condition
50+
- uses: actions/upload-artifact@v2
51+
if: always()
52+
with:
53+
name: cypress-videos
54+
path: cypress/videos
55+
56+
- name: coverage report
57+
run: npx nyc report --reporter=text-summary

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,25 @@
1616
.env.local
1717
.env.development.local
1818
.env.test.local
19+
.env.test
1920
.env.production.local
2021

2122
npm-debug.log*
2223
yarn-debug.log*
2324
yarn-error.log*
2425

26+
# yarn
27+
.yarn/
28+
!.yarn/patches
29+
!.yarn/plugins
30+
!.yarn/releases
31+
!.yarn/sdks
32+
!.yarn/versions
33+
yarn-error.log
34+
2535
# editor files
2636
/.idea
37+
38+
# cypress
39+
cypress/screenshots/
40+
cypress/videos/

.yarnrc.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
nodeLinker: node-modules
22

3+
plugins:
4+
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
5+
spec: '@yarnpkg/plugin-interactive-tools'
6+
37
yarnPath: .yarn/releases/yarn-3.2.0.cjs

cypress.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"baseUrl": "http://localhost:3000",
3+
"video": false
4+
}

cypress/integration/home.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {
2+
buildDataCy,
3+
LEARN_REACT_LINK_CYPRESS,
4+
} from '../../src/config/selectors';
5+
6+
describe('Renders Home', () => {
7+
it('should render the link', () => {
8+
cy.visit('/');
9+
cy.get(buildDataCy(LEARN_REACT_LINK_CYPRESS)).should(
10+
'contain.text',
11+
'Learn React',
12+
);
13+
});
14+
});

cypress/plugins/index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// <reference types="cypress" />
2+
// ***********************************************************
3+
// This example plugins/index.js can be used to load plugins
4+
//
5+
// You can change the location of this file or turn off loading
6+
// the plugins file with the 'pluginsFile' configuration option.
7+
//
8+
// You can read more here:
9+
// https://on.cypress.io/plugins-guide
10+
// ***********************************************************
11+
12+
// This function is called when a project is opened or re-opened (e.g. due to
13+
// the project's config changing)
14+
15+
/**
16+
* @type {Cypress.PluginConfig}
17+
*/
18+
// eslint-disable-next-line no-unused-vars
19+
module.exports = (on, config) => {
20+
// `on` is used to hook into various events Cypress emits
21+
// `config` is the resolved Cypress config
22+
};

cypress/support/commands.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import '@testing-library/cypress/add-commands';
2+
// ***********************************************
3+
// This example commands.js shows you how to
4+
// create various custom commands and overwrite
5+
// existing commands.
6+
//
7+
// For more comprehensive examples of custom
8+
// commands please read more here:
9+
// https://on.cypress.io/custom-commands
10+
// ***********************************************
11+
//
12+
//
13+
// -- This is a parent command --
14+
// Cypress.Commands.add('login', (email, password) => { ... })
15+
//
16+
//
17+
// -- This is a child command --
18+
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
19+
//
20+
//
21+
// -- This is a dual command --
22+
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
23+
//
24+
//
25+
// -- This will overwrite an existing command --
26+
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })

cypress/support/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// ***********************************************************
2+
// This example support/index.js is processed and
3+
// loaded automatically before your test files.
4+
//
5+
// This is a great place to put global configuration and
6+
// behavior that modifies Cypress.
7+
//
8+
// You can change the location of this file or turn off
9+
// automatically serving support files with the
10+
// 'supportFile' configuration option.
11+
//
12+
// You can read more here:
13+
// https://on.cypress.io/configuration
14+
// ***********************************************************
15+
16+
// Import commands.js using ES2015 syntax:
17+
import './commands.js';
18+
19+
// Alternatively you can use CommonJS syntax:
20+
// require('./commands')

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
2-
"name": "graasp-code-review-app-test",
2+
"name": "graasp-app-code-review-rewrite",
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6+
"@testing-library/cypress": "^8.0.2",
67
"@testing-library/jest-dom": "^5.14.1",
78
"@testing-library/react": "^13.0.0",
89
"@testing-library/user-event": "^13.2.1",
@@ -26,7 +27,7 @@
2627
"hooks:install": "husky install",
2728
"hooks:uninstall": "husky uninstall",
2829
"lint": "eslint .",
29-
"test:once": "",
30+
"test:once": "yarn test:ci",
3031
"test:ci": "env-cmd -f ./.env.test cypress run"
3132
},
3233
"browserslist": {
@@ -47,10 +48,12 @@
4748
"@commitlint/config-conventional": "16.0.0",
4849
"@typescript-eslint/eslint-plugin": "^5.22.0",
4950
"@typescript-eslint/parser": "^5.22.0",
51+
"cypress": "^9.6.0",
5052
"eslint": "^8.14.0",
5153
"eslint-config-airbnb": "^19.0.4",
5254
"eslint-config-prettier": "^8.5.0",
5355
"eslint-import-resolver-typescript": "^2.7.1",
56+
"eslint-plugin-cypress": "^2.12.1",
5457
"eslint-plugin-import": "^2.26.0",
5558
"eslint-plugin-jsx-a11y": "^6.5.1",
5659
"eslint-plugin-prettier": "^4.0.0",

0 commit comments

Comments
 (0)