Merge pull request #31 from linux-odyssey/feat-tests

Feat tests
This commit is contained in:
Annie Huang authored and GitHub committed 2023-09-28 14:55:03 +08:00
commit b881f37b7b
12 files changed
+948 -24

No files matched your search

+2
View File
@@ -4,10 +4,12 @@ module.exports = {
node: true,
jest: true,
},
plugins: ['cypress'],
extends: [
'plugin:vue/vue3-essential',
'airbnb-base',
'plugin:prettier/recommended', // We added this
'plugin:cypress/recommended',
],
parserOptions: {
// parser: 'babel-eslint',
+22 -2
View File
@@ -24,8 +24,28 @@ jobs:
- name: Test
run: yarn test
e2e:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Build Test Environment, Stage 1
run: docker-compose -f docker-compose.testing.yml build base backend app-test
- name: Build Test Environment, Stage 2
run: docker-compose -f docker-compose.testing.yml build helloworld
- name: Run Cypress Tests
run: docker-compose -f docker-compose.testing.yml run cypress
- name: Tear Down Test Environment
run: docker-compose -f docker-compose.testing.yml down
build-and-push:
needs: ci
needs:
- ci
- e2e
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
@@ -60,7 +80,7 @@ jobs:
with:
context: .
file: ./quests/Dockerfile
push: false
push: true
tags: docker.io/${{ secrets.DOCKERHUB_USERNAME }}/linux-odyssey:base
- name: Build quest helloworld
+14
View File
@@ -19,6 +19,20 @@ Run everything (frontend, backend, db, swagger, quests):
docker compose build
docker compose up -d
## Testing
Run Cypress locally, using the current development containers:
docker compose up -d
yarn test:e2e
Run Cypress in container, create brand-new containers along with it:
docker compose -f docker-compose.testing.yml run cypress
# tearing off the containers
docker compose -f docker-compose.testing.yml down
### Deployment
docker compose -f docker-compose.prod.yml build
+71
View File
@@ -0,0 +1,71 @@
version: '3'
services:
cypress:
image: cypress/included
networks:
- internal
volumes:
- ./tests:/e2e
working_dir: /e2e
environment:
- BASE_URL=http://app-test
depends_on:
- app-test
app-test:
image: lancatlin/linux-odyssey:app
build:
context: .
dockerfile: app/Dockerfile
networks:
internal:
ports:
- 5173:80
depends_on:
- backend
backend:
image: lancatlin/linux-odyssey:backend
build:
context: .
dockerfile: server/Dockerfile
depends_on:
- db-test
networks:
- internal
- players
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
- MONGO_URL=mongodb://user:user-password@db-test:27017/odyssey-test
- DOCKER_NETWORK=linux-odyssey-players
db-test:
image: mongo
networks:
- internal
volumes:
- ./mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
environment:
- MONGO_INITDB_ROOT_USERNAME=admin
- MONGO_INITDB_ROOT_PASSWORD=admin-password
- MONGO_USER=user
- MONGO_PASS=user-password
- MONGO_DB=odyssey-test
base:
image: lancatlin/linux-odyssey:base
build:
context: .
dockerfile: ./quests/Dockerfile
helloworld:
image: lancatlin/linux-odyssey:helloworld
build:
context: .
dockerfile: quests/helloworld/Dockerfile
networks:
internal:
players:
name: linux-odyssey-players
+4 -1
View File
@@ -8,7 +8,8 @@
"workspaces": [
"app",
"server",
"packages/*"
"packages/*",
"tests"
],
"scripts": {
"app": "yarn workspace app dev",
@@ -19,6 +20,7 @@
"lint": "eslint --ext .js,.vue .",
"format": "prettier --ignore-path .prettierignore --write app server",
"test": "yarn node --experimental-vm-modules $(yarn bin jest)",
"test:e2e": "yarn workspace tests test",
"clean": "yarn workspace server clean"
},
"devDependencies": {
@@ -26,6 +28,7 @@
"eslint": "^8.44.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-cypress": "^2.15.1",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-vue": "^9.15.1",
+12
View File
@@ -0,0 +1,12 @@
const { defineConfig } = require('cypress')
const process = require('process')
const getConfig = (key, defaultValue) => {
return process.env[key] || defaultValue
}
module.exports = defineConfig({
e2e: {
baseUrl: getConfig('BASE_URL', 'http://localhost:5173'),
},
})
+11
View File
@@ -0,0 +1,11 @@
/// <reference types="cypress" />
describe('example helloworld app', () => {
beforeEach(() => {
cy.visit('/')
})
it('open login page', () => {
cy.get('#username').type('alex')
cy.get('#password').type('123456{enter}')
})
})
+5
View File
@@ -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"
}
+25
View File
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
+20
View File
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.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
// ***********************************************************
// Import commands.js using ES2015 syntax:
import './commands'
// Alternatively you can use CommonJS syntax:
// require('./commands')
+13
View File
@@ -0,0 +1,13 @@
{
"name": "tests",
"version": "1.0.0",
"private": true,
"main": "index.js",
"license": "MIT",
"scripts": {
"test": "cypress run"
},
"dependencies": {
"cypress": "^13.2.0"
}
}
+749 -21
View File
File diff suppressed because it is too large. Load diff