Skip to content

Commit

Permalink
test server is not created if config validation fails
Browse files Browse the repository at this point in the history
  • Loading branch information
mshustov committed Apr 23, 2019
1 parent 532089a commit 4d805ad
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
16 changes: 16 additions & 0 deletions src/core/server/root/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,19 @@ test('stops services if consequent logger upgrade fails', async () => {

expect(mockConsoleError.mock.calls).toMatchSnapshot();
});

test(`doesn't create server if config validation fails`, async () => {
configService.validateAll.mockImplementation(() => {
throw new Error('invalid config');
});
const ServerMock = jest.fn();
jest.doMock('../server', () => ({
Server: ServerMock,
}));
const onShutdown = jest.fn();
const root = new Root(config$, env, onShutdown);

await expect(root.setup()).rejects.toThrowErrorMatchingInlineSnapshot(`"invalid config"`);
expect(ServerMock).not.toHaveBeenCalled();
expect(onShutdown).toHaveBeenCalledTimes(1);
});
14 changes: 7 additions & 7 deletions src/core/server/root/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@ export class Root {
}

public async setup() {
const newPlatformPluginDefinitions = await this.discoverPlugins();
const schemas = this.getSchemas(newPlatformPluginDefinitions);
try {
const newPlatformPluginDefinitions = await this.discoverPlugins();
const schemas = this.getSchemas(newPlatformPluginDefinitions);

this.configService = new ConfigService(this.config$, this.env, this.logger, schemas);
this.configService = new ConfigService(this.config$, this.env, this.logger, schemas);

await this.configService.validateAll();
await this.configService.validateAll();

this.server = new Server(this.configService, this.logger, this.env);
this.server = new Server(this.configService, this.logger, this.env);

this.log.debug('setting up root');
this.log.debug('setting up root');

try {
await this.setupLogging();
await this.server.setup(newPlatformPluginDefinitions);
} catch (e) {
Expand Down

0 comments on commit 4d805ad

Please sign in to comment.