Skip to content

Commit

Permalink
Compile test context in CI (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
kibertoad authored Oct 17, 2023
1 parent 3da164a commit 842c121
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 55 deletions.
110 changes: 55 additions & 55 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
{
"name": "awilix-manager",
"description": "Wrapper over awilix to support more complex use-cases, such as async init and eager injection",
"version": "3.3.0",
"dependencies": {
"awilix": "^9.0.0"
},
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"build:release": "del-cli dist && del-cli coverage && npm run lint && npm run build",
"test": "vitest",
"test:coverage": "npm test -- --coverage",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"format": "prettier --write .",
"prepublishOnly": "npm run build:release"
},
"devDependencies": {
"@types/node": "^20.8.4",
"@typescript-eslint/eslint-plugin": "^6.7.2",
"@typescript-eslint/parser": "^6.7.2",
"@vitest/coverage-v8": "^0.34.6",
"del-cli": "^5.0.0",
"eslint": "^8.51.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-vitest": "^0.3.2",
"prettier": "^3.0.3",
"typescript": "^5.2.2",
"vitest": "^0.34.6"
},
"engines": {
"node": ">=16"
},
"repository": {
"type": "git",
"url": "git://github.com/kibertoad/awilix-manager.git"
},
"keywords": [
"init",
"async",
"eager",
"awilix",
"di"
],
"homepage": "https://github.com/kibertoad/awilix-manager",
"files": [
"README.md",
"LICENSE",
"dist/*"
]
}
{
"name": "awilix-manager",
"description": "Wrapper over awilix to support more complex use-cases, such as async init and eager injection",
"version": "3.3.0",
"dependencies": {
"awilix": "^9.0.0"
},
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"build:release": "del-cli dist && del-cli coverage && npm run lint && npm run build",
"test": "vitest",
"test:coverage": "npm test -- --coverage",
"lint": "eslint . --ext .ts && tsc --project tsconfig.lint.json --noEmit",
"lint:fix": "eslint . --ext .ts --fix",
"format": "prettier --write .",
"prepublishOnly": "npm run build:release"
},
"devDependencies": {
"@types/node": "^20.8.4",
"@typescript-eslint/eslint-plugin": "^6.7.2",
"@typescript-eslint/parser": "^6.7.2",
"@vitest/coverage-v8": "^0.34.6",
"del-cli": "^5.0.0",
"eslint": "^8.51.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-vitest": "^0.3.2",
"prettier": "^3.0.3",
"typescript": "^5.2.2",
"vitest": "^0.34.6"
},
"engines": {
"node": ">=16"
},
"repository": {
"type": "git",
"url": "git://github.com/kibertoad/awilix-manager.git"
},
"keywords": [
"init",
"async",
"eager",
"awilix",
"di"
],
"homepage": "https://github.com/kibertoad/awilix-manager",
"files": [
"README.md",
"LICENSE",
"dist/*"
]
}
34 changes: 34 additions & 0 deletions test/testContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type { AwilixContainer } from 'awilix'
import { asClass, Lifetime } from 'awilix'
import type { Resolver } from 'awilix/lib/resolvers'

export const SINGLETON_CONFIG = { lifetime: Lifetime.SINGLETON }

export type DependencyOverrides = Partial<DiConfig>
class SomeModule {}

export function registerDependencies(
diContainer: AwilixContainer,
dependencyOverrides: DependencyOverrides = {},
): void {
const diConfig: DiConfig = {
module: asClass(SomeModule, {
...SINGLETON_CONFIG,
asyncInit: 'start',
asyncDispose: 'close',
asyncDisposePriority: 10,
enabled: true,
}),
}
diContainer.register(diConfig)

for (const [dependencyKey, dependencyValue] of Object.entries(dependencyOverrides)) {
diContainer.register(dependencyKey, dependencyValue)
}
}

type DiConfig = Record<keyof Dependencies, Resolver<any>>

export interface Dependencies {
module: SomeModule
}
5 changes: 5 additions & 0 deletions tsconfig.lint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": ["./tsconfig.json"],
"include": ["lib/**/*.ts", "test/**/*.ts", "vitest.config.ts"],
"exclude": []
}

0 comments on commit 842c121

Please sign in to comment.