From c29adeda58d03a5cdad2c93a9fe35c844f979bbe Mon Sep 17 00:00:00 2001 From: HexaField Date: Sat, 21 Sep 2024 08:29:00 +1000 Subject: [PATCH 1/7] type module vite node test --- .mocharc.js | 21 --------------------- package.json | 1 + tests/mocha.env.js | 11 ----------- tsconfig.json | 2 +- 4 files changed, 2 insertions(+), 33 deletions(-) delete mode 100644 .mocharc.js delete mode 100644 tests/mocha.env.js diff --git a/.mocharc.js b/.mocharc.js deleted file mode 100644 index 1d919ee..0000000 --- a/.mocharc.js +++ /dev/null @@ -1,21 +0,0 @@ -module.exports = { - failZero: false, - parallel: false, - require: [ - 'tests/mocha.env', // init env here - 'jsdom-global/register' - ], - spec: [ - './**/*.test.ts', - './**/*.test.tsx' - ], - extension: [ - 'ts', - 'tsx' - ], - bail: true, - exit: true, - recursive: true, - jobs: '1', - timeout: '60000' -}; diff --git a/package.json b/package.json index 27055ad..8bf130f 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "name": "@ir-engine/ir-bot", "version": "0.5.8", + "type": "module", "description": "A test bot using puppeteer", "repository": { "type": "git", diff --git a/tests/mocha.env.js b/tests/mocha.env.js deleted file mode 100644 index 1e62d29..0000000 --- a/tests/mocha.env.js +++ /dev/null @@ -1,11 +0,0 @@ -process.env.APP_ENV = 'test' -process.env.NODE_ENV = 'test' -process.env.NODE_TLS_REJECT_UNAUTHORIZED='0' - -require("ts-node").register({ - project: './tsconfig.json', - files: true, - swc: true -}) - -require("fix-esm").register() \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 9c7b888..5730b7b 100755 --- a/tsconfig.json +++ b/tsconfig.json @@ -26,7 +26,7 @@ "emitDecoratorMetadata": true, "declaration": true, "outDir": "./dist", - "types": ["vite/client", "@types/mocha"] + "types": ["vite/client"] }, "exclude": [ "../projects/projects/**", From 154d26bd496c6a5ea370ed78325801c153b54bef Mon Sep 17 00:00:00 2001 From: HexaField Date: Wed, 25 Sep 2024 09:08:25 +1000 Subject: [PATCH 2/7] types --- tsconfig.json | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/tsconfig.json b/tsconfig.json index 5730b7b..994e543 100755 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,42 +1,30 @@ { "compilerOptions": { - "target": "esnext", - "lib": [ - "esnext", - "dom", - "dom.iterable" - ], - "allowJs": true, + "target": "ESNext", + "useDefineForClassFields": true, + "module": "ESNext", + "lib": ["ESNext", "DOM", "DOM.Iterable"], "skipLibCheck": true, - "forceConsistentCasingInFileNames": true, + "moduleResolution": "node", + "allowImportingTsExtensions": true, + "isolatedModules": true, + "moduleDetection": "force", "noEmit": true, - "module": "CommonJS", + "allowJs": true, + "forceConsistentCasingInFileNames": true, "strict": false, "strictNullChecks": true, "strictBindCallApply": true, "noImplicitAny": false, "resolveJsonModule": true, "esModuleInterop": true, - "moduleResolution": "node", "sourceMap": true, "jsx": "react", - "isolatedModules": true, "experimentalDecorators": true, "allowSyntheticDefaultImports": true, "emitDecoratorMetadata": true, - "declaration": true, - "outDir": "./dist", - "types": ["vite/client"] + "declaration": false, + "types": ["@types/node"] }, - "exclude": [ - "../projects/projects/**", - "**/node_modules/**" - ], - "include": [ - "../../../../../__global.d.ts", - "../../../../server-core/src/*", - "../../../../client-core/src/*", - "./**/*.ts", - "./**/*.tsx" - ] + "include": ["../../../../../__global.d.ts", "../../../../", "./src", "./index.ts"] } From fb61f9648122ca841d890879af13b2d0699eec5d Mon Sep 17 00:00:00 2001 From: HexaField Date: Thu, 26 Sep 2024 08:17:11 +1000 Subject: [PATCH 3/7] vitest config --- vitest.config.ts | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 vitest.config.ts diff --git a/vitest.config.ts b/vitest.config.ts new file mode 100644 index 0000000..72524c2 --- /dev/null +++ b/vitest.config.ts @@ -0,0 +1,8 @@ +import { defineConfig } from 'vitest/config' + +export default defineConfig({ + test: { + environment: 'jsdom', + passWithNoTests: true + } +}) From 1d3ad1ff5306d798a99a047b93a40841655e3f02 Mon Sep 17 00:00:00 2001 From: HexaField Date: Thu, 26 Sep 2024 09:18:40 +1000 Subject: [PATCH 4/7] test passes --- src/bot/utils/make-user-admin.ts | 4 ++-- tests/xr.test.ts | 6 +++--- tsconfig.json | 7 ++++++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/bot/utils/make-user-admin.ts b/src/bot/utils/make-user-admin.ts index fea940f..1f49c4a 100755 --- a/src/bot/utils/make-user-admin.ts +++ b/src/bot/utils/make-user-admin.ts @@ -29,9 +29,9 @@ import { v4 } from 'uuid' import { ScopeID, ScopeTypeInterface, scopePath } from '@ir-engine/common/src/schemas/scope/scope.schema' import { UserType, userPath } from '@ir-engine/common/src/schemas/user/user.schema' -const dotenv = require('dotenv-flow') +import dotenv from 'dotenv-flow' import appRootPath from 'app-root-path' -const { scopeTypeSeed } = require('@ir-engine/server-core/src/scope/scope-type/scope-type.seed') +import { scopeTypeSeed } from '@ir-engine/server-core/src/scope/scope-type/scope-type.seed' dotenv.config({ path: appRootPath.path, diff --git a/tests/xr.test.ts b/tests/xr.test.ts index 0f89561..f37712d 100644 --- a/tests/xr.test.ts +++ b/tests/xr.test.ts @@ -1,6 +1,6 @@ import { mockEngineRenderer } from '@ir-engine/spatial/tests/util/MockEngineRenderer' import { createEngine, destroyEngine } from '@ir-engine/ecs/src/Engine' -import { initializeSpatialEngine } from '@ir-engine/spatial/src/initializeEngine' +import { initializeSpatialEngine, initializeSpatialViewer } from '@ir-engine/spatial/src/initializeEngine' import { requestXRSession } from '@ir-engine/spatial/src/xr/XRSessionFunctions' import { describe, it, beforeEach, afterEach, assert, beforeAll } from 'vitest' import { WebXREventDispatcher } from '../webxr-emulator/WebXREventDispatcher' @@ -43,8 +43,7 @@ const deviceDefinition = { ] } -/** @todo fix */ -describe.skip('WebXR', () => { +describe('WebXR', () => { beforeAll(async () => { const { CustomWebXRPolyfill } = await import('../webxr-emulator/CustomWebXRPolyfill') new CustomWebXRPolyfill() @@ -53,6 +52,7 @@ describe.skip('WebXR', () => { beforeEach(async () => { createEngine() initializeSpatialEngine() + initializeSpatialViewer() const timer = Timer((time, xrFrame) => { getMutableState(XRState).xrFrame.set(xrFrame) diff --git a/tsconfig.json b/tsconfig.json index 994e543..bd1c6c5 100755 --- a/tsconfig.json +++ b/tsconfig.json @@ -26,5 +26,10 @@ "declaration": false, "types": ["@types/node"] }, - "include": ["../../../../../__global.d.ts", "../../../../", "./src", "./index.ts"] + "include": [ + "../../../../../__global.d.ts", + "../../../../client-core/src/", + "../../../../server-core/src/", + "./src" + ] } From 63786a3ee26f5affbbe5d18e83953c650f246c4b Mon Sep 17 00:00:00 2001 From: HexaField Date: Thu, 26 Sep 2024 09:18:49 +1000 Subject: [PATCH 5/7] format --- src/bot/bot-class.ts | 14 ++++--- src/bot/bot-manager.ts | 20 ++++----- src/index.ts | 94 +++++++++++++++++++++--------------------- 3 files changed, 64 insertions(+), 64 deletions(-) diff --git a/src/bot/bot-class.ts b/src/bot/bot-class.ts index b36e86c..7a7eef2 100644 --- a/src/bot/bot-class.ts +++ b/src/bot/bot-class.ts @@ -193,12 +193,14 @@ export class IREngineBot { async clickEmoteButtonAndSelectEmote() { const emoteButton = await this.page.waitForSelector('[aria-label="Emote"]') if (emoteButton) { - await emoteButton.click().catch(err => { - console.error('Error clicking emoteButton:', err); + await emoteButton.click().catch((err) => { + console.error('Error clicking emoteButton:', err) }) await this.delay(6000) - const imgElement = await this.page.waitForSelector('button.MuiButtonBase-root-IIrwk.ispAN.MuiButton-root.MuiButton-text.MuiButton-textPrimary.MuiButton-sizeMedium.MuiButton-textSizeMedium.MuiButton-root-gwFoGh.hLKZiD._menuItem_fba7b_146:nth-child(0)') + const imgElement = await this.page.waitForSelector( + 'button.MuiButtonBase-root-IIrwk.ispAN.MuiButton-root.MuiButton-text.MuiButton-textPrimary.MuiButton-sizeMedium.MuiButton-textSizeMedium.MuiButton-root-gwFoGh.hLKZiD._menuItem_fba7b_146:nth-child(0)' + ) if (imgElement) { imgElement.click() console.log('Button clicked successfully.', imgElement) @@ -215,11 +217,11 @@ export class IREngineBot { const savebutton = await this.page.waitForSelector('li[tabindex="-1"][role="menuitem"]') if (savebutton) { await savebutton.click() - console.log("savebutton clicked") + console.log('savebutton clicked') await this.delay(4000) } const submitbutton = await this.page.waitForSelector('button[type="submit"]') - if (submitbutton){ + if (submitbutton) { await submitbutton.click() console.log('submitbutton clicked') await this.delay(10000) @@ -444,7 +446,7 @@ export class IREngineBot { '--use-fake-device-for-media-stream', '--disable-web-security=1', //'--no-first-run', - '--allow-file-access=1', + '--allow-file-access=1' //'--mute-audio', ].filter(Boolean), ...this.detectOsOption() diff --git a/src/bot/bot-manager.ts b/src/bot/bot-manager.ts index 6e7de4c..1870e76 100755 --- a/src/bot/bot-manager.ts +++ b/src/bot/bot-manager.ts @@ -20,11 +20,11 @@ export class BotManager { this.options = options } - findBotById(id:string) { + findBotById(id: string) { return this.bots[id] } - addBot(id:string,name:string ,options:any = this.options) { + addBot(id: string, name: string, options: any = this.options) { const foundBot = this.findBotById(id) if (foundBot) { return foundBot @@ -40,9 +40,9 @@ export class BotManager { return bot } - removeBot(id:string){ + removeBot(id: string) { const foundBot = this.findBotById(id) - if(!foundBot){ + if (!foundBot) { return null } foundBot.quit() @@ -50,19 +50,19 @@ export class BotManager { return foundBot } - getActions(){ + getActions() { return this.actions } - - addAction(botId:string, action:BotAction) { + + addAction(botId: string, action: BotAction) { this.actions.push({ botId, action }) } async run() { - console.log("bots : ",this.bots) + console.log('bots : ', this.bots) for (const botAction of this.actions) { - const { botId, action }:{botId:string,action} = botAction + const { botId, action }: { botId: string; action } = botAction const bot = this.findBotById(botId) if (!bot) { @@ -190,5 +190,3 @@ export class BotManager { this.bots = {} } } - - diff --git a/src/index.ts b/src/index.ts index aa461f9..a834e13 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,71 +1,71 @@ -import Koa from 'koa'; -import Router from "koa-router" -import bodyParser from "koa-bodyparser" -import { BotAction } from './bot/bot-action'; -import { BotManager } from './bot/bot-manager'; +import Koa from 'koa' +import Router from 'koa-router' +import bodyParser from 'koa-bodyparser' +import { BotAction } from './bot/bot-action' +import { BotManager } from './bot/bot-manager' -const app = new Koa(); -const router = new Router(); -const botManager = new BotManager(); +const app = new Koa() +const router = new Router() +const botManager = new BotManager() -app.use(bodyParser()); +app.use(bodyParser()) router.get('/', (ctx) => { - ctx.body = { status: 'ir-bot api is working' }; -}); + ctx.body = { status: 'ir-bot api is working' } +}) router.get('/bots', (ctx) => { - ctx.body = botManager.bots; -}); + ctx.body = botManager.bots +}) router.get('/bots/:id', (ctx) => { - const id = ctx.params.id; - const bot = botManager.findBotById(id); - ctx.body = bot; -}); + const id = ctx.params.id + const bot = botManager.findBotById(id) + ctx.body = bot +}) router.get('/bots/actions', (ctx) => { - const actions = botManager.getActions(); - ctx.body = actions; -}); + const actions = botManager.getActions() + ctx.body = actions +}) router.put('/bots/:id/create', (ctx) => { - const id = ctx.params.id; - const body:any = ctx.request.body - const name = body.name; - const options = body.options; - const bot = botManager.addBot(id, name, options); - ctx.body = bot; -}); + const id = ctx.params.id + const body: any = ctx.request.body + const name = body.name + const options = body.options + const bot = botManager.addBot(id, name, options) + ctx.body = bot +}) router.post('/bots/:id/actions/add', (ctx) => { - const id = ctx.params.id; - const body:any = ctx.request.body - const action: BotAction = body.action; - botManager.addAction(id, action); - ctx.status = 200; -}); + const id = ctx.params.id + const body: any = ctx.request.body + const action: BotAction = body.action + botManager.addAction(id, action) + ctx.status = 200 +}) router.post('/bots/run', async (ctx) => { - await botManager.run(); - ctx.status = 200; -}); + await botManager.run() + ctx.status = 200 +}) router.delete('/bots/:id/delete', async (ctx) => { - const id = ctx.params.id; - const bot = botManager.removeBot(id); - ctx.status = 200; -}); + const id = ctx.params.id + const bot = botManager.removeBot(id) + ctx.status = 200 +}) router.delete('/bots/clear', async (ctx) => { - await botManager.clear(); - ctx.status = 200; -}); + await botManager.clear() + ctx.status = 200 +}) -app.use(router.routes()); -app.use(router.allowedMethods()); +app.use(router.routes()) +app.use(router.allowedMethods()) const PORT = process.env.PORT || 4000 app.listen(PORT, () => { - console.log(`Koa Server listening on port ${PORT}`); -}); + console.log(`Koa Server listening on port ${PORT}`) +}) From 25d94beb46bb0a1f41ff0152fde5d15b5040d367 Mon Sep 17 00:00:00 2001 From: HexaField Date: Fri, 27 Sep 2024 09:50:57 +1000 Subject: [PATCH 6/7] deps --- package.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/package.json b/package.json index 8bf130f..e2288cf 100755 --- a/package.json +++ b/package.json @@ -40,12 +40,9 @@ }, "license": "ISC", "devDependencies": { - "vitest": "2.0.4", - "@swc/core": "1.3.41", "@types/expect-puppeteer": "^5.0.3", "@types/koa-bodyparser": "^4.3.10", - "@types/koa-router": "^7.4.4", - "@types/mocha": "^10.0.1" + "@types/koa-router": "^7.4.4" }, "pre-commit": [ "format-staged" From 3d9c9d54e6d537070abdd6e2ca78ba0a4b12b881 Mon Sep 17 00:00:00 2001 From: HexaField Date: Wed, 2 Oct 2024 09:15:20 +1000 Subject: [PATCH 7/7] replace ts-node --- package.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index e2288cf..86dab1a 100755 --- a/package.json +++ b/package.json @@ -18,8 +18,8 @@ "scripts": { "build": "tsc", "check-errors": "tsc --noemit", - "dev": "ts-node --swc ./src/index.ts", - "dev-koa": "ts-node --swc ./src/index_koa.ts", + "dev": "vite-node ./src/index.ts", + "dev-koa": "vite-node ./src/index_koa.ts", "format": "prettier --write \"**/*.{ts,tsx}\"", "format-scss": "stylelint \"**/*.scss\" --fix", "format-staged": "lint-staged", @@ -35,7 +35,6 @@ "koa-router": "^12.0.0", "localforage": "^1.10.0", "puppeteer": "^19.6.3", - "ts-node": "10.9.1", "webxr-polyfill": "github:felixtrz/webxr-polyfill#81d2db4f01b518f2c42b74a90973dac095515e9f" }, "license": "ISC",