-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPackage.swift
More file actions
258 lines (256 loc) · 12.2 KB
/
Copy pathPackage.swift
File metadata and controls
258 lines (256 loc) · 12.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
// swift-tools-version:5.9
//
// Swift Package for native (Swift) unit tests of the NitroWebView library.
//
// The library is still shipped to React Native consumers via
// `NitroWebview.podspec`; this manifest only exists so `swift test` can
// exercise the iOS handlers on the macOS host. Neither `Package.swift` nor
// `iosTests/` ships to npm consumers (see `package.json#files`).
//
// Run tests:
// swift test
// ./iosTests/run-tests.sh
import PackageDescription
let package = Package(
name: "NitroWebViewNative",
platforms: [
// macOS host is enough for these unit tests — they run against
// protocol-seam spies, not a real WKWebView. iOS shipping is handled
// by the podspec.
.macOS(.v11),
],
targets: [
.testTarget(
name: "NitroWebViewDialogCompletionTests",
dependencies: ["NitroWebViewSource"],
path: "iosTests/Tests/NitroWebViewDialogCompletionTests"
),
.target(
name: "NitroWebViewSource",
path: "ios",
exclude: [
// `Bridge.h` is the only non-Swift artefact in `ios/` today.
"Bridge.h",
// `HybridNitroWebView.swift` depends on Nitro-generated bridge
// code (`HybridNitroWebViewSpec`, `NitroModules`) that is only
// resolved at CocoaPods install time, so it cannot participate
// in this SwiftPM host harness. The binding contract it
// implements is covered by
// `HybridNitroWebViewUIDelegateBindingTests` via a structural
// replica.
"HybridNitroWebView.swift",
"NitroWebViewDialogPresenter.swift",
],
sources: [
"NitroWebViewDialogCompletion.swift",
"NitroWebViewSourceHandler.swift",
"NitroWebViewMessageHandler.swift",
// Second WKScriptMessageHandler for the SPA history shim. Like the
// message handler it is Nitro-free (Foundation/WebKit only), so it
// compiles into this host harness and its stringify seam is tested
// by NitroWebViewHistoryHandlerTests.
"NitroWebViewHistoryHandler.swift",
"NitroWebViewErrorMapper.swift",
"NitroWebViewEvaluateJavaScriptHandler.swift",
// Extracted from `HybridNitroWebView` so it can be exercised on
// the macOS host without linking the Nitro/WKWebView-bound class.
"NitroWebViewCookieFilter.swift",
// Same rationale as the cookie filter — `HybridNitroWebView`
// can't be linked into this SwiftPM harness, so the parser lives
// standalone and is re-exposed on the hybrid class via
// `parseContentDispositionFilename(_:)`.
"NitroWebViewContentDispositionParser.swift",
// Native→web message-delivery statement builder + JS-source-string
// escaping. Standalone for the same reason — re-exposed on the
// hybrid via `HybridNitroWebView.postMessageScript(_:)`.
"NitroWebViewPostMessage.swift",
]
),
.testTarget(
name: "NitroWebViewSourceHandlerTests",
dependencies: ["NitroWebViewSource"],
path: "iosTests/Tests/NitroWebViewSourceHandlerTests"
),
.testTarget(
name: "NitroWebViewMessageHandlerTests",
dependencies: ["NitroWebViewSource"],
path: "iosTests/Tests/NitroWebViewMessageHandlerTests"
),
.testTarget(
name: "NitroWebViewErrorMapperTests",
dependencies: ["NitroWebViewSource"],
path: "iosTests/Tests/NitroWebViewErrorMapperTests"
),
.testTarget(
// Exercises the SPA history handler's dispatcher seam: a received
// nav-type string is forwarded to the NavStateDispatcher, and the
// body stringify coerces non-String bodies defensively.
name: "NitroWebViewHistoryHandlerTests",
dependencies: ["NitroWebViewSource"],
path: "iosTests/Tests/NitroWebViewHistoryHandlerTests"
),
.testTarget(
name: "NitroWebViewEvaluateJavaScriptHandlerTests",
dependencies: ["NitroWebViewSource"],
path: "iosTests/Tests/NitroWebViewEvaluateJavaScriptHandlerTests"
),
.testTarget(
// Asserts the file-upload `WKUIDelegate` binding contract on
// `HybridNitroWebView`. The real class depends on Nitro-generated
// bridge code only available at CocoaPods install time, so the
// test uses a `BindingProbe` whose init mirrors the production
// wiring step-for-step.
name: "HybridNitroWebViewUIDelegateBindingTests",
dependencies: ["NitroWebViewSource"],
path: "iosTests/Tests/HybridNitroWebViewUIDelegateBindingTests"
),
.testTarget(
// Runtime introspection guard that asserts no
// `runOpenPanelWith:initiatedByFrame:completionHandler:` (a
// macOS-only WKUIDelegate selector) is implemented on the
// production class. Uses a structural replica (`FileUploadProbe`)
// because the production class cannot be linked into this harness.
name: "HybridNitroWebViewFileUploadIntrospectionTests",
dependencies: ["NitroWebViewSource"],
path: "iosTests/Tests/HybridNitroWebViewFileUploadIntrospectionTests"
),
.testTarget(
// Exercises the host / path-prefix / secure-flag filter rules in
// `NitroWebViewCookieFilter` against real `HTTPCookie` instances.
// Mirrors the call path used by `HybridNitroWebView.getCookies(url:)`.
name: "HybridNitroWebViewGetCookiesFilterTests",
dependencies: ["NitroWebViewSource"],
path: "iosTests/Tests/HybridNitroWebViewGetCookiesFilterTests"
),
.testTarget(
// Unit-tests the iOS Swift header-merge function that combines
// `defaultHeaders` with per-request `source.headers` using
// `Dictionary(_:uniquingKeysWith:)` with a last-wins resolver
// (per-request keys override defaults on collision). Exercises a
// `HeaderMergeProbe` that mirrors the production implementation
// because the hybrid class cannot be linked into this harness.
name: "HybridNitroWebViewHeaderMergeTests",
dependencies: ["NitroWebViewSource"],
path: "iosTests/Tests/HybridNitroWebViewHeaderMergeTests"
),
.testTarget(
// Verifies that `HybridNitroWebView.setCookie(url:cookie:)`
// 1. applies documented defaults (domain → URL host, path → "/",
// expires divided by 1000, secure honored), and
// 2. persists the resulting `HTTPCookie` in `WKHTTPCookieStore`
// (observable via `getAllCookies(_:)`).
// Uses a `SetCookieProbe` against an isolated
// `WKWebsiteDataStore.nonPersistent()` because the hybrid class
// cannot be linked into this harness.
name: "HybridNitroWebViewSetCookieTests",
dependencies: ["NitroWebViewSource"],
path: "iosTests/Tests/HybridNitroWebViewSetCookieTests"
),
.testTarget(
// Verifies that `HybridNitroWebView.clearCookies()` invokes
// `WKWebsiteDataStore.default().removeData(ofTypes:
// [WKWebsiteDataTypeCookies], modifiedSince: .distantPast,
// completionHandler:)` and that pre-existing cookies are removed
// after the call completes. Uses a `ClearCookiesProbe` against an
// isolated `WKWebsiteDataStore.nonPersistent()`.
name: "HybridNitroWebViewClearCookiesTests",
dependencies: ["NitroWebViewSource"],
path: "iosTests/Tests/HybridNitroWebViewClearCookiesTests"
),
.testTarget(
// Exercises the Content-Disposition filename parser in
// `NitroWebViewContentDispositionParser` (which backs
// `HybridNitroWebView.parseContentDispositionFilename(_:)`).
// Covers RFC 5987 encoded, quoted plain, unquoted plain, and the
// missing-filename case.
name: "HybridNitroWebViewContentDispositionParserTests",
dependencies: ["NitroWebViewSource"],
path: "iosTests/Tests/HybridNitroWebViewContentDispositionParserTests"
),
.testTarget(
// Verifies that the URI branch of `HybridNitroWebView.applySource(_:)`
// forwards every merged header to `URLRequest` via
// `setValue(_:forHTTPHeaderField:)`. Uses an `ApplySourceWireUpProbe`
// that mirrors the production lines byte-for-byte (build URLRequest,
// merge headers, setValue loop) and captures the request instead of
// handing it to a real WKWebView — keeping the test free of WebKit
// dependencies. The production class is excluded because it depends
// on Nitro-generated bridge symbols only available at CocoaPods
// install time.
name: "HybridNitroWebViewApplySourceWireUpTests",
dependencies: ["NitroWebViewSource"],
path: "iosTests/Tests/HybridNitroWebViewApplySourceWireUpTests"
),
.testTarget(
// Exercises `HybridNitroWebView.shouldTreatAsDownload(response:
// canShowMIMEType:)` against the four cases (attachment header,
// inline header, missing header with unsupported MIME, supported
// inline MIME) plus close-cousin edges. Uses an
// `AttachmentDetectionProbe` that mirrors the production helper.
// The probe takes no dependencies beyond `Foundation` (used
// implicitly via `HTTPURLResponse`), so it does not technically
// need the `NitroWebViewSource` target — kept for consistency
// with the surrounding download/cookie/header test targets.
name: "HybridNitroWebViewAttachmentDetectionTests",
dependencies: ["NitroWebViewSource"],
path: "iosTests/Tests/HybridNitroWebViewAttachmentDetectionTests"
),
.testTarget(
// Exercises the navigation-interception plumbing introduced for
// `onShouldStartLoadWithRequest`:
// 1. `navigationType(from:)` raw -> spec-token mapping.
// 2. `shouldStartPayload(for:)` URL + mainDocumentURL + target
// frame construction.
// 3. The in-memory pending-decisions stash that survives until
// the JS Promise resolves (NO timeout — iOS parity with RNW).
// Uses local probe types that mirror the production helpers
// byte-for-byte because `HybridNitroWebView` cannot be linked into
// this SwiftPM harness.
name: "HybridNitroWebViewShouldStartTests",
dependencies: ["NitroWebViewSource"],
path: "iosTests/Tests/HybridNitroWebViewShouldStartTests"
),
.testTarget(
// cacheEnabled -> URLRequest.cachePolicy mapping; see the test file
// header for the mirror-probe rationale.
name: "HybridNitroWebViewCachePolicyTests",
dependencies: ["NitroWebViewSource"],
path: "iosTests/Tests/HybridNitroWebViewCachePolicyTests"
),
.testTarget(
// Exercises the native→web `postMessage` statement builder +
// JS-source-string escaping in `NitroWebViewPostMessage` (which backs
// `HybridNitroWebView.postMessageScript(_:)`). Asserts the emitted
// statement is valid JS, escapes U+2028/U+2029, and carries the
// payload verbatim — the Swift mirror of the TS oracle in
// `src/__tests__/post-message-escaping.test.ts`.
name: "HybridNitroWebViewPostMessageTests",
dependencies: ["NitroWebViewSource"],
path: "iosTests/Tests/HybridNitroWebViewPostMessageTests"
),
.testTarget(
// Exercises `HybridNitroWebView.httpError(from:)` — the 4xx/5xx
// main-frame HTTP-error mapper backing `onHttpError`. Uses an
// `HttpErrorProbe` that mirrors the production static helper (the
// production class cannot be linked into this SwiftPM harness). Covers
// 2xx/3xx → nil, 4xx/5xx → mapped, and the 400/599 boundaries.
name: "HybridNitroWebViewHttpErrorTests",
dependencies: ["NitroWebViewSource"],
path: "iosTests/Tests/HybridNitroWebViewHttpErrorTests"
),
.testTarget(
// Exercises the imperative-method + blob-download helpers:
// 1. `cacheDataTypes()` — the cache-only record set clearCache uses
// (disk + memory only, never cookies/localStorage).
// 2. `isBlobDownload(response:canShowMIMEType:)` — routes a blob:
// navigation response to WKDownloadDelegate.
// 3. `NavigationDelegate.blobDownloadDestination(suggestedFilename:)`
// — the unique, non-existent temp-file path a blob is written to.
// Uses probe mirrors because the production class cannot be linked
// into this SwiftPM host harness.
name: "HybridNitroWebViewImperativeMethodsTests",
dependencies: ["NitroWebViewSource"],
path: "iosTests/Tests/HybridNitroWebViewImperativeMethodsTests"
),
]
)