From 6891169444163aca52a9c9fe1081045dbd771bec Mon Sep 17 00:00:00 2001 From: Yurij Mikhalevich Date: Sun, 28 Apr 2024 21:18:24 +0400 Subject: [PATCH] tests: add tests infrastructure + first unit and e2e tests (#6) --- .env.e2e | 1 + .github/workflows/validate.yaml | 12 + .gitignore | 3 + README.md | 18 +- bin/seed-test-users.ts | 3 + components/CodeEditor.vue | 5 +- components/GameScreen.vue | 5 +- components/GlobalHeader.nuxt.spec.ts | 10 + nuxt.config.ts | 7 +- package-lock.json | 3126 +++++++++++++++----------- package.json | 12 + playwright.config.ts | 23 + schema.prisma | 2 +- {utils => server}/botApis/level01.js | 0 server/plugins/engine.ts | 39 +- tests/e2e/global-setup.ts | 12 + tests/e2e/login.e2e.spec.ts | 27 + tests/utils/seed-test-users.ts | 28 + utils/db.ts | 2 +- utils/getRandomElement.spec.ts | 15 + utils/world.ts | 2 + vitest.config.ts | 13 + 22 files changed, 2075 insertions(+), 1290 deletions(-) create mode 100644 .env.e2e create mode 100644 bin/seed-test-users.ts create mode 100644 components/GlobalHeader.nuxt.spec.ts create mode 100644 playwright.config.ts rename {utils => server}/botApis/level01.js (100%) create mode 100644 tests/e2e/global-setup.ts create mode 100644 tests/e2e/login.e2e.spec.ts create mode 100644 tests/utils/seed-test-users.ts create mode 100644 utils/getRandomElement.spec.ts create mode 100644 vitest.config.ts diff --git a/.env.e2e b/.env.e2e new file mode 100644 index 0000000..793ac49 --- /dev/null +++ b/.env.e2e @@ -0,0 +1 @@ +DATABASE_URL=file:/tmp/aibyss-test.db diff --git a/.github/workflows/validate.yaml b/.github/workflows/validate.yaml index fea310f..edfbd95 100644 --- a/.github/workflows/validate.yaml +++ b/.github/workflows/validate.yaml @@ -18,3 +18,15 @@ jobs: - run: npm ci - run: npm run lint - run: npm run build + + test: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: '20.x' + - run: npm ci + - run: npm run test:e2e:install + - run: npm run test + - run: npm run test:e2e diff --git a/.gitignore b/.gitignore index dc31c39..978f81a 100644 --- a/.gitignore +++ b/.gitignore @@ -22,7 +22,10 @@ logs .env .env.* !.env.example +!.env.e2e # Data Base dev.db dev.db-journal + +test-results diff --git a/README.md b/README.md index a6b976f..8216bb9 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,25 @@ Start the development server on `http://localhost:3000`: npm run dev ``` +## Running the tests + +### unit tests + +```bash +npm run test +``` + +### e2e tests + +First, setup e2e tests by running `npm run test:e2e:install`, then run the tests with: + +```bash +npm run test:e2e +``` + ## Contributors guide -- we follow [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/), name your PRs accordingly +We follow [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/), name your PRs accordingly ## Production diff --git a/bin/seed-test-users.ts b/bin/seed-test-users.ts new file mode 100644 index 0000000..60c7687 --- /dev/null +++ b/bin/seed-test-users.ts @@ -0,0 +1,3 @@ +import { seedTestUsers } from "../tests/utils/seed-test-users"; + +seedTestUsers(); diff --git a/components/CodeEditor.vue b/components/CodeEditor.vue index 477b10a..dc0f581 100644 --- a/components/CodeEditor.vue +++ b/components/CodeEditor.vue @@ -73,7 +73,10 @@ function onSubmit(event: Event) {