Skip to content

Commit 4568f64

Browse files
committed
Add client e2e tests with cypress
1 parent bc1ad9c commit 4568f64

File tree

14 files changed

+2951
-647
lines changed

14 files changed

+2951
-647
lines changed

.semaphore/semaphore.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ blocks:
9898
- npm --version
9999
- sem-service start postgres
100100
jobs:
101+
- name: Client Tests
102+
commands:
103+
- cd src/client
104+
- cache restore client-node-modules-$SEMAPHORE_GIT_BRANCH-$(checksum package-lock.json),client-node-modules-$SEMAPHORE_GIT_BRANCH,client-node-modules-master
105+
- npm run test:e2e
101106
- name: Server Tests
102107
commands:
103108
- cd src/server
@@ -124,10 +129,10 @@ blocks:
124129
- cd src/client
125130
- cache restore client-node-modules-$SEMAPHORE_GIT_BRANCH-$(checksum package-lock.json),client-node-modules-$SEMAPHORE_GIT_BRANCH,client-node-modules-master
126131
- npm run build
127-
- cache restore client-dist-$SEMAPHORE_GIT_BRANCH-$(checksum package-lock.json),client-dist-$SEMAPHORE_GIT_BRANCH,client-dist-master
132+
- cache store client-dist-$SEMAPHORE_GIT_BRANCH-$(checksum package-lock.json),client-dist-$SEMAPHORE_GIT_BRANCH,client-dist-master
128133
- name: Build Server
129134
commands:
130135
- cd src/server
131136
- cache restore server-node-modules-$SEMAPHORE_GIT_BRANCH-$(checksum package-lock.json),server-node-modules-$SEMAPHORE_GIT_BRANCH,server-node-modules-master
132137
- npm run build
133-
- cache restore server-dist-$SEMAPHORE_GIT_BRANCH-$(checksum package-lock.json),server-dist-$SEMAPHORE_GIT_BRANCH,server-dist-master
138+
- cache store server-dist-$SEMAPHORE_GIT_BRANCH-$(checksum package-lock.json),server-dist-$SEMAPHORE_GIT_BRANCH,server-dist-master

src/client/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@
2121
npm-debug.log*
2222
yarn-debug.log*
2323
yarn-error.log*
24+
25+
cypress/integration/examples
26+
cypress/videos

src/client/cypress.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

src/client/cypress/config/ci.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"baseUrl": "http://localhost:3030",
3+
"env": {
4+
"env": "ci"
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"baseUrl": "http://localhost:3030",
3+
"env": {
4+
"env": "development"
5+
}
6+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Using fixtures to represent data",
3+
"email": "[email protected]",
4+
"body": "Fixtures are a great way to mock data for responses to routes"
5+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference types="Cypress" />
2+
3+
context('Home Page', () => {
4+
beforeEach(() => {
5+
cy.visit('/');
6+
});
7+
8+
it('cy.get() - query DOM elements', () => {
9+
cy.get('h1').should('contain', 'Home');
10+
});
11+
});

src/client/cypress/plugins/index.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// ***********************************************************
2+
// This example plugins/index.js can be used to load plugins
3+
//
4+
// You can change the location of this file or turn off loading
5+
// the plugins file with the 'pluginsFile' configuration option.
6+
//
7+
// You can read more here:
8+
// https://on.cypress.io/plugins-guide
9+
// ***********************************************************
10+
11+
// This function is called when a project is opened or re-opened (e.g. due to
12+
// the project's config changing)
13+
const wp = require('@cypress/webpack-preprocessor');
14+
const fs = require('fs-extra')
15+
const path = require('path')
16+
17+
function getConfigurationByFile (file) {
18+
const pathToConfigFile = path.resolve(__dirname, '..', 'config', `${file}.json`)
19+
20+
return fs.readJson(pathToConfigFile)
21+
}
22+
23+
module.exports = (on, config) => {
24+
const options = {
25+
webpackOptions: {
26+
resolve: {
27+
extensions: [".ts", ".tsx", ".js"]
28+
},
29+
module: {
30+
rules: [
31+
{
32+
test: /\.tsx?$/,
33+
loader: "ts-loader",
34+
options: { transpileOnly: true }
35+
}
36+
]
37+
}
38+
},
39+
}
40+
on('file:preprocessor', wp(options));
41+
42+
const file = config.env.configFile || 'development'
43+
44+
return getConfigurationByFile(file);
45+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// ***********************************************
2+
// This example commands.js shows you how to
3+
// create various custom commands and overwrite
4+
// existing commands.
5+
//
6+
// For more comprehensive examples of custom
7+
// commands please read more here:
8+
// https://on.cypress.io/custom-commands
9+
// ***********************************************
10+
//
11+
//
12+
// -- This is a parent command --
13+
// Cypress.Commands.add("login", (email, password) => { ... })
14+
//
15+
//
16+
// -- This is a child command --
17+
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
18+
//
19+
//
20+
// -- This is a dual command --
21+
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
22+
//
23+
//
24+
// -- This is will overwrite an existing command --
25+
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })

src/client/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'
18+
19+
// Alternatively you can use CommonJS syntax:
20+
// require('./commands')

0 commit comments

Comments
 (0)