Commit 9efb2dbe authored by nanahira's avatar nanahira

unit test

parent 2176878c
stages: stages:
- install
- build - build
- deploy - deploy
variables: variables:
GIT_DEPTH: "1" GIT_DEPTH: "1"
build: npm_ci:
stage: build stage: install
tags: tags:
- linux - linux
script: script:
- npm ci - npm ci
artifacts:
paths:
- node_modules
.build_base:
stage: build
tags:
- linux
dependencies:
- npm_ci
build:
extends:
- .build_base
script:
- npm run build - npm run build
artifacts: artifacts:
paths: paths:
- dist/ - dist/
unit-test:
extends:
- .build_base
script:
- npm run test
deploy_npm: deploy_npm:
stage: deploy stage: deploy
dependencies: dependencies:
......
...@@ -9,3 +9,4 @@ Dockerfile ...@@ -9,3 +9,4 @@ Dockerfile
/test /test
/dist/test /dist/test
/src /src
/coverage
\ No newline at end of file
This diff is collapsed.
...@@ -6,7 +6,8 @@ ...@@ -6,7 +6,8 @@
"typings": "dist/index.d.ts", "typings": "dist/index.d.ts",
"scripts": { "scripts": {
"lint": "eslint --fix .", "lint": "eslint --fix .",
"build": "tsc" "build": "tsc",
"test": "jest"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
...@@ -29,6 +30,7 @@ ...@@ -29,6 +30,7 @@
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@koishijs/plugin-adapter-onebot": "^4.0.0-beta.2", "@koishijs/plugin-adapter-onebot": "^4.0.0-beta.2",
"@types/jest": "^27.0.3",
"@types/lodash": "^4.14.177", "@types/lodash": "^4.14.177",
"@types/node": "^16.11.9", "@types/node": "^16.11.9",
"@typescript-eslint/eslint-plugin": "^4.33.0", "@typescript-eslint/eslint-plugin": "^4.33.0",
...@@ -36,8 +38,10 @@ ...@@ -36,8 +38,10 @@
"eslint": "^7.32.0", "eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0", "eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.1", "eslint-plugin-prettier": "^3.4.1",
"jest": "^27.4.3",
"koishi": "^4.0.0-beta.3", "koishi": "^4.0.0-beta.3",
"prettier": "^2.4.1", "prettier": "^2.4.1",
"ts-jest": "^27.0.7",
"typescript": "^4.5.2", "typescript": "^4.5.2",
"ws": "^8.2.3" "ws": "^8.2.3"
}, },
...@@ -50,5 +54,22 @@ ...@@ -50,5 +54,22 @@
"schemastery": "^2.0.0", "schemastery": "^2.0.0",
"schemastery-gen": "2.0.2", "schemastery-gen": "2.0.2",
"typed-reflector": "^1.0.5" "typed-reflector": "^1.0.5"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "tests",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
} }
} }
import { Inject, KoishiPlugin } from '..';
import { Cache, Assets, Bot, Context } from 'koishi';
describe('InjectUsing', () => {
@KoishiPlugin({ using: ['database'] })
class MyPlugin {
@Inject(true)
cache: Cache;
@Inject('assets', true)
assets: Assets;
@Inject('bots')
bots: Bot[];
}
it('Should include injected using services', () => {
const usingList = (MyPlugin as any).using as (keyof Context.Services)[];
expect(usingList).toBeInstanceOf(Array);
expect(usingList.length).toEqual(3);
expect(usingList.includes('database')).toEqual(true);
expect(usingList.includes('assets')).toEqual(true);
expect(usingList.includes('cache')).toEqual(true);
expect(usingList.includes('bots')).toEqual(false);
});
});
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
"include": [ "include": [
"*.ts", "*.ts",
"src/**/*.ts", "src/**/*.ts",
"test/**/*.ts" "test/**/*.ts",
"tests/**/*.ts"
] ]
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment