-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[chore] Add end-to-end testing with Cypress (#2261)
Can be used to write automated tests which actually utilize a browser. Will produce videos as artifacts. Can also be run locally. Uses an environment variable for logging in.
- Loading branch information
Benedicte Emilie Brækken
committed
Jan 28, 2021
1 parent
686fb62
commit b3db232
Showing
10 changed files
with
152 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: End-to-end tests | ||
|
||
on: [push] | ||
|
||
jobs: | ||
e2e: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [14.x] | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Cache node modules | ||
uses: actions/cache@v2 | ||
env: | ||
# added -vX just to reset the cache, feel free to up it if you need | ||
# to reset the cache again | ||
cache-name: cache-node-modules-v4 | ||
with: | ||
path: ~/.npm | ||
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} | ||
restore-keys: | | ||
${{ runner.os }}-build-${{ env.cache-name }}- | ||
- name: Install npm dependencies | ||
run: npm install | ||
|
||
- name: Run cypress | ||
run: npm run test-e2e | ||
env: | ||
CYPRESS_SANITY_SESSION_TOKEN: ${{ secrets.CYPRESS_SANITY_SESSION_TOKEN }} | ||
|
||
- name: Archive videos | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: videos | ||
path: cypress/videos | ||
# Make sure this step runs even though the test steps fails. | ||
# Otherwise we won't get videos if tests fail. | ||
if: ${{ always() }} | ||
|
||
- name: Archive screenshots | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: screenshots | ||
path: cypress/screenshots | ||
# Make sure this step runs even though the test steps fails. | ||
# Otherwise we won't get videos if tests fail. | ||
if: ${{ always() }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
extends: ['plugin:cypress/recommended'], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/videos/ | ||
/screenshots/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"baseUrl": "http://localhost:3333" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "Using fixtures to represent data", | ||
"email": "hello@cypress.io", | ||
"body": "Fixtures are a great way to mock data for responses to routes" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
describe('BooleanInput', () => { | ||
it('should have a height of 35px if no description', () => { | ||
cy.visit('/test/desk/booleansTest;bd99e58a-845f-4d52-b54a-56a9b7af3be1') | ||
|
||
cy.getField('switchIndeterminate2').invoke('outerHeight').should('be.eq', 35) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/// <reference types="cypress" /> | ||
// *********************************************************** | ||
// This example plugins/index.js can be used to load plugins | ||
// | ||
// You can change the location of this file or turn off loading | ||
// the plugins file with the 'pluginsFile' configuration option. | ||
// | ||
// You can read more here: | ||
// https://on.cypress.io/plugins-guide | ||
// *********************************************************** | ||
|
||
// This function is called when a project is opened or re-opened (e.g. due to | ||
// the project's config changing) | ||
|
||
/** | ||
* @type {Cypress.PluginConfig} | ||
*/ | ||
module.exports = (on, config) => { | ||
// `on` is used to hook into various events Cypress emits | ||
// `config` is the resolved Cypress config | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Cypress.Commands.add('login', (sanitySessionToken) => { | ||
const token = sanitySessionToken ? sanitySessionToken : Cypress.env('SANITY_SESSION_TOKEN') | ||
|
||
cy.intercept({url: 'v1/users/me', method: 'GET'}).as('getUser') | ||
|
||
return cy.visit('/').then(() => { | ||
cy.wait('@getUser').then((interception) => { | ||
const domain = new URL(interception.response.url).hostname | ||
|
||
cy.setCookie('sanitySession', token, { | ||
secure: true, | ||
httpOnly: true, | ||
sameSite: 'None', | ||
domain: `.${domain}`, | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
Cypress.Commands.add('getField', (fieldName) => { | ||
// TODO(@benedicteb, 2021-01-26) Add <data-qa=..." /> or something to html to make select super robust | ||
return cy.get(`[data-focus-path=${fieldName}]`) | ||
}) | ||
|
||
Cypress.Commands.add('getFieldInput', (fieldName) => { | ||
return cy.getField(fieldName).within(($field) => { | ||
return cy.get('input') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// *********************************************************** | ||
// This example support/index.js is processed and | ||
// loaded automatically before your test files. | ||
// | ||
// This is a great place to put global configuration and | ||
// behavior that modifies Cypress. | ||
// | ||
// You can change the location of this file or turn off | ||
// automatically serving support files with the | ||
// 'supportFile' configuration option. | ||
// | ||
// You can read more here: | ||
// https://on.cypress.io/configuration | ||
// *********************************************************** | ||
|
||
// noinspection ES6UnusedImports | ||
import commands from './commands' | ||
|
||
// Alternatively you can use CommonJS syntax: | ||
// require('./commands') | ||
before(() => { | ||
cy.login() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
b3db232
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: