diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 867fefba..cfb51d75 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,5 +12,12 @@ jobs: run: npm i -g pnpm - run: pnpm install - run: pnpm build - # todo use nohup and official action? - # - run: pnpm prod-start & pnpm test:cypress + - uses: cypress-io/github-action@v5 + with: + start: pnpm prod-start + - uses: actions/upload-artifact@v3 + if: failure() + with: + name: cypress-images + path: cypress/integration/__image_snapshots__/ + if-no-files-found: ignore diff --git a/cypress/integration/__image_snapshots__/Loads & renders singleplayer #0.png b/cypress/integration/__image_snapshots__/Loads & renders singleplayer #0.png new file mode 100644 index 00000000..ea42d86f Binary files /dev/null and b/cypress/integration/__image_snapshots__/Loads & renders singleplayer #0.png differ diff --git a/cypress/integration/__image_snapshots__/Renders menu (options button) #0.png b/cypress/integration/__image_snapshots__/Renders menu (options button) #0.png deleted file mode 100644 index 93a6c53c..00000000 Binary files a/cypress/integration/__image_snapshots__/Renders menu (options button) #0.png and /dev/null differ diff --git a/cypress/integration/index.spec.ts b/cypress/integration/index.spec.ts index 27a92da7..41f8e96d 100644 --- a/cypress/integration/index.spec.ts +++ b/cypress/integration/index.spec.ts @@ -1,11 +1,10 @@ /// -it('Renders menu (options button)', () => { +it('Loads & renders singleplayer', () => { // todo use { - win['cypress'] = true - win['hideStats']() }) window.localStorage.server = 'localhost' window.localStorage.setItem('renderDistance', '2') @@ -15,7 +14,8 @@ it('Renders menu (options button)', () => { options: { seed: 250869072 } } })) - cy.get('#title-screen').find('.menu > pmui-button:nth-child(2)', { includeShadowDom: true, }).click() + // todo replace with data-test + cy.get('#title-screen').find('.menu > div:nth-child(2) > pmui-button:nth-child(1)', { includeShadowDom: true, }).click() // todo implement load event cy.wait(6000) //@ts-ignore diff --git a/package.json b/package.json index 84248950..b0167853 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,7 @@ "test:cypress": "cypress run", "test:e2e": "start-test http-get://localhost:8080 test:cypress", "prod-start": "node server.js", - "prepublishOnly": "npm run build", - "test": "npm run lint && mocha" + "prepublishOnly": "npm run build" }, "keywords": [ "prismarine", @@ -71,7 +70,6 @@ "memfs": "^3.5.3", "mineflayer": "^4.11.0", "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", diff --git a/src/chat.js b/src/chat.js index 2b388609..176cedcc 100644 --- a/src/chat.js +++ b/src/chat.js @@ -4,6 +4,7 @@ const { isMobile } = require('./menus/components/common') const { activeModalStack, hideCurrentModal, showModal } = require('./globalState') import { repeat } from 'lit/directives/repeat.js' import { classMap } from 'lit/directives/class-map.js' +import { isCypress } from './utils' const styles = { black: 'color:#000000', @@ -400,13 +401,12 @@ class ChatBox extends LitElement { } render () { - // todo just to hide player joined at random timings - if (window.cypress) return html`` return html` - ${repeat(this.messages, (m) => m.id, (m) => this.renderMessage(m))} + + ${repeat(isCypress() ? [] : this.messages, (m) => m.id, (m) => this.renderMessage(m))} diff --git a/src/index.js b/src/index.js index 2696a250..20becd66 100644 --- a/src/index.js +++ b/src/index.js @@ -55,7 +55,7 @@ const Cursor = require('./cursor') global.THREE = require('three') const { initVR } = require('./vr') const { activeModalStack, showModal, hideModal, hideCurrentModal, activeModalStacks, replaceActiveModalStack, isGameActive, miscUiState, gameAdditionalState } = require('./globalState') -const { pointerLock, goFullscreen, toNumber } = require('./utils') +const { pointerLock, goFullscreen, toNumber, isCypress } = require('./utils') const { notification } = require('./menus/notification') const { removePanorama, addPanoramaCubeMap, initPanoramaOptions } = require('./panorama') const { startLocalServer } = require('./createLocalServer') @@ -65,7 +65,7 @@ const { default: updateTime } = require('./updateTime') const { options } = require('./optionsStorage') const { subscribeKey } = require('valtio/utils') -if ('serviceWorker' in navigator) { +if ('serviceWorker' in navigator && !isCypress()) { window.addEventListener('load', () => { navigator.serviceWorker.register('./service-worker.js').then(registration => { console.log('SW registered: ', registration) @@ -87,11 +87,10 @@ document.body.appendChild(stats.dom) stats2.dom.style.left = '80px' document.body.appendChild(stats2.dom) -window.hideStats = () => { +if (localStorage.hideStats || isCypress()) { stats.dom.style.display = 'none' stats2.dom.style.display = 'none' } -if (localStorage.hideStats) window.hideStats() // const debugPitch = document.createElement('span') // debugPitch.style.cssText = ` diff --git a/src/utils.js b/src/utils.js index 07dc1f91..cf129d24 100644 --- a/src/utils.js +++ b/src/utils.js @@ -112,3 +112,7 @@ export const getGamemodeNumber = (bot) => { default: return -1 } } + +export const isCypress = () => { + return localStorage.cypress === 'true' +}