Skip to content

Commit e92f027

Browse files
committed
test
1 parent 20771dc commit e92f027

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

lib/service.spec.ts

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@
1515
*/
1616

1717
import { it, expect } from 'vitest';
18-
import { BaseService, ServiceState } from './service';
19-
18+
import { BaseService, ServiceState, StartupLog } from './service';
19+
import { LogLevel } from './modules/logging';
20+
import { getMockLogger } from './tests/mock/mock_logger';
2021
class TestService extends BaseService {
21-
constructor() {
22-
super();
22+
constructor(startUpLogs?: StartupLog[]) {
23+
super(startUpLogs);
2324
}
2425

2526
start(): void {
27+
super.start();
2628
this.setState(ServiceState.Running);
2729
this.startPromise.resolve();
2830
}
@@ -64,6 +66,30 @@ it('should return correct state when getState() is called', () => {
6466
expect(service.getState()).toBe(ServiceState.Failed);
6567
});
6668

69+
it('should log startupLogs on start', () => {
70+
const startUpLogs: StartupLog[] = [
71+
{
72+
level: LogLevel.WARNING,
73+
message: 'warn message',
74+
params: [1, 2]
75+
},
76+
{
77+
level: LogLevel.ERROR,
78+
message: 'error message',
79+
params: [3, 4]
80+
},
81+
];
82+
83+
const logger = getMockLogger();
84+
const service = new TestService(startUpLogs);
85+
service.setLogger(logger);
86+
service.start();
87+
88+
expect(logger.log).toHaveBeenCalledTimes(2);
89+
expect(logger.log).toHaveBeenNthCalledWith(1, LogLevel.WARNING, 'warn message', 1, 2);
90+
expect(logger.log).toHaveBeenNthCalledWith(2, LogLevel.ERROR, 'error message', 3, 4);
91+
});
92+
6793
it('should return an appropraite promise when onRunning() is called', () => {
6894
const service1 = new TestService();
6995
const onRunning1 = service1.onRunning();

vitest.config.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default defineConfig({
2020
test: {
2121
onConsoleLog: () => true,
2222
environment: 'happy-dom',
23-
include: ['**/cache.spec.ts'],
23+
include: ['**/service.spec.ts'],
2424
typecheck: {
2525
tsconfig: 'tsconfig.spec.json',
2626
},

0 commit comments

Comments
 (0)