Skip to content

Commit

Permalink
test: make mdns test stable
Browse files Browse the repository at this point in the history
We need to ensure that the actual mdns module is not loaded in any test
so that we can make it virtual. If this is not done the ClusterService
tests will be flaky if the mdns module is installed and compiled on the
machine.
  • Loading branch information
mKeRix committed Dec 6, 2020
1 parent 9d2eb5b commit 6fed59f
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/entities/entities.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { ConfigModule } from '../config/config.module';
import { BinarySensor } from './binary-sensor';
import { Camera } from './camera';

jest.mock('mdns', () => ({}), { virtual: true });

describe('Entities Controller', () => {
let controller: EntitiesController;
let service: EntitiesService;
Expand Down
2 changes: 2 additions & 0 deletions src/entities/entities.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { ClusterModule } from '../cluster/cluster.module';
import { Switch } from './switch';
import { ConfigModule } from '../config/config.module';

jest.mock('mdns', () => ({}), { virtual: true });

describe('EntitiesService', () => {
let service: EntitiesService;
const emitter: EventEmitter = new EventEmitter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { Device } from './device';
import { DeviceTracker } from '../../entities/device-tracker';
import * as util from 'util';

jest.mock('mdns', () => ({}), { virtual: true });
jest.mock('../room-presence/room-presence-distance.sensor');
jest.mock('kalmanjs', () => {
return jest.fn().mockImplementation(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
jest.mock('mdns', () => ({}), { virtual: true });
jest.mock('kalmanjs', () => {
return jest.fn().mockImplementation(() => {
return {
Expand Down
1 change: 1 addition & 0 deletions src/integrations/gpio/gpio.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { mocked } from 'ts-jest/utils';
import { ClusterService } from '../../cluster/cluster.service';
import { GpioSwitch } from './gpio.switch';

jest.mock('mdns', () => ({}), { virtual: true });
jest.mock('onoff');

describe('GpioService', () => {
Expand Down
1 change: 1 addition & 0 deletions src/integrations/grid-eye/grid-eye.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { Sensor } from '../../entities/sensor';
import i2cBus from 'i2c-bus';
import * as math from 'mathjs';

jest.mock('mdns', () => ({}), { virtual: true });
jest.mock(
'i2c-bus',
() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { HomeAssistantConfig } from './home-assistant.config';
import { ConfigService } from '../../config/config.service';
import c from 'config';

jest.mock('mdns', () => ({}), { virtual: true });
jest.mock('async-mqtt', () => {
return {
connectAsync: jest.fn().mockReturnValue(mockMqttClient),
Expand Down
1 change: 1 addition & 0 deletions src/integrations/omron-d6t/omron-d6t.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Sensor } from '../../entities/sensor';
import { I2CError } from './i2c.error';
import i2cBus from 'i2c-bus';

jest.mock('mdns', () => ({}), { virtual: true });
jest.mock(
'i2c-bus',
() => {
Expand Down
1 change: 1 addition & 0 deletions src/integrations/shell/shell.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { CronJob } from 'cron';
import * as util from 'util';
import { ShellSwitch } from './shell.switch';

jest.mock('mdns', () => ({}), { virtual: true });
jest.mock('cron');
jest.mock('util', () => ({
...jest.requireActual('util'),
Expand Down
1 change: 1 addition & 0 deletions src/integrations/xiaomi-mi/xiaomi-mi.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
jest.mock('mdns', () => ({}), { virtual: true });
jest.mock(
'@mkerix/noble',
() => {
Expand Down
2 changes: 2 additions & 0 deletions src/status/status.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { EntitiesService } from '../entities/entities.service';
import { ClusterService } from '../cluster/cluster.service';
import { Sensor } from '../entities/sensor';

jest.mock('mdns', () => ({}), { virtual: true });

describe('StatusService', () => {
let service: StatusService;
const entitiesService = {
Expand Down

0 comments on commit 6fed59f

Please sign in to comment.