Skip to content

Commit

Permalink
protocol & errors improvements & cleanup (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy authored Sep 25, 2023
2 parents ee8380b + 3ca17f1 commit 358203f
Show file tree
Hide file tree
Showing 25 changed files with 557 additions and 400 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Install pnpm
run: npm i -g pnpm
- run: pnpm install
- run: pnpm build
- run: pnpm check-build
- run: nohup pnpm prod-start &
- run: nohup node cypress/minecraft-server.mjs &
- uses: cypress-io/github-action@v5
Expand Down
Binary file modified cypress/integration/__image_snapshots__/superflat-world #0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 46 additions & 26 deletions cypress/integration/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,78 @@
/// <reference types="cypress" />
import type { AppOptions } from '../../src/optionsStorage'

const setLocalStorageSettings = () => {
const cleanVisit = () => {
window.localStorage.clear()
visit()
}

const visit = (url = '/') => {
window.localStorage.cypress = 'true'
window.localStorage.server = 'localhost'
cy.visit(url)
}

// todo use ssl

const compareRenderedFlatWorld = () => {
// wait for render
// cy.wait(6000)
// cy.get('body').toMatchImageSnapshot({
// name: 'superflat-world',
// })
}

const testWorldLoad = () => {
cy.document().then({ timeout: 20_000, }, doc => {
return new Cypress.Promise(resolve => {
doc.addEventListener('cypress-world-ready', resolve)
})
}).then(() => {
compareRenderedFlatWorld()
})
}

const setOptions = (options: Partial<AppOptions>) => {
cy.window().then(win => {
Object.assign(win['options'], options)
})
}

it('Loads & renders singleplayer', () => {
cy.visit('/')
window.localStorage.clear()
window.localStorage.setItem('options', JSON.stringify({
cleanVisit()
setOptions({
localServerOptions: {
generation: {
name: 'superflat',
options: { seed: 250869072 }
}
},
},
renderDistance: 2
}))
setLocalStorageSettings()
})
cy.get('#title-screen').find('[data-test-id="singleplayer-button"]', { includeShadowDom: true, }).click()
// todo implement load event
cy.wait(12000)
testWorldLoad()
})

// even on local testing indeed it doesn't work sometimes, but sometimes it does
it.skip('Joins to server', () => {
cy.visit('/')
setLocalStorageSettings()
window.localStorage.version = ''
it('Joins to server', () => {
// visit('/?version=1.16.1')
window.localStorage.version = '1.16.1'
visit()
// todo replace with data-test
cy.get('#title-screen').find('[data-test-id="connect-screen-button"]', { includeShadowDom: true, }).click()
cy.get('input#serverip', { includeShadowDom: true, }).clear().focus().type('localhost')
cy.get('[data-test-id="connect-to-server"]', { includeShadowDom: true, }).click()
// todo implement load event
cy.wait(16000)
testWorldLoad()
})

it('Loads & renders zip world', () => {
cy.visit('/')
setLocalStorageSettings()
cleanVisit()
cy.get('#title-screen').find('[data-test-id="select-file-folder"]', { includeShadowDom: true, }).click({ shiftKey: true })
cy.get('input[type="file"]').selectFile('cypress/superflat.zip', { force: true })
// todo implement load event
cy.wait(10000)
testWorldLoad()
})

it.skip('Performance test', () => {
cy.visit('/')
window.localStorage.cypress = 'true'
window.localStorage.setItem('renderDistance', '6')
cy.get('#title-screen').find('.menu > div:nth-child(2) > pmui-button:nth-child(1)', { includeShadowDom: true, }).selectFile('worlds')
// -2 85 24
// select that world
// from -2 85 24
// await bot.loadPlugin(pathfinder.pathfinder)
// bot.pathfinder.goto(new pathfinder.goals.GoalXZ(28, -28))
})
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"scripts": {
"start": "node scripts/build.js copyFilesDev && node scripts/prepareData.mjs && node esbuild.mjs --watch",
"start-watch-script": "nodemon -w esbuild.mjs esbuild.mjs",
"build": "node scripts/build.js copyFiles && node scripts/prepareData.mjs && node esbuild.mjs --minify --prod",
"build": "node scripts/build.js copyFiles && node scripts/prepareData.mjs -f && node esbuild.mjs --minify --prod",
"check-build": "tsc && pnpm build",
"watch": "node scripts/build.js copyFilesDev && webpack serve --config webpack.dev.js --progress",
"test:cypress": "cypress run",
"test:e2e": "start-test http-get://localhost:8080 test:cypress",
Expand All @@ -31,9 +32,10 @@
"browserfs": "github:zardoy/browserfs#build",
"compression": "^1.7.4",
"cypress-plugin-snapshots": "^1.4.4",
"debug": "^4.3.4",
"diamond-square": "^1.2.0",
"eruda": "^3.0.1",
"esbuild": "^0.19.2",
"esbuild": "^0.19.3",
"esbuild-loader": "^4.0.0",
"esbuild-plugin-polyfill-node": "^0.3.0",
"express": "^4.18.2",
Expand All @@ -42,6 +44,7 @@
"iconify-icon": "^1.0.8",
"jszip": "^3.10.1",
"lit": "^2.8.0",
"lodash": "^4.17.21",
"minecraft-data": "^3.0.0",
"net-browserify": "github:PrismarineJS/net-browserify",
"peerjs": "^1.5.0",
Expand Down Expand Up @@ -90,6 +93,7 @@
"style-loader": "^3.3.3",
"three": "0.128.0",
"timers-browserify": "^2.0.12",
"typescript": "^5.2.2",
"url-loader": "^4.1.1",
"use-typed-event-listener": "^4.0.2",
"vite": "^4.4.9",
Expand Down
Loading

0 comments on commit 358203f

Please sign in to comment.