Skip to content

Commit

Permalink
dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
bwp91 committed Aug 29, 2024
1 parent 811cd73 commit 3c83b13
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 69 deletions.
9 changes: 5 additions & 4 deletions __mocks__/bonjour-hap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ class Advertisement {
destroy = vi.fn()
}

class BonjourService {
publish = vi.fn(() => {
return new Advertisement()
})
function publishFn() {
return new Advertisement()
}

class BonjourService {
publish = vi.fn(publishFn)
destroy = vi.fn()
}

Expand Down
4 changes: 3 additions & 1 deletion __mocks__/node-persist.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { vi } from 'vitest'

const createFn = vi.fn().mockImplementation(() => new Storage())

class Storage {
getItem = vi.fn()
setItemSync = vi.fn()
persistSync = vi.fn()
removeItemSync = vi.fn()
initSync = vi.fn()
create = vi.fn().mockImplementation(() => new Storage())
create = createFn
}

export default new Storage()
4 changes: 1 addition & 3 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import antfu from '@antfu/eslint-config'

export default antfu(
{
ignores: ['dist', 'docs'],
jsx: false,
typescript: true,
formatters: {
Expand Down Expand Up @@ -44,7 +45,4 @@ export default antfu(
'unused-imports/no-unused-vars': ['error', { caughtErrors: 'none' }],
},
},
{
ignores: ['dist', 'docs'],
},
)
107 changes: 60 additions & 47 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"tweetnacl": "^1.0.3"
},
"devDependencies": {
"@antfu/eslint-config": "^2.27.3",
"@antfu/eslint-config": "^3.0.0",
"@types/debug": "^4.1.12",
"@types/escape-html": "^1.0.4",
"@types/node": "^22.5.1",
Expand Down
13 changes: 5 additions & 8 deletions src/lib/Accessory.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Buffer } from 'node:buffer'

import type { MockInstance } from 'vitest'
import type { Mock, MockInstance } from 'vitest'

import type {
AccessoriesResponse,
Expand Down Expand Up @@ -56,8 +56,6 @@ import { HapStatusError } from './util/hapStatusError.js'
import { awaitEventOnce, PromiseTimeout } from './util/promise-utils.js'
import { generate, toShortForm } from './util/uuid.js'

import Mock = vi.Mock

describe('accessory', () => {
const TEST_DISPLAY_NAME = 'Test Accessory'
const TEST_UUID = generate('HAP-NODEJS-TEST-ACCESSORY!')
Expand Down Expand Up @@ -339,8 +337,6 @@ describe('accessory', () => {
username: serverUsername,
pincode: '000-00-000',
category: Categories.SWITCH,

// @ts-expect-error Type unknown is not assignable to type MDNSAdvertiser | undefined
advertiser,
}

Expand Down Expand Up @@ -946,7 +942,7 @@ describe('accessory', () => {
characteristicConstructor: new () => Characteristic,
iid: number,
value?: CharacteristicValue,
): Promise<CharacteristicJsonObject> => {
): Promise<CharacteristicJsonObject> => { // eslint-disable-line unicorn/consistent-function-scoping
// eslint-disable-next-line new-cap
const characteristic = new characteristicConstructor()
if (value !== undefined) {
Expand Down Expand Up @@ -1012,7 +1008,7 @@ describe('accessory', () => {
const testRequestResponse = async (
request: Partial<CharacteristicsReadRequest>,
...expectedReadData: CharacteristicReadData[]
): Promise<void> => {
): Promise<void> => { // eslint-disable-line unicorn/consistent-function-scoping
// @ts-expect-error: private access
accessory.handleGetCharacteristics(connection, {
ids: [],
Expand Down Expand Up @@ -1232,7 +1228,7 @@ describe('accessory', () => {
const testRequestResponse = async (
request: Partial<CharacteristicsWriteRequest>,
...expectedReadData: CharacteristicWriteData[]
): Promise<void> => {
): Promise<void> => { // eslint-disable-line unicorn/consistent-function-scoping
// @ts-expect-error: private access
accessory.handleSetCharacteristics(connection, {
characteristics: [],
Expand Down Expand Up @@ -1699,6 +1695,7 @@ describe('accessory', () => {
accessory.configureController(cameraController)
})

// eslint-disable-next-line unicorn/consistent-function-scoping
const testRequestResponse = async (partial: Partial<ResourceRequest> = {}) => {
// @ts-expect-error: private access
accessory.handleResource({
Expand Down
10 changes: 5 additions & 5 deletions src/lib/util/eventedhttp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ import { HAPHTTPCode } from '../HAPServer.js'
import { EventedHTTPServer, EventedHTTPServerEvent, HAPConnectionEvent } from './eventedhttp.js'
import { awaitEventOnce, PromiseTimeout } from './promise-utils.js'

function defaultRequestHandler(connection: any, request: any, response: ServerResponse) {
response.writeHead(HAPHTTPCode.OK, { 'Content-Type': 'plain/text' })
response.end('Hello World', 'ascii')
}

describe('eventedhttp', () => {
let httpAgent: Agent
let server: EventedHTTPServer
let baseUrl: string

const defaultRequestHandler = (connection: any, request: any, response: ServerResponse) => {
response.writeHead(HAPHTTPCode.OK, { 'Content-Type': 'plain/text' })
response.end('Hello World', 'ascii')
}

beforeEach(async () => {
// used to do long living http connections without own tcp interface
httpAgent = new Agent({
Expand Down

0 comments on commit 3c83b13

Please sign in to comment.