@tramvai/test-helpers 1.70.2 → 1.72.1
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.es.js +14 -1
- package/lib/index.js +14 -1
- package/lib/parseHtml.d.ts +1 -1
- package/package.json +3 -3
package/lib/index.es.js
CHANGED
|
@@ -5,6 +5,9 @@ import { createMockDi } from '@tramvai/test-mocks';
|
|
|
5
5
|
|
|
6
6
|
const parseHtml = (html, parserOptions = { blockTextElements: { script: false, style: false } }) => {
|
|
7
7
|
var _a;
|
|
8
|
+
if (!html) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
8
11
|
const parsed = parse(html, parserOptions);
|
|
9
12
|
return {
|
|
10
13
|
parsed,
|
|
@@ -17,10 +20,20 @@ const parseHtml = (html, parserOptions = { blockTextElements: { script: false, s
|
|
|
17
20
|
const renderFactory = (request) => async (path, { method = 'get', parserOptions, } = {}) => {
|
|
18
21
|
const response = await request(path, { method });
|
|
19
22
|
const parsed = parseHtml(response.text, parserOptions);
|
|
23
|
+
if (!parsed) {
|
|
24
|
+
throw new Error(`Cannot parse response
|
|
25
|
+
got response:
|
|
26
|
+
status: ${response.statusCode}
|
|
27
|
+
content: ${response.text}`);
|
|
28
|
+
}
|
|
20
29
|
return {
|
|
21
30
|
...parsed,
|
|
22
31
|
get initialState() {
|
|
23
|
-
|
|
32
|
+
var _a;
|
|
33
|
+
const parsedWithScripts = (_a = parseHtml(response.text, {})) === null || _a === void 0 ? void 0 : _a.parsed;
|
|
34
|
+
if (!parsedWithScripts) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
24
37
|
const scripts = parsedWithScripts.querySelectorAll('body > script');
|
|
25
38
|
for (const script of scripts) {
|
|
26
39
|
if (script.innerHTML.startsWith('var initialState')) {
|
package/lib/index.js
CHANGED
|
@@ -13,6 +13,9 @@ var supertest__default = /*#__PURE__*/_interopDefaultLegacy(supertest);
|
|
|
13
13
|
|
|
14
14
|
const parseHtml = (html, parserOptions = { blockTextElements: { script: false, style: false } }) => {
|
|
15
15
|
var _a;
|
|
16
|
+
if (!html) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
16
19
|
const parsed = nodeHtmlParser.parse(html, parserOptions);
|
|
17
20
|
return {
|
|
18
21
|
parsed,
|
|
@@ -25,10 +28,20 @@ const parseHtml = (html, parserOptions = { blockTextElements: { script: false, s
|
|
|
25
28
|
const renderFactory = (request) => async (path, { method = 'get', parserOptions, } = {}) => {
|
|
26
29
|
const response = await request(path, { method });
|
|
27
30
|
const parsed = parseHtml(response.text, parserOptions);
|
|
31
|
+
if (!parsed) {
|
|
32
|
+
throw new Error(`Cannot parse response
|
|
33
|
+
got response:
|
|
34
|
+
status: ${response.statusCode}
|
|
35
|
+
content: ${response.text}`);
|
|
36
|
+
}
|
|
28
37
|
return {
|
|
29
38
|
...parsed,
|
|
30
39
|
get initialState() {
|
|
31
|
-
|
|
40
|
+
var _a;
|
|
41
|
+
const parsedWithScripts = (_a = parseHtml(response.text, {})) === null || _a === void 0 ? void 0 : _a.parsed;
|
|
42
|
+
if (!parsedWithScripts) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
32
45
|
const scripts = parsedWithScripts.querySelectorAll('body > script');
|
|
33
46
|
for (const script of scripts) {
|
|
34
47
|
if (script.innerHTML.startsWith('var initialState')) {
|
package/lib/parseHtml.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/test-helpers",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.72.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"build-for-publish": "true"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@tramvai/core": "1.
|
|
22
|
-
"@tramvai/test-mocks": "1.
|
|
21
|
+
"@tramvai/core": "1.72.1",
|
|
22
|
+
"@tramvai/test-mocks": "1.72.1",
|
|
23
23
|
"@types/express": "^4.17.1",
|
|
24
24
|
"@types/supertest": "^2.0.11",
|
|
25
25
|
"express": "^4.17.1",
|