hass-taste-test 0.0.13 → 0.1.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/README.md +19 -0
- package/lib/index.js +38 -11
- package/lib/integrations/get-diffable-html.js +1 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -83,6 +83,25 @@ it('Custom Card', async () => {
|
|
|
83
83
|
|
|
84
84
|
You may now consider customizing your Jest configuration using (`npx jest --init`), [learning more about Jest](https://jestjs.io/docs/getting-started), and browsing through the [examples](https://github.com/rianadon/hass-taste-test/tree/main/test)
|
|
85
85
|
|
|
86
|
+
## Developing
|
|
87
|
+
|
|
88
|
+
If you wish to make changes to this repository, follow these instructions. Tests are run with `ts-node`, so no recompilation of typescript is necessary.
|
|
89
|
+
|
|
90
|
+
1. Install dependencies
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
npm install
|
|
94
|
+
npx playwright install-deps
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
2. Run tests
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
npm run test
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
To update snapshots, use `npx jest -u` and `npx ava -u`.
|
|
104
|
+
|
|
86
105
|
### But I want to write my tests in TypeScript
|
|
87
106
|
|
|
88
107
|
Install [`ts-jest`](https://kulshekhar.github.io/ts-jest/docs/getting-started/installation/), `@types/jest`, and `@types/jest-image-snapshot` along with the other dependencies, then run `npx ts-jest config:init` to configure Jest for Typescript. Browse the [examples](https://github.com/rianadon/hass-taste-test/tree/main/test) for example tests; they are all written in TypeScript.
|
package/lib/index.js
CHANGED
|
@@ -99,19 +99,27 @@ class HomeAssistant {
|
|
|
99
99
|
await Promise.all([
|
|
100
100
|
this.findPort().then(() => this.writeYAMLConfiguration(config)),
|
|
101
101
|
this.setupVenv(),
|
|
102
|
-
fs.writeFile(this.path_cache(), JSON.stringify(this.cache)),
|
|
103
102
|
]);
|
|
103
|
+
await fs.writeFile(this.path_cache(), JSON.stringify(this.cache));
|
|
104
104
|
await releaseLock();
|
|
105
105
|
// Step 3: Start Home Assistant and onboard
|
|
106
|
-
this.process = (0, child_process_1.spawn)(this.path_hass(), ['-c', this.configDir, ...this.options.hassArgs], {
|
|
106
|
+
this.process = (0, child_process_1.spawn)(this.path_hass(), ['-c', this.configDir, '-v', ...this.options.hassArgs], {
|
|
107
107
|
stdio: 'inherit',
|
|
108
108
|
});
|
|
109
109
|
this.process.on('error', (e) => {
|
|
110
110
|
console.error(`----\nHome Assistant is having trouble starting. This is likely due to a problem with your virtual environment; try removing the venv folder at ${this.venvDir} and re-running hass-taste-test\n---`);
|
|
111
111
|
throw e;
|
|
112
112
|
});
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
await new Promise(async (resolve, reject) => {
|
|
114
|
+
// Wait for Home Assistant to start, but quit early if the process exits
|
|
115
|
+
this.process.on('close', (code) => {
|
|
116
|
+
if (code != 0)
|
|
117
|
+
reject(new Error(`Home Assistant exited with code ${code}`));
|
|
118
|
+
});
|
|
119
|
+
while (!(await this.isUp()))
|
|
120
|
+
await sleep();
|
|
121
|
+
resolve();
|
|
122
|
+
});
|
|
115
123
|
await this.onboard();
|
|
116
124
|
}
|
|
117
125
|
/** Write configuration.yaml */
|
|
@@ -199,7 +207,7 @@ class HomeAssistant {
|
|
|
199
207
|
const libs = await Promise.all(libFolders.map((f) => fs.readdir((0, path_1.join)(this.venvDir, 'lib', f, 'site-packages'))));
|
|
200
208
|
const homeAssistant = libs
|
|
201
209
|
.flat()
|
|
202
|
-
.map((f) => f.match(
|
|
210
|
+
.map((f) => f.match(/^homeassistant-(.*)\.dist-info/))
|
|
203
211
|
.find((f) => f !== null);
|
|
204
212
|
return homeAssistant ? homeAssistant[1] : null;
|
|
205
213
|
}
|
|
@@ -211,12 +219,27 @@ class HomeAssistant {
|
|
|
211
219
|
});
|
|
212
220
|
/** Complete onboarding and fetch short-lived access token */
|
|
213
221
|
async onboard() {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
222
|
+
let login;
|
|
223
|
+
for (let tries = 0; tries < 20; tries++) {
|
|
224
|
+
try {
|
|
225
|
+
login = await this.post('/api/onboarding/users', {
|
|
226
|
+
language: this.options.userLanguage,
|
|
227
|
+
name: this.options.userDisplayName,
|
|
228
|
+
username: this.options.username,
|
|
229
|
+
password: this.options.password,
|
|
230
|
+
});
|
|
231
|
+
if (login.auth_code)
|
|
232
|
+
break;
|
|
233
|
+
else
|
|
234
|
+
await sleep();
|
|
235
|
+
}
|
|
236
|
+
catch (e) {
|
|
237
|
+
console.warn(e);
|
|
238
|
+
await sleep();
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (!login.auth_code)
|
|
242
|
+
throw new Error('No auth code found');
|
|
220
243
|
this.accessCode = login.auth_code;
|
|
221
244
|
await this.launchWebsocket(this.accessCode);
|
|
222
245
|
// Step through the onboarding pages
|
|
@@ -261,6 +284,8 @@ class HomeAssistant {
|
|
|
261
284
|
username: this.options.username,
|
|
262
285
|
password: this.options.password,
|
|
263
286
|
});
|
|
287
|
+
if (response.error)
|
|
288
|
+
throw new Error(`Login code returned with error ${response.error}`);
|
|
264
289
|
return response.result;
|
|
265
290
|
}
|
|
266
291
|
/** Login and create tokens and websocket */
|
|
@@ -278,6 +303,8 @@ class HomeAssistant {
|
|
|
278
303
|
body: params,
|
|
279
304
|
});
|
|
280
305
|
const tokens = (await response.json());
|
|
306
|
+
if (tokens.error)
|
|
307
|
+
throw new Error(`Tokens returned with error ${tokens.error}`);
|
|
281
308
|
this.accessToken = tokens.access_token;
|
|
282
309
|
const auth = new hass.Auth({
|
|
283
310
|
...tokens,
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hass-taste-test",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.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
|
+
"publish": "tsc && npm publish"
|
|
9
10
|
},
|
|
10
11
|
"bin": {
|
|
11
12
|
"hass-taste-test": "lib/bin.js"
|