Commit 9efb2dbe authored by nanahira's avatar nanahira

unit test

parent 2176878c
stages:
- install
- build
- deploy
variables:
GIT_DEPTH: "1"
build:
stage: build
npm_ci:
stage: install
tags:
- linux
script:
- npm ci
artifacts:
paths:
- node_modules
.build_base:
stage: build
tags:
- linux
dependencies:
- npm_ci
build:
extends:
- .build_base
script:
- npm run build
artifacts:
paths:
- dist/
unit-test:
extends:
- .build_base
script:
- npm run test
deploy_npm:
stage: deploy
dependencies:
......
......@@ -8,4 +8,5 @@
Dockerfile
/test
/dist/test
/src
\ No newline at end of file
/src
/coverage
\ No newline at end of file
This diff is collapsed.
......@@ -6,7 +6,8 @@
"typings": "dist/index.d.ts",
"scripts": {
"lint": "eslint --fix .",
"build": "tsc"
"build": "tsc",
"test": "jest"
},
"repository": {
"type": "git",
......@@ -29,6 +30,7 @@
"license": "MIT",
"devDependencies": {
"@koishijs/plugin-adapter-onebot": "^4.0.0-beta.2",
"@types/jest": "^27.0.3",
"@types/lodash": "^4.14.177",
"@types/node": "^16.11.9",
"@typescript-eslint/eslint-plugin": "^4.33.0",
......@@ -36,8 +38,10 @@
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.1",
"jest": "^27.4.3",
"koishi": "^4.0.0-beta.3",
"prettier": "^2.4.1",
"ts-jest": "^27.0.7",
"typescript": "^4.5.2",
"ws": "^8.2.3"
},
......@@ -50,5 +54,22 @@
"schemastery": "^2.0.0",
"schemastery-gen": "2.0.2",
"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 @@
"include": [
"*.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