hass-taste-test 0.0.15 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +34 -11
- package/lib/integrations/playwright.d.ts +3 -2
- package/lib/integrations/playwright.js +5 -2
- package/lib/types.d.ts +2 -2
- package/package.json +20 -18
package/lib/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -99,11 +103,11 @@ class HomeAssistant {
|
|
|
99
103
|
await Promise.all([
|
|
100
104
|
this.findPort().then(() => this.writeYAMLConfiguration(config)),
|
|
101
105
|
this.setupVenv(),
|
|
102
|
-
fs.writeFile(this.path_cache(), JSON.stringify(this.cache)),
|
|
103
106
|
]);
|
|
107
|
+
await fs.writeFile(this.path_cache(), JSON.stringify(this.cache));
|
|
104
108
|
await releaseLock();
|
|
105
109
|
// Step 3: Start Home Assistant and onboard
|
|
106
|
-
this.process = (0, child_process_1.spawn)(this.path_hass(), ['-c', this.configDir, ...this.options.hassArgs], {
|
|
110
|
+
this.process = (0, child_process_1.spawn)(this.path_hass(), ['-c', this.configDir, '-v', ...this.options.hassArgs], {
|
|
107
111
|
stdio: 'inherit',
|
|
108
112
|
});
|
|
109
113
|
this.process.on('error', (e) => {
|
|
@@ -114,7 +118,7 @@ class HomeAssistant {
|
|
|
114
118
|
// Wait for Home Assistant to start, but quit early if the process exits
|
|
115
119
|
this.process.on('close', (code) => {
|
|
116
120
|
if (code != 0)
|
|
117
|
-
reject(new Error(`Home
|
|
121
|
+
reject(new Error(`Home Assistant exited with code ${code}`));
|
|
118
122
|
});
|
|
119
123
|
while (!(await this.isUp()))
|
|
120
124
|
await sleep();
|
|
@@ -207,7 +211,7 @@ class HomeAssistant {
|
|
|
207
211
|
const libs = await Promise.all(libFolders.map((f) => fs.readdir((0, path_1.join)(this.venvDir, 'lib', f, 'site-packages'))));
|
|
208
212
|
const homeAssistant = libs
|
|
209
213
|
.flat()
|
|
210
|
-
.map((f) => f.match(
|
|
214
|
+
.map((f) => f.match(/^homeassistant-(.*)\.dist-info/))
|
|
211
215
|
.find((f) => f !== null);
|
|
212
216
|
return homeAssistant ? homeAssistant[1] : null;
|
|
213
217
|
}
|
|
@@ -219,12 +223,27 @@ class HomeAssistant {
|
|
|
219
223
|
});
|
|
220
224
|
/** Complete onboarding and fetch short-lived access token */
|
|
221
225
|
async onboard() {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
226
|
+
let login;
|
|
227
|
+
for (let tries = 0; tries < 20; tries++) {
|
|
228
|
+
try {
|
|
229
|
+
login = await this.post('/api/onboarding/users', {
|
|
230
|
+
language: this.options.userLanguage,
|
|
231
|
+
name: this.options.userDisplayName,
|
|
232
|
+
username: this.options.username,
|
|
233
|
+
password: this.options.password,
|
|
234
|
+
});
|
|
235
|
+
if (login.auth_code)
|
|
236
|
+
break;
|
|
237
|
+
else
|
|
238
|
+
await sleep();
|
|
239
|
+
}
|
|
240
|
+
catch (e) {
|
|
241
|
+
console.warn(e);
|
|
242
|
+
await sleep();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (!login.auth_code)
|
|
246
|
+
throw new Error('No auth code found');
|
|
228
247
|
this.accessCode = login.auth_code;
|
|
229
248
|
await this.launchWebsocket(this.accessCode);
|
|
230
249
|
// Step through the onboarding pages
|
|
@@ -269,6 +288,8 @@ class HomeAssistant {
|
|
|
269
288
|
username: this.options.username,
|
|
270
289
|
password: this.options.password,
|
|
271
290
|
});
|
|
291
|
+
if (response.error)
|
|
292
|
+
throw new Error(`Login code returned with error ${response.error}`);
|
|
272
293
|
return response.result;
|
|
273
294
|
}
|
|
274
295
|
/** Login and create tokens and websocket */
|
|
@@ -286,6 +307,8 @@ class HomeAssistant {
|
|
|
286
307
|
body: params,
|
|
287
308
|
});
|
|
288
309
|
const tokens = (await response.json());
|
|
310
|
+
if (tokens.error)
|
|
311
|
+
throw new Error(`Tokens returned with error ${tokens.error}`);
|
|
289
312
|
this.accessToken = tokens.access_token;
|
|
290
313
|
const auth = new hass.Auth({
|
|
291
314
|
...tokens,
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { ElementHandle, Page, LaunchOptions } from 'playwright';
|
|
2
|
+
import { Browser, ElementHandle, Page, LaunchOptions, BrowserContext } from 'playwright';
|
|
3
3
|
import { BrowserIntegration, BrowserPage, DashboardOptions, DiffOptions } from '../types';
|
|
4
|
-
export
|
|
4
|
+
export type PlaywrightElement = ElementHandle<Node>;
|
|
5
5
|
export declare class PlaywrightBrowser implements BrowserIntegration<PlaywrightElement> {
|
|
6
6
|
private static browsers;
|
|
7
7
|
private browserName;
|
|
8
8
|
private browserPromise;
|
|
9
9
|
constructor(browserName: string, options?: LaunchOptions);
|
|
10
|
+
newPage(browser: Browser | BrowserContext): Promise<Page>;
|
|
10
11
|
open(url: string, options: DashboardOptions): Promise<PlaywrightPage>;
|
|
11
12
|
openInHeaded(url: string): Promise<void>;
|
|
12
13
|
close(): Promise<void>;
|
|
@@ -14,6 +14,9 @@ class PlaywrightBrowser {
|
|
|
14
14
|
this.browserName = browserName;
|
|
15
15
|
this.browserPromise = PlaywrightBrowser.browsers[browserName].launch(options);
|
|
16
16
|
}
|
|
17
|
+
async newPage(browser) {
|
|
18
|
+
return await browser.newPage();
|
|
19
|
+
}
|
|
17
20
|
async open(url, options) {
|
|
18
21
|
let browser = await this.browserPromise;
|
|
19
22
|
if (options) {
|
|
@@ -21,7 +24,7 @@ class PlaywrightBrowser {
|
|
|
21
24
|
colorScheme: options.colorScheme,
|
|
22
25
|
});
|
|
23
26
|
}
|
|
24
|
-
const page = await
|
|
27
|
+
const page = await this.newPage(browser);
|
|
25
28
|
await page.goto(url);
|
|
26
29
|
return new PlaywrightPage(page);
|
|
27
30
|
}
|
|
@@ -29,7 +32,7 @@ class PlaywrightBrowser {
|
|
|
29
32
|
const browser = await PlaywrightBrowser.browsers[this.browserName].launch({
|
|
30
33
|
headless: false,
|
|
31
34
|
});
|
|
32
|
-
const page = await
|
|
35
|
+
const page = await this.newPage(browser);
|
|
33
36
|
await page.goto(url);
|
|
34
37
|
await page.waitForEvent('close', { timeout: 0 });
|
|
35
38
|
}
|
package/lib/types.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export interface DiffOptions {
|
|
|
21
21
|
/** whether to strip attributes from Lit & Polymer with undefined values */
|
|
22
22
|
stripUndefinedAttributes: boolean;
|
|
23
23
|
}
|
|
24
|
-
export
|
|
24
|
+
export type DashboardOptions = Partial<{
|
|
25
25
|
colorScheme: 'light' | 'dark' | 'no-preference';
|
|
26
26
|
}>;
|
|
27
27
|
export interface BrowserIntegration<E> {
|
|
@@ -36,7 +36,7 @@ export interface BrowserPage<E> {
|
|
|
36
36
|
screenshot(element: E): Promise<Buffer>;
|
|
37
37
|
find(element: E, selector: string): Promise<E | null | undefined>;
|
|
38
38
|
}
|
|
39
|
-
export
|
|
39
|
+
export type LovelaceResourceType = 'css' | 'js' | 'module' | 'html';
|
|
40
40
|
export interface LovelaceDashboardMutableParams {
|
|
41
41
|
require_admin: boolean;
|
|
42
42
|
show_in_sidebar: boolean;
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hass-taste-test",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Integration testing for Home Assistant cards",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "jest && ava",
|
|
8
|
-
"prepare": "husky install"
|
|
8
|
+
"prepare": "husky install",
|
|
9
|
+
"prepublishOnly": "tsc"
|
|
9
10
|
},
|
|
10
11
|
"bin": {
|
|
11
12
|
"hass-taste-test": "lib/bin.js"
|
|
@@ -14,26 +15,27 @@
|
|
|
14
15
|
"homepage": "https://github.com/rianadon/hass-taste-test#readme",
|
|
15
16
|
"license": "AGPL-3.0-or-later",
|
|
16
17
|
"dependencies": {
|
|
17
|
-
"home-assistant-js-websocket": "^
|
|
18
|
+
"home-assistant-js-websocket": "^8.0.1",
|
|
18
19
|
"node-fetch": "^2.6.1",
|
|
19
|
-
"proper-lockfile": "^4.1.2"
|
|
20
|
+
"proper-lockfile": "^4.1.2",
|
|
21
|
+
"ws": "^8.11.0"
|
|
20
22
|
},
|
|
21
23
|
"devDependencies": {
|
|
22
|
-
"@types/jest": "^
|
|
23
|
-
"@types/jest-image-snapshot": "^
|
|
24
|
-
"@types/node-fetch": "^2.
|
|
24
|
+
"@types/jest": "^29.2.4",
|
|
25
|
+
"@types/jest-image-snapshot": "^6.1.0",
|
|
26
|
+
"@types/node-fetch": "^2.6.2",
|
|
25
27
|
"@types/proper-lockfile": "^4.1.2",
|
|
26
|
-
"@types/ws": "^8.
|
|
27
|
-
"ava": "^
|
|
28
|
-
"husky": "^
|
|
29
|
-
"jest": "^
|
|
30
|
-
"jest-image-snapshot": "^
|
|
31
|
-
"lint-staged": "^
|
|
32
|
-
"playwright": "^1.
|
|
33
|
-
"prettier": "^2.
|
|
34
|
-
"ts-jest": "^
|
|
35
|
-
"ts-node": "^10.
|
|
36
|
-
"typescript": "^4.4
|
|
28
|
+
"@types/ws": "^8.5.3",
|
|
29
|
+
"ava": "^5.1.0",
|
|
30
|
+
"husky": "^8.0.2",
|
|
31
|
+
"jest": "^29.3.1",
|
|
32
|
+
"jest-image-snapshot": "^6.1.0",
|
|
33
|
+
"lint-staged": "^13.1.0",
|
|
34
|
+
"playwright": "^1.29.0",
|
|
35
|
+
"prettier": "^2.8.1",
|
|
36
|
+
"ts-jest": "^29.0.3",
|
|
37
|
+
"ts-node": "^10.9.1",
|
|
38
|
+
"typescript": "^4.9.4"
|
|
37
39
|
},
|
|
38
40
|
"prettier": {
|
|
39
41
|
"printWidth": 100,
|