Skip to content

Commit

Permalink
chore(test): test Cypress component tests in main
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-codes committed Jun 9, 2024
1 parent 3534bda commit d56a148
Show file tree
Hide file tree
Showing 11 changed files with 8,479 additions and 290 deletions.
17 changes: 10 additions & 7 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ mosquitto-clients

# MongoDB
RUN apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
dirmngr \
gnupg \
gnupg2 \
dirmngr \
apt-transport-https \
software-properties-common \
ca-certificates
iputils-ping \
net-tools \
software-properties-common
RUN curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | apt-key add -
RUN echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/debian bullseye/mongodb-org/7.0 main" | tee /etc/apt/sources.list.d/mongodb-org-7.0.list
RUN apt-get update
Expand All @@ -28,13 +30,14 @@ RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E03280
RUN echo "deb https://download.mono-project.com/repo/debian stable-buster main" > /etc/apt/sources.list.d/mono-official-stable.list
RUN apt-get update -y
RUN apt-get install -y \
libgtk2.0-0 \
libgtk-3-0 \
libasound2 \
libgbm-dev \
libgconf-2-4 \
libgtk-3-0 \
libgtk2.0-0 \
libnotify-dev \
libnss3 \
libxss1 \
libasound2 \
libxtst6 \
mono-complete \
xauth \
Expand Down
7 changes: 4 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"version": "7.0.403"
},
"ghcr.io/devcontainers/features/node:1": {
"version": "20.9.0"
"version": "20.9.0",
"nodeGypDependencies": true
},
"ghcr.io/devcontainers/features/powershell:1": {}
},
Expand Down Expand Up @@ -70,9 +71,9 @@
"3001:3001"
],
"containerEnv": {
"DISPLAY": "localhost:10.0"
"DISPLAY": "${localEnv:DISPLAY}"
},
"remoteEnv": {
"DISPLAY": "localhost:10.0"
"DISPLAY": "${localEnv:DISPLAY}"
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ _packaged
*.user
*.env
!local.env
.test-runs

apps/playnite-web/.cache
apps/playnite-web/build
Expand Down
4,870 changes: 4,768 additions & 102 deletions .pnp.cjs

Large diffs are not rendered by default.

Binary file modified .yarn/install-state.gz
Binary file not shown.
88 changes: 88 additions & 0 deletions apps/playnite-web/cypress.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import babelPluginTsTransform from '@babel/plugin-transform-typescript'
import babelPresetEnv from '@babel/preset-env'
import babelPresetReact from '@babel/preset-react'
import { defineConfig } from 'cypress'
import fs from 'fs'

const config = {
chromeWebSecurity: false,
viewportWidth: 1920,
viewportHeight: 1080,
reporter: require.resolve('mocha-junit-reporter'),
reporterOptions: {
mochaFile: '.test-runs/functional-component-tests-[hash].xml',
},
component: {
specPattern: '**/__component_tests__/**/*.test.tsx',
excludeSpecPattern: [],
devServer: {
framework: 'react',
bundler: 'webpack',
webpackConfig: async () => {
const config = {
mode: 'development',
devtool: 'source-map',
module: {
rules: [
{
test: /\.?tsx?$/,
use: {
loader: 'babel-loader',
options: {
presets: [babelPresetEnv, babelPresetReact],
plugins: [babelPluginTsTransform],
},
},
},
],
},
plugins: [
// new webpack.ProvidePlugin({
// React: 'react',
// }),
],
}
return config
},
},
video: process.env.CI === 'true',
videoCompression: 32,
setupNodeEvents: (on, config) => {
const { viewportWidth, viewportHeight } = config
on('before:browser:launch', (browser, launchOptions) => {
switch (browser?.name) {
case 'chrome':
case 'edge':
launchOptions.args.push(
`--window-size=${viewportWidth},${viewportHeight}`,
)
launchOptions.args.push('--force-device-scale-factor=1')
break
case 'electron':
default:
launchOptions.preferences.width = viewportWidth
launchOptions.preferences.height = viewportHeight
}

return launchOptions
})

on('after:spec', (spec, results) => {
if (process.env.CI === 'false') {
return
}
if (results && results.video) {
// Do we have failures for any retry attempts?
const failures = results.tests.some((test) =>
test.attempts.some((attempt) => attempt.state === 'failed'),
)
if (!failures) {
fs.unlinkSync(results.video)
}
}
})
},
},
}

export default defineConfig(config)
12 changes: 12 additions & 0 deletions apps/playnite-web/cypress/support/component-index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<title>Components App</title>
</head>
<body>
<div data-cy-root></div>
</body>
</html>
13 changes: 13 additions & 0 deletions apps/playnite-web/cypress/support/component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'cypress-plugin-tab'
import { mount } from 'cypress/react'

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Cypress {
interface Chainable {
mount: typeof mount
}
}
}

Cypress.Commands.add('mount', mount)
23 changes: 23 additions & 0 deletions apps/playnite-web/cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"esModuleInterop": true,
"allowJs": true,
"baseUrl": ".",
"types": [
"cypress"
],
"module": "ESNext"
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"*.tsx",
"*.ts",
"cypress.config.mjs",
"cypress/**/*.js",
"cypress/**/*.ts"
],
"exclude": [
"**/__tests__/*.*"
]
}
15 changes: 13 additions & 2 deletions apps/playnite-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,31 @@
},
"devDependencies": {
"@babel/core": "^7.23.6",
"@babel/plugin-transform-typescript": "^7.24.7",
"@babel/preset-env": "^7.24.7",
"@babel/preset-react": "^7.23.6",
"@remix-pwa/dev": "2.0.31",
"@remix-pwa/worker-runtime": "^2.0.8",
"@remix-run/dev": "^2.4.0",
"@types/cypress": "^1.1.3",
"@types/express": "^4",
"@types/lodash": "^4.17.1",
"@types/node": "^20.14.0",
"@types/react": "^18",
"@types/react-dom": "^18",
"@types/shelljs": "^0.8.15",
"@types/styled-components": "^5.1.34",
"babel-loader": "^9.1.3",
"babel-plugin-direct-import": "^1.0.0",
"concurrently": "^8.2.2",
"cross-env": "^7.0.3",
"cypress": "^13.6.1",
"cypress": "^13.11.0",
"cypress-plugin-tab": "^1.0.5",
"esbuild": "^0.21.4",
"glob": "^10.3.10",
"html-webpack-plugin": "^5.6.0",
"mocha": "10.4.0",
"mocha-junit-reporter": "2.2.1",
"npm-run-all": "^4.1.5",
"nx": "19.1.1",
"prettier": "^3.1.1",
Expand All @@ -72,7 +81,9 @@
"ts-jest": "^29.0.5",
"typescript": "^5.3.2",
"typescript-remix-routes-plugin": "^1.0.1",
"versioning": "workspace:*"
"versioning": "workspace:*",
"webpack": "^5.91.0",
"webpack-dev-server": "^5.0.4"
},
"scripts": {
"postinstall": "yarn remix-esbuild-override"
Expand Down
Loading

0 comments on commit d56a148

Please sign in to comment.