diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md new file mode 100644 index 0000000..e89d8d0 --- /dev/null +++ b/DEVELOPMENT.md @@ -0,0 +1,76 @@ +# `cordova-plugin-meteor-webapp` Development + +## Running iOS Tests + +1) Start with a cloned copy of the `cordova-plugin-meteor-webapp` repo: + +``` +cd ~ +git clone https://github.com/meteor/cordova-plugin-meteor-webapp.git +``` + +2) Make sure the `GCDWebServer` submodule is pulled in: + +``` +cd cordova-plugin-meteor-webapp +git submodule update --init --recursive +``` + +3) Create a new test Cordova app: + +``` +cd ~ +cordova create test-app +``` + +4) Add the `cordova-plugin-meteor-webapp`, `cordova-plugin-meteor-webapp-tests`, and `cordova-plugin-test-framework` plugins: + +``` +cd test-app +cordova plugin add https://github.com/apache/cordova-plugin-test-framework.git +cordova plugin add ../cordova-plugin-meteor-webapp/ +cordova plugin add ../cordova-plugin-meteor-webapp/tests +``` + +5) Add the `ios` platform: + +``` +cordova platform add ios +``` + +6) Add a [`build.json`](https://cordova.apache.org/docs/en/latest/guide/platforms/ios/#using-buildjson) file to the root of your `test-app`, that includes your Apple Developer Team ID: + +```json +{ + "ios": { + "debug": { + "developmentTeam": "ABC123DEF456" + }, + "release": { + "developmentTeam": "ABC123DEF456", + "codeSignIdentity": "iPhone Developer", + "packageType": "ad-hoc" + } + } +} +``` + +7) Update the `test-app`'s `config.xml` to point to the test runner: + +Change + +```xml + +``` + +to + +```xml + +``` + +8) Run the tests on a device or using the iOS emulator: + +``` +cordova emulate ios +``` diff --git a/tests/package.json b/tests/package.json new file mode 100644 index 0000000..f227b7f --- /dev/null +++ b/tests/package.json @@ -0,0 +1,24 @@ +{ + "name": "cordova-plugin-meteor-webapptests", + "version": "1.3.1", + "cordova": { + "id": "cordova-plugin-meteor-webapp-tests", + "platforms": [ + "android", + "ios" + ] + }, + "repository": { + "type": "git", + "url": "https://github.com/meteor/cordova-plugin-meteor-webapp" + }, + "keywords": [ + "cordova", + "meteor", + "ecosystem:cordova", + "cordova-android", + "cordova-ios" + ], + "author": "Meteor Development Group", + "license": "MIT" +} diff --git a/tests/plugin.xml b/tests/plugin.xml index e427429..52765cc 100644 --- a/tests/plugin.xml +++ b/tests/plugin.xml @@ -1,7 +1,7 @@ + version="1.3.1"> Meteor Webapp Tests Meteor Development Group MIT @@ -31,7 +31,7 @@ - + diff --git a/tests/src/ios/WebAppMockRemoteServer.swift b/tests/src/ios/WebAppMockRemoteServer.swift index cb2fde6..0fb9405 100644 --- a/tests/src/ios/WebAppMockRemoteServer.swift +++ b/tests/src/ios/WebAppMockRemoteServer.swift @@ -1,11 +1,11 @@ extension Data { func SHA1() -> String { var digest = [UInt8](repeating: 0, count: Int(CC_SHA1_DIGEST_LENGTH)) - + withUnsafeBytes { (bytes) -> Void in CC_SHA1(bytes, CC_LONG(count), &digest) } - + var hexString = "" for index in 0.. GCDWebServerRequest! in if requestMethod != "GET" { return nil } - if !(URLPath?.hasPrefix(basePath))! { return nil } + if !(URLPath.hasPrefix(basePath)) { return nil } let request = GCDWebServerRequest(method: requestMethod, url: requestURL, headers: requestHeaders, path: URLPath, query: URLQuery) return request }) { (request) -> GCDWebServerResponse! in - let URLPath = request?.path.substring(from: basePath.endIndex) - let fileURL = self.versionDirectoryURL.appendingPathComponent(URLPath!) + let URLPath = request.path.substring(from: basePath.endIndex) + let fileURL = self.versionDirectoryURL.appendingPathComponent(URLPath) var response: GCDWebServerResponse var isDirectory = ObjCBool(false) if fileManager.fileExists(atPath: fileURL.path, isDirectory: &isDirectory) && !isDirectory.boolValue { - response = GCDWebServerFileResponse(file: fileURL.path) + response = GCDWebServerFileResponse(file: fileURL.path)! let fileHash = (try! Data(contentsOf: fileURL)).SHA1() response.eTag = "\"\(fileHash)\"" - } else if request?.query["meteor_dont_serve_index"] == nil { + } else if request.query!["meteor_dont_serve_index"] == nil { let indexFileURL = self.versionDirectoryURL.appendingPathComponent("index.html") - response = GCDWebServerFileResponse(file: indexFileURL.path) + response = GCDWebServerFileResponse(file: indexFileURL.path)! } else { response = GCDWebServerResponse(statusCode: GCDWebServerClientErrorHTTPStatusCode.httpStatusCode_NotFound.rawValue) }