test(repos): service 测试用例,工作目录改为从配置文件中读取。

This commit is contained in:
Ivan
2021-02-24 11:11:47 +08:00
parent 1e7c594e72
commit 625ed18ae9
2 changed files with 20 additions and 20 deletions

View File

@ -2,11 +2,10 @@ import { Test, TestingModule } from '@nestjs/testing';
import { getRepositoryToken } from '@nestjs/typeorm';
import { Project } from '../projects/project.entity';
import { ReposService } from './repos.service';
import { ConfigService } from '@nestjs/config';
import { ConfigService, ConfigModule } from '@nestjs/config';
import { rm } from 'fs/promises';
import { join } from 'path';
const workspacesRoot = 'E:\\Projects\\demos\\workspaces';
import configuration from '../commons/config/configuration';
describe('ReposService', () => {
let service: ReposService;
@ -21,34 +20,35 @@ describe('ReposService', () => {
}),
),
}));
let workspacesRoot: string;
afterEach(async () => {
await rm(join(workspacesRoot, 'test1'), {
recursive: true,
}).catch(() => undefined);
});
beforeEach(async () => {
await rm(join(workspacesRoot, 'test1'), {
recursive: true,
}).catch(() => undefined);
const module: TestingModule = await Test.createTestingModule({
imports: [
ConfigModule.forRoot({
load: [configuration],
}),
],
providers: [
ReposService,
{
provide: getRepositoryToken(Project),
useFactory: repositoryMockFactory,
},
{
provide: ConfigService,
useValue: {
get() {
return workspacesRoot;
},
},
},
],
}).compile();
service = module.get<ReposService>(ReposService);
const configServer = module.get<ConfigService>(ConfigService);
workspacesRoot = configServer.get<string>('workspaces.root');
await rm(join(workspacesRoot, 'test1'), {
recursive: true,
}).catch(() => undefined);
});
it('should be defined', () => {