Skip to content

Commit 1fec3ef

Browse files
committed
Draft implementation of cypress with mocks server
1 parent 366a5c5 commit 1fec3ef

7 files changed

Lines changed: 2751 additions & 30 deletions

File tree

.github/workflows/ci.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,24 @@ jobs:
5252
command: npm run test:frontend:gui:cloud
5353
env:
5454
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
55+
gui-tests-mocks-server:
56+
needs: eslint
57+
runs-on: ubuntu-latest
58+
steps:
59+
- name: Checkout
60+
uses: actions/checkout@v4
61+
- name: Install frontend modules
62+
uses: cypress-io/github-action@v6
63+
with:
64+
install-command: npm run install:frontend
65+
runTests: false
66+
- name: Run frontend GUI tests with mocks server 🧪
67+
uses: cypress-io/github-action@v6
68+
with:
69+
start: npm run mocks:ci, npm run start:frontend
70+
command: npm run test:frontend:gui:mocksserver:cloud
71+
env:
72+
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
5573
api-tests:
5674
needs: eslint
5775
runs-on: ubuntu-latest

cypress/e2e/gui/mocksServer.cy.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
describe('EngageSphere - Mocks Server', () => {
2+
describe('when there are five customers', () => {
3+
before(() => {
4+
cy.mocksUseRouteVariant('get-customers:five-customers')
5+
cy.visit('/')
6+
})
7+
8+
it('displays five customers', () => {
9+
cy.get('table tbody tr').should('have.length', 5)
10+
})
11+
})
12+
13+
describe('when there are no customers', () => {
14+
before(() => {
15+
cy.mocksUseRouteVariant('get-customers:no-customers')
16+
cy.visit('/')
17+
})
18+
19+
it('displays five customers', () => {
20+
cy.get('[alt="image of an empty box"]').should('be.visible')
21+
cy.contains('span', 'No customers available.').should('be.visible')
22+
})
23+
})
24+
})

cypress/support/e2e.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
import 'cypress-axe'
2+
3+
import { register } from '@mocks-server/cypress-commands'
4+
5+
register()

mocks.config.js

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// For a detailed explanation regarding each configuration property, visit:
2+
// https://www.mocks-server.org/docs/configuration/how-to-change-settings
3+
// https://www.mocks-server.org/docs/configuration/options
4+
5+
module.exports = {
6+
// Log level. Can be one of silly, debug, verbose, info, warn or error
7+
//log: "info",
8+
config: {
9+
// Allow unknown arguments
10+
//allowUnknownArguments: false,
11+
},
12+
plugins: {
13+
// Plugins to be registered
14+
//register: [],
15+
proxyRoutesHandler: {
16+
},
17+
adminApi: {
18+
// Port number for the admin API server to be listening at
19+
//port: 3110,
20+
// Host for the admin API server
21+
//host: "0.0.0.0",
22+
https: {
23+
// Use https protocol or not
24+
//enabled: false,
25+
// Path to a TLS/SSL certificate
26+
//cert: undefined,
27+
// Path to the certificate private key
28+
//key: undefined,
29+
},
30+
},
31+
inquirerCli: {
32+
// Start interactive CLI or not
33+
//enabled: true,
34+
// Render emojis or not
35+
//emojis: true,
36+
},
37+
openapi: {
38+
collection: {
39+
// Name for the collection created from OpenAPI definitions
40+
//id: "openapi",
41+
// Name of the collection to extend from
42+
//from: undefined,
43+
},
44+
},
45+
},
46+
mock: {
47+
routes: {
48+
// Global delay to apply to routes
49+
//delay: 0,
50+
},
51+
collections: {
52+
// Selected collection
53+
//selected: "base",
54+
},
55+
},
56+
server: {
57+
// Port number for the server to be listening at
58+
// port: 3001,
59+
// Host for the server
60+
//host: "0.0.0.0",
61+
cors: {
62+
// Use CORS middleware or not
63+
//enabled: true,
64+
// Options for the CORS middleware. Further information at https://github.com/expressjs/cors#configuration-options
65+
//options: {"preflightContinue":false},
66+
},
67+
jsonBodyParser: {
68+
// Use json body-parser middleware or not
69+
//enabled: true,
70+
// Options for the json body-parser middleware. Further information at https://github.com/expressjs/body-parser
71+
//options: {},
72+
},
73+
urlEncodedBodyParser: {
74+
// Use urlencoded body-parser middleware or not
75+
//enabled: true,
76+
// Options for the urlencoded body-parser middleware. Further information at https://github.com/expressjs/body-parser
77+
//options: {"extended":true},
78+
},
79+
https: {
80+
// Use https protocol or not
81+
//enabled: false,
82+
// Path to a TLS/SSL certificate
83+
//cert: undefined,
84+
// Path to the certificate private key
85+
//key: undefined,
86+
},
87+
},
88+
files: {
89+
// Allows to disable files load
90+
//enabled: true,
91+
// Define folder from where to load collections and routes
92+
//path: "mocks",
93+
// Enable/disable files watcher
94+
//watch: true,
95+
babelRegister: {
96+
// Load @babel/register
97+
//enabled: false,
98+
// Options for @babel/register
99+
//options: {},
100+
},
101+
},
102+
variantHandlers: {
103+
// Variant Handlers to be registered
104+
//register: [],
105+
},
106+
}

mocks/routes/customers.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const response = require('../../cypress/fixtures/customers.json')
2+
3+
module.exports = [
4+
{
5+
id: 'get-customers', // id of the route
6+
url: '*/customers*', // url in path-to-regexp format
7+
method: 'GET', // HTTP method
8+
variants: [
9+
{
10+
id: 'five-customers', // id of the variant
11+
type: 'json', // variant type
12+
options: {
13+
status: 200,
14+
body: response
15+
}
16+
},
17+
{
18+
id: 'no-customers',
19+
type: 'text',
20+
options: {
21+
status: 200,
22+
body: ''
23+
}
24+
},
25+
]
26+
}
27+
]

0 commit comments

Comments
 (0)