1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/src/lib/server-impl.test.ts
Christopher Kolstad 6673d131fe
feat: biome lint (#4853)
This commit changes our linter/formatter to biome (https://biomejs.dev/)
Causing our prehook to run almost instantly, and our "yarn lint" task to
run in sub 100ms.

Some trade-offs:
* Biome isn't quite as well established as ESLint
* Are we ready to install a different vscode plugin (the biome plugin)
instead of the prettier plugin


The configuration set for biome also has a set of recommended rules,
this is turned on by default, in order to get to something that was
mergeable I have turned off a couple the rules we seemed to violate the
most, that we also explicitly told eslint to ignore.
2023-09-29 14:18:21 +02:00

118 lines
2.7 KiB
TypeScript

import express from 'express';
import { createTestConfig } from '../test/config/test-config';
import { start, create } from './server-impl';
import FakeEventStore from '../test/fixtures/fake-event-store';
jest.mock(
'./routes',
() =>
class Index {
router() {
return express.Router();
}
},
);
const noop = () => {};
const eventStore = new FakeEventStore();
const settingStore = {
get: () => {
Promise.resolve('secret');
},
};
jest.mock('./metrics', () => ({
createMetricsMonitor() {
return {
startMonitoring: noop,
stopMonitoring: noop,
};
},
}));
jest.mock('./db', () => ({
createStores() {
return {
db: {
destroy: () => undefined,
},
clientInstanceStore: {
destroy: noop,
removeInstancesOlderThanTwoDays: noop,
},
clientMetricsStore: { destroy: noop, on: noop },
eventStore,
publicSignupTokenStore: { destroy: noop, on: noop },
settingStore,
projectStore: { getAll: () => Promise.resolve([]) },
};
},
}));
jest.mock('../migrator', () => ({
migrateDb: () => Promise.resolve(),
}));
jest.mock('./util/db-lock', () => ({
withDbLock: () => (fn) => fn,
}));
jest.mock(
'./util/version',
() =>
function () {
return 'unleash-test-version';
},
);
test('should call preHook', async () => {
let called = 0;
const config = createTestConfig({
server: { port: 0 },
preHook: () => {
called++;
},
});
const { stop } = await start(config);
expect(called).toBe(1);
await stop();
});
test('should call preRouterHook', async () => {
let called = 0;
const { stop } = await start(
createTestConfig({
server: { port: 0 },
preRouterHook: () => {
called++;
},
}),
);
expect(called === 1).toBe(true);
await stop();
});
test('should auto-create server on start()', async () => {
const { server, stop } = await start(
createTestConfig({ server: { port: 0 } }),
);
expect(typeof server === 'undefined').toBe(false);
await stop();
});
test('should not create a server using create()', async () => {
const config = createTestConfig({ server: { port: 0 } });
const { server, stop } = await create(config);
expect(server).toBeUndefined();
await stop();
});
test('should shutdown the server when calling stop()', async () => {
const { server, stop } = await start(
createTestConfig({ server: { port: 0 } }),
);
await stop();
expect(server?.address()).toBe(null);
});