-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use as esm module to allow latest version of node-fetch to …
…be used
- Loading branch information
1 parent
371d429
commit 7496aca
Showing
11 changed files
with
1,242 additions
and
103 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import { Logger } from "homebridge"; | ||
import { vi } from "vitest"; | ||
|
||
export const loggerMock = { | ||
info: jest.fn(), | ||
warn: jest.fn(), | ||
error: jest.fn(), | ||
debug: jest.fn(), | ||
log: jest.fn(), | ||
info: vi.fn(), | ||
warn: vi.fn(), | ||
error: vi.fn(), | ||
debug: vi.fn(), | ||
log: vi.fn(), | ||
} satisfies Logger; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,55 @@ | ||
import { HomebridgeAPI } from "homebridge/lib/api"; | ||
import { HomebridgeHomeWizardEnergySocket } from "../platform"; | ||
import { PLATFORM_NAME } from "../settings"; | ||
import { TxtRecord } from "../api/types"; | ||
import { loggerMock } from "./mocks/logger"; | ||
import { vi } from "vitest"; | ||
|
||
jest.mock("bonjour-service"); | ||
|
||
// mock the config parameter | ||
const configMock = { | ||
platform: PLATFORM_NAME, | ||
}; | ||
|
||
const apiMock = new HomebridgeAPI(); | ||
|
||
const platform = new HomebridgeHomeWizardEnergySocket( | ||
loggerMock, | ||
configMock, | ||
apiMock | ||
); | ||
vi.mock("bonjour-service"); | ||
|
||
describe("platform", () => { | ||
it('should return true if api_enabled is "1"', () => { | ||
const txtRecordMock = { | ||
api_enabled: "1", | ||
} as TxtRecord; | ||
|
||
expect(platform.isDeviceApiEnabled(txtRecordMock)).toBe(true); | ||
expect( | ||
HomebridgeHomeWizardEnergySocket.prototype.isDeviceApiEnabled( | ||
txtRecordMock | ||
) | ||
).toBe(true); | ||
}); | ||
|
||
it('should return false if api_enabled is not "1"', () => { | ||
const txtRecordMock = { | ||
api_enabled: "0", | ||
} as TxtRecord; | ||
|
||
expect(platform.isDeviceApiEnabled(txtRecordMock)).toBe(false); | ||
expect( | ||
HomebridgeHomeWizardEnergySocket.prototype.isDeviceApiEnabled( | ||
txtRecordMock | ||
) | ||
).toBe(false); | ||
}); | ||
|
||
it('should return true if product_type is "HWE-SKT"', () => { | ||
const txtRecordMock = { | ||
product_type: "HWE-SKT", | ||
} as TxtRecord; | ||
|
||
expect(platform.isDeviceProductTypeSupported(txtRecordMock)).toBe(true); | ||
expect( | ||
HomebridgeHomeWizardEnergySocket.prototype.isDeviceProductTypeSupported( | ||
txtRecordMock | ||
) | ||
).toBe(true); | ||
}); | ||
|
||
it('should return false if product_type is not "HWE-SKT"', () => { | ||
const txtRecordMock = { | ||
product_type: "something-else", | ||
} as TxtRecord; | ||
|
||
expect(platform.isDeviceProductTypeSupported(txtRecordMock)).toBe(false); | ||
expect( | ||
HomebridgeHomeWizardEnergySocket.prototype.isDeviceProductTypeSupported( | ||
txtRecordMock | ||
) | ||
).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { defineConfig } from "vitest/config"; | ||
import path from "path"; | ||
|
||
export default defineConfig({ | ||
test: { | ||
globals: true, | ||
environment: "node", | ||
setupFiles: ["./vitest.setup.ts"], | ||
}, | ||
resolve: { | ||
alias: [ | ||
{ | ||
find: "@", | ||
replacement: path.resolve(__dirname, "src"), | ||
}, | ||
], | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { server } from "src/api/mocks/server"; | ||
import { vi } from "vitest"; | ||
|
||
beforeAll(() => { | ||
// Establish API mocking before all tests. | ||
server.listen(); | ||
}); | ||
|
||
afterEach(() => { | ||
// Reset any MSW request handlers that we may add during the tests, | ||
// so they don't affect other tests. | ||
server.resetHandlers(); | ||
|
||
vi.clearAllMocks(); | ||
}); | ||
|
||
afterAll(() => { | ||
// Clean up after the tests are finished. | ||
server.close(); | ||
}); |