wip: first cypress tests that should work

This commit is contained in:
Vitaly Turovsky 2023-08-15 20:41:15 +03:00
commit 4fe10fc9d0
8 changed files with 79 additions and 5 deletions

9
.gitignore vendored
View file

@ -2,6 +2,13 @@ node_modules/
package-lock.json
.vscode
public
*.log
.env.local
Thumbs.db
build
dist
.DS_Store
.idea/
*.iml
world
out
*.iml

6
cypress.json Normal file
View file

@ -0,0 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/cypress-io/cypress/develop/cli/schema/cypress.schema.json",
"baseUrl": "http://localhost:8080",
"testFiles": "**/*.spec.ts",
"video": false
}

2
cypress/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
screenshots
fixtures

View file

@ -0,0 +1,12 @@
/// <reference types="cypress" />
it('Renders menu (options button)', () => {
// todo use <button match text selectors
cy.visit('/')
window.localStorage.server = 'localhost'
window.localStorage.setItem('renderDistance', '2')
cy.get('#title-screen').find('.menu > pmui-button:nth-child(1)', {includeShadowDom: true,}).click()
// config load TODO remove
// cy.wait(500)
cy.get('#play-screen').find('pmui-button', {includeShadowDom: true,}).contains('Connect', {includeShadowDom: true, }).click()
})

11
cypress/plugins/index.js Normal file
View file

@ -0,0 +1,11 @@
const { cypressEsbuildPreprocessor } = require('cypress-esbuild-preprocessor')
module.exports = on => {
on('file:preprocessor', cypressEsbuildPreprocessor())
on('task', {
log(message) {
console.log(message)
return null
},
})
}

1
cypress/support/index.js Normal file
View file

@ -0,0 +1 @@
Cypress.Commands.overwrite('log', (_subject, message) => cy.task('log', message))

31
minecraft-server.mjs Normal file
View file

@ -0,0 +1,31 @@
//@ts-check
import mcServer from 'flying-squid'
mcServer.createMCServer({
'motd': 'A Minecraft Server \nRunning flying-squid',
'port': 25565,
'max-players': 10,
'online-mode': false,
'logging': true,
'gameMode': 1,
'difficulty': 0,
'worldFolder': 'world',
// todo set sid, disable entities auto-spawn
'generation': {
'name': 'diamond_square',
'options': {
'worldHeight': 80
}
},
'kickTimeout': 10000,
'plugins': {},
'modpe': false,
'view-distance': 10,
'player-list-text': {
'header': 'Flying squid',
'footer': 'Test server'
},
'everybody-op': true,
'max-entities': 100,
'version': '1.16.1'
})

View file

@ -4,12 +4,12 @@
"description": "A minecraft client running in a browser",
"main": "index.js",
"scripts": {
"start": "NODE_OPTIONS=--max-old-space-size=8192 run-p watch prod-start",
"build": "NODE_OPTIONS=--max-old-space-size=8192 node build.js copyFiles && webpack --config webpack.prod.js --progress",
"build-dev": "node build.js copyFilesDev && webpack serve --config webpack.dev.js --progress",
"start": "NODE_OPTIONS=--max-old-space-size=8192 pnpm build-dev",
"watch": "node build.js copyFilesDev && webpack serve --config webpack.dev.js --progress",
"test:cypress": "cypress run",
"test:e2e": "start-test http-get://localhost:8080 test:cypress",
"prod-start": "node server.js",
"build-dev-start": "npm run build-dev && npm run prod-start",
"build-start": "npm run build && npm run prod-start",
"prepublishOnly": "npm run build",
"lint": "standard",
"fix": "standard --fix",
@ -56,7 +56,10 @@
"constants-browserify": "^1.0.0",
"copy-webpack-plugin": "^11.0.0",
"crypto-browserify": "^3.12.0",
"cypress": "^9.5.4",
"cypress-esbuild-preprocessor": "^1.0.2",
"events": "^3.3.0",
"flying-squid": "^1.5.0",
"html-webpack-plugin": "^5.5.3",
"http-browserify": "^1.7.0",
"http-server": "^14.1.1",
@ -66,6 +69,7 @@
"mineflayer": "^4.10.1",
"mineflayer-pathfinder": "^2.4.4",
"mocha": "^10.2.0",
"npm-run-all": "^4.1.5",
"os-browserify": "^0.3.0",
"path-browserify": "^1.0.1",
"prismarine-viewer": "./prismarine-viewer",