From f7fc00dd22aa1862ff87dd714c51fef849b0806f Mon Sep 17 00:00:00 2001 From: Maiko Tan Date: Tue, 12 Sep 2023 22:38:41 +0800 Subject: [PATCH] test: add test framework and workflows --- .eslintrc.yml | 3 ++- .github/workflows/lint.yml | 2 +- .github/workflows/test.yml | 30 +++++++++++++++++++++++++++++ packages/core/tests/index.spec.ts | 18 +++++++++++++++++ packages/wordle/src/index.ts | 2 +- packages/wordle/tests/index.spec.ts | 22 +++++++++++++++++++++ tsconfig.base.json | 2 +- 7 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/test.yml create mode 100644 packages/core/tests/index.spec.ts create mode 100644 packages/wordle/tests/index.spec.ts diff --git a/.eslintrc.yml b/.eslintrc.yml index 6418f8d..6eeffee 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -1,4 +1,4 @@ -extends: "@hamster-bot/eslint-config/typescript" +extends: '@hamster-bot/eslint-config/typescript' rules: # TypeScript would do this check so we don't need this. @@ -6,6 +6,7 @@ rules: ignorePatterns: - node_modules + - lib - dist - coverage - docs diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 79434e9..54ba155 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -12,7 +12,7 @@ jobs: lint: strategy: matrix: - version: [14, 16, 18] + version: [14, 16, 18, 20] runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..7996ae1 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,30 @@ +name: Test + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + lint: + strategy: + matrix: + version: [14, 16, 18, 20] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.version }} + + - name: Install dependencies + run: yarn install + + - name: Build + run: yarn run build + + - name: Test + run: yarn run test diff --git a/packages/core/tests/index.spec.ts b/packages/core/tests/index.spec.ts new file mode 100644 index 0000000..5991907 --- /dev/null +++ b/packages/core/tests/index.spec.ts @@ -0,0 +1,18 @@ +import memory from '@koishijs/plugin-database-memory' +import mock from '@koishijs/plugin-mock' +import { expect } from 'chai' +import { App } from 'koishi' + +describe('wordle', () => { + const app = new App() + + app.plugin(mock) + app.plugin(memory) + + before(() => app.start()) + after(() => app.stop()) + + it('should pass test', async () => { + expect(1).to.equal(1) + }) +}) diff --git a/packages/wordle/src/index.ts b/packages/wordle/src/index.ts index b13ce50..3bde2e9 100644 --- a/packages/wordle/src/index.ts +++ b/packages/wordle/src/index.ts @@ -7,11 +7,11 @@ export class Wordle extends WordleCore { getTodayWord(): string { return '' } + validateInput(): WordleCore.Validation { return { isValid: false, color: [], - } } } diff --git a/packages/wordle/tests/index.spec.ts b/packages/wordle/tests/index.spec.ts new file mode 100644 index 0000000..4527b5a --- /dev/null +++ b/packages/wordle/tests/index.spec.ts @@ -0,0 +1,22 @@ +import memory from '@koishijs/plugin-database-memory' +import mock from '@koishijs/plugin-mock' +import { App } from 'koishi' + +import * as wordle from '../src' + +describe('wordle', () => { + const app = new App() + + app.plugin(mock) + app.plugin(memory) + app.plugin(wordle) + + const client = app.mock.client('123') + + before(() => app.start()) + after(() => app.stop()) + + it('get today wordle', async () => { + await client.shouldReply('wordle') + }) +}) diff --git a/tsconfig.base.json b/tsconfig.base.json index 9f9a75b..22079e0 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -11,6 +11,6 @@ "strictBindCallApply": true, "jsx": "react-jsx", "jsxImportSource": "@satorijs/element", - "types": ["yml-register/types"] + "types": ["mocha", "yml-register/types"] } }