@testspectra/react-native 1.3.2 → 1.3.4
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/dist/index.js +40 -10
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1460,7 +1460,14 @@ function createElementActions(selector, index) {
|
|
|
1460
1460
|
if (options?.clearFirst) {
|
|
1461
1461
|
await clearValue();
|
|
1462
1462
|
}
|
|
1463
|
-
|
|
1463
|
+
const d = driver();
|
|
1464
|
+
if (typeof d.typeText !== "function") {
|
|
1465
|
+
await setValue(value);
|
|
1466
|
+
return;
|
|
1467
|
+
}
|
|
1468
|
+
return trackStep("action", { type: "action", key: "type", target: selector, args: [value] }, async () => {
|
|
1469
|
+
await d.typeText(selector, value, index);
|
|
1470
|
+
});
|
|
1464
1471
|
}
|
|
1465
1472
|
async function clearValue() {
|
|
1466
1473
|
return trackStep("action", { type: "action", key: "clear", target: selector, args: [] }, async () => {
|
|
@@ -1681,8 +1688,9 @@ function createMockHandle(rule, release) {
|
|
|
1681
1688
|
respondWith: async (newFixture, newOptions = {}) => {
|
|
1682
1689
|
const newObj = newFixture;
|
|
1683
1690
|
rule.response = newObj && newObj.body !== void 0 ? newObj.body : newFixture;
|
|
1684
|
-
|
|
1685
|
-
|
|
1691
|
+
const envelopeStatus = readMockEnvelope(newObj)?.statusCode;
|
|
1692
|
+
if (newOptions.statusCode || newObj && newObj.statusCode || envelopeStatus) {
|
|
1693
|
+
rule.statusCode = newOptions.statusCode || newObj?.statusCode || envelopeStatus || 200;
|
|
1686
1694
|
}
|
|
1687
1695
|
if (newOptions.headers || newObj && newObj.headers) {
|
|
1688
1696
|
rule.headers = newOptions.headers || newObj?.headers;
|
|
@@ -1695,7 +1703,7 @@ function createMockHandle(rule, release) {
|
|
|
1695
1703
|
respondOnce: async (newFixture, newOptions = {}) => {
|
|
1696
1704
|
const newObj = newFixture;
|
|
1697
1705
|
const resp = newObj && newObj.body !== void 0 ? newObj.body : newFixture;
|
|
1698
|
-
const statusCode = newOptions.statusCode || newObj && newObj.statusCode || rule.statusCode || 200;
|
|
1706
|
+
const statusCode = newOptions.statusCode || newObj && newObj.statusCode || readMockEnvelope(newObj)?.statusCode || rule.statusCode || 200;
|
|
1699
1707
|
const headers = newOptions.headers || newObj && newObj.headers || rule.headers;
|
|
1700
1708
|
const delayMs = newOptions.delayMs ?? (newObj && newObj.delayMs) ?? rule.delayMs;
|
|
1701
1709
|
rule.respondOnceQueue.push({ response: resp, statusCode, headers, delayMs });
|
|
@@ -1822,6 +1830,27 @@ function recordMockCall(rule, request) {
|
|
|
1822
1830
|
}
|
|
1823
1831
|
return request;
|
|
1824
1832
|
}
|
|
1833
|
+
function readMockEnvelope(value) {
|
|
1834
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
|
|
1835
|
+
const record = value;
|
|
1836
|
+
const keys = Object.keys(record);
|
|
1837
|
+
if (keys.length === 0 || !keys.every((key) => ENVELOPE_KEYS.has(key))) return null;
|
|
1838
|
+
const status = typeof record.status === "number" ? record.status : record.statusCode;
|
|
1839
|
+
if (!("body" in record) && typeof status !== "number") return null;
|
|
1840
|
+
return { body: record.body ?? "", statusCode: status, headers: record.headers, delayMs: record.delayMs };
|
|
1841
|
+
}
|
|
1842
|
+
async function resolveMockResponse(rule, request) {
|
|
1843
|
+
const consumed = consumeMockResponse(rule);
|
|
1844
|
+
const value = typeof consumed.body === "function" ? await consumed.body(request) : consumed.body;
|
|
1845
|
+
const envelope = readMockEnvelope(value);
|
|
1846
|
+
if (!envelope) return { ...consumed, body: value };
|
|
1847
|
+
return {
|
|
1848
|
+
body: envelope.body,
|
|
1849
|
+
statusCode: envelope.statusCode ?? consumed.statusCode,
|
|
1850
|
+
headers: { ...consumed.headers, ...envelope.headers },
|
|
1851
|
+
delayMs: envelope.delayMs ?? consumed.delayMs
|
|
1852
|
+
};
|
|
1853
|
+
}
|
|
1825
1854
|
function consumeMockResponse(rule) {
|
|
1826
1855
|
if (rule.respondOnceQueue.length > 0) {
|
|
1827
1856
|
const queued = rule.respondOnceQueue.shift();
|
|
@@ -1854,11 +1883,12 @@ function mockResponseBodyText(body) {
|
|
|
1854
1883
|
if (typeof body === "object" && body !== null) return JSON.stringify(body);
|
|
1855
1884
|
return String(body ?? "");
|
|
1856
1885
|
}
|
|
1857
|
-
var DEFAULT_MOCK_RESPONSE_HEADERS;
|
|
1886
|
+
var ENVELOPE_KEYS, DEFAULT_MOCK_RESPONSE_HEADERS;
|
|
1858
1887
|
var init_mock_intercept = __esm({
|
|
1859
1888
|
"../../core/worker-runtime/src/dsl/mock_intercept.ts"() {
|
|
1860
1889
|
"use strict";
|
|
1861
1890
|
init_reporter();
|
|
1891
|
+
ENVELOPE_KEYS = /* @__PURE__ */ new Set(["status", "statusCode", "headers", "body", "delayMs"]);
|
|
1862
1892
|
DEFAULT_MOCK_RESPONSE_HEADERS = {
|
|
1863
1893
|
"Content-Type": "application/json; charset=utf-8",
|
|
1864
1894
|
"Access-Control-Allow-Origin": "*",
|
|
@@ -2120,7 +2150,7 @@ async function patchedFetch(origFetch, input, init) {
|
|
|
2120
2150
|
if (rule.aborted) {
|
|
2121
2151
|
throw new TypeError(`Spectra.intercept() aborted ${method} ${url} (${rule.abortReason || "Failed"})`);
|
|
2122
2152
|
}
|
|
2123
|
-
const consumed =
|
|
2153
|
+
const consumed = await resolveMockResponse(rule, intercepted);
|
|
2124
2154
|
if (consumed.delayMs && consumed.delayMs > 0) await sleep(consumed.delayMs);
|
|
2125
2155
|
return buildMockResponse(consumed);
|
|
2126
2156
|
}
|
|
@@ -2157,8 +2187,7 @@ function patchXMLHttpRequest() {
|
|
|
2157
2187
|
setTimeout(fireError, 0);
|
|
2158
2188
|
return;
|
|
2159
2189
|
}
|
|
2160
|
-
const
|
|
2161
|
-
const respond2 = () => {
|
|
2190
|
+
const respond2 = (consumed) => {
|
|
2162
2191
|
const bodyText = mockResponseBodyText(consumed.body);
|
|
2163
2192
|
Object.defineProperties(xhr, {
|
|
2164
2193
|
status: { value: consumed.statusCode, configurable: true },
|
|
@@ -2174,8 +2203,9 @@ function patchXMLHttpRequest() {
|
|
|
2174
2203
|
xhr.dispatchEvent?.(new Event("load"));
|
|
2175
2204
|
xhr.dispatchEvent?.(new Event("loadend"));
|
|
2176
2205
|
};
|
|
2177
|
-
|
|
2178
|
-
|
|
2206
|
+
void resolveMockResponse(rule, intercepted).then((consumed) => {
|
|
2207
|
+
setTimeout(() => respond2(consumed), consumed.delayMs && consumed.delayMs > 0 ? consumed.delayMs : 0);
|
|
2208
|
+
});
|
|
2179
2209
|
};
|
|
2180
2210
|
return xhr;
|
|
2181
2211
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@testspectra/react-native",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.4",
|
|
4
4
|
"description": "Native Android & iOS component test runner for React Native with TestSpectra Spectra.* DSL",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"testspectra",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"cross-spawn": "^7.0.6",
|
|
34
34
|
"esbuild": "^0.28.2",
|
|
35
|
-
"@testspectra/matchers": "1.3.
|
|
35
|
+
"@testspectra/matchers": "1.3.4"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"react": ">=18.0.0",
|