@blankgrimoire/testing 1.2.0 → 1.3.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/README.md +6 -3
- package/dist/vmHarness.d.ts +9 -0
- package/dist/vmHarness.js +15 -22
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -40,9 +40,12 @@ const result = await harness.testTheme(html, 'https://example.org/', {
|
|
|
40
40
|
});
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
The harness scores the detection signature
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
The harness scores the detection signature with the same weights as the host
|
|
44
|
+
(`+30` generator, `+15` per selector, `+20` per script pattern), then calls the
|
|
45
|
+
runtime through its JSON dispatcher. `probePaths` never contribute to the score:
|
|
46
|
+
the host fetches them only to break a tie. When the theme is not detected the
|
|
47
|
+
harness returns only detection data. Adapters may be passed directly or as a
|
|
48
|
+
module-shaped `{ default: adapter }`.
|
|
46
49
|
|
|
47
50
|
## MockServer
|
|
48
51
|
|
package/dist/vmHarness.d.ts
CHANGED
|
@@ -27,6 +27,15 @@ export declare class VMHarness {
|
|
|
27
27
|
constructor(allowedHosts: string[], runtimeIIFE: string, adapterModule: {
|
|
28
28
|
default: ThemeAdapter;
|
|
29
29
|
} | ThemeAdapter);
|
|
30
|
+
/**
|
|
31
|
+
* Scores a detection signature exactly like the host:
|
|
32
|
+
* `+30` for a `metaGenerator` match, `+15` per matching selector and `+20`
|
|
33
|
+
* per matching `scriptSrc` pattern.
|
|
34
|
+
*
|
|
35
|
+
* `probePaths` never contribute here. The host fetches them only to break a
|
|
36
|
+
* tie between adapters that scored equally, and this harness scores a single
|
|
37
|
+
* adapter against a single document, so there is no tie to resolve.
|
|
38
|
+
*/
|
|
30
39
|
private score;
|
|
31
40
|
testTheme(html: string, url?: string, options?: ThemeTestOptions): Promise<ThemeTestResult>;
|
|
32
41
|
/** Exposes the bridge for tests that simulate network responses. */
|
package/dist/vmHarness.js
CHANGED
|
@@ -47,18 +47,27 @@ export class VMHarness {
|
|
|
47
47
|
}
|
|
48
48
|
this.runtime = runtime;
|
|
49
49
|
}
|
|
50
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Scores a detection signature exactly like the host:
|
|
52
|
+
* `+30` for a `metaGenerator` match, `+15` per matching selector and `+20`
|
|
53
|
+
* per matching `scriptSrc` pattern.
|
|
54
|
+
*
|
|
55
|
+
* `probePaths` never contribute here. The host fetches them only to break a
|
|
56
|
+
* tie between adapters that scored equally, and this harness scores a single
|
|
57
|
+
* adapter against a single document, so there is no tie to resolve.
|
|
58
|
+
*/
|
|
59
|
+
score(signature, document) {
|
|
51
60
|
let total = 0;
|
|
52
61
|
if (signature.metaGenerator) {
|
|
53
62
|
const meta = document.querySelector('meta[name="generator"]');
|
|
54
63
|
const content = meta?.getAttribute('content') ?? '';
|
|
55
64
|
if (new RegExp(signature.metaGenerator).test(content)) {
|
|
56
|
-
total +=
|
|
65
|
+
total += 30;
|
|
57
66
|
}
|
|
58
67
|
}
|
|
59
68
|
for (const selector of signature.selectors ?? []) {
|
|
60
69
|
if (document.querySelector(selector)) {
|
|
61
|
-
total +=
|
|
70
|
+
total += 15;
|
|
62
71
|
}
|
|
63
72
|
}
|
|
64
73
|
for (const pattern of signature.scriptSrc ?? []) {
|
|
@@ -68,33 +77,17 @@ export class VMHarness {
|
|
|
68
77
|
const src = script.getAttribute('src') ?? '';
|
|
69
78
|
return regex.test(src);
|
|
70
79
|
})) {
|
|
71
|
-
total +=
|
|
80
|
+
total += 20;
|
|
72
81
|
}
|
|
73
82
|
}
|
|
74
|
-
return
|
|
75
|
-
for (const probePath of signature.probePaths ?? []) {
|
|
76
|
-
try {
|
|
77
|
-
const response = await this.bridge.request({
|
|
78
|
-
url: new URL(probePath, url).toString(),
|
|
79
|
-
method: 'GET',
|
|
80
|
-
});
|
|
81
|
-
if (response.status >= 200 && response.status < 300) {
|
|
82
|
-
total += 3;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
catch {
|
|
86
|
-
// A failed probe simply contributes no score.
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return total;
|
|
90
|
-
})();
|
|
83
|
+
return total;
|
|
91
84
|
}
|
|
92
85
|
async testTheme(html, url = 'https://example.org/', options = {}) {
|
|
93
86
|
const dom = new JSDOM(html, { url });
|
|
94
87
|
const document = dom.window.document;
|
|
95
88
|
const window = dom.window;
|
|
96
89
|
const detectionSignature = this.adapter.detectionSignature;
|
|
97
|
-
const score =
|
|
90
|
+
const score = this.score(detectionSignature, document);
|
|
98
91
|
const base = {
|
|
99
92
|
detected: score >= detectionSignature.minScore,
|
|
100
93
|
score,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blankgrimoire/testing",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Node testing harness and mock server for BlankGrimoire theme adapters.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"jsdom": "^24.0.0",
|
|
29
|
-
"@blankgrimoire/
|
|
30
|
-
"@blankgrimoire/
|
|
29
|
+
"@blankgrimoire/types": "1.3.1",
|
|
30
|
+
"@blankgrimoire/runtime": "1.3.1"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "tsc -p tsconfig.json",
|