diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..5a91fc9 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +# Apply to all files +[*] +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +# Ruby specific rules +[{*.rb,Fastfile,Gemfile}] +indent_style = space +indent_size = 2 + +[*.{swift,h,m}] +indent_style = space +indent_size = 4 diff --git a/.github/workflows/ios.yml b/.github/workflows/ios.yml index e715ef5..1e176e3 100644 --- a/.github/workflows/ios.yml +++ b/.github/workflows/ios.yml @@ -34,11 +34,4 @@ jobs: with: xcode-version: ${{ matrix.xcode }} - name: Build and Test - run: | - xcodebuild test \ - -project Demo/ParselyDemo.xcodeproj \ - -scheme ParselyDemo \ - -sdk iphonesimulator \ - -destination 'platform=iOS Simulator,name=iPhone 14,OS=latest' \ - | xcpretty \ - && exit ${PIPESTATUS[0]} + run: make test diff --git a/.gitignore b/.gitignore index 58f360b..a08e021 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,7 @@ xcuserdata/* # Ruby tooling vendor/bundle + + +# SwiftLint Remote Config Cache +.swiftlint/RemoteConfigCache \ No newline at end of file diff --git a/.swiftlint.yml b/.swiftlint.yml new file mode 100644 index 0000000..81eecbd --- /dev/null +++ b/.swiftlint.yml @@ -0,0 +1,7 @@ +swiftlint_version: 0.57.0 + +parent_config: https://raw.githubusercontent.com/Automattic/swiftlint-config/b497131f8d0fddbf3b23278cfc4ef8d86c9bcb20/.swiftlint.yml +remote_timeout: 10.0 + +excluded: + - .build diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e48ec50 --- /dev/null +++ b/Makefile @@ -0,0 +1,22 @@ +# TODO: Use newer Sim. Sticking with it at the moment because we know it works in the existing GitHub action setup. +SIMULATOR_NAME ?= iPhone 14 +SIMULATOR_OS ?= latest +XCODE_PATH ?= /Applications/Xcode.app + +# Convenience to open the lib and demo project with Xcode, given it's not in the root. +open: + open -a $(XCODE_PATH) ./Demo/ParselyDemo.xcodeproj + +# TODO: Move off xcpretty to xcbeautify. Sticking with it at the moment because we know it works in the existing GitHub action setup. +test: + set -o pipefail \ + && xcodebuild test \ + -project Demo/ParselyDemo.xcodeproj \ + -scheme ParselyDemo \ + -sdk iphonesimulator \ + -destination 'platform=iOS Simulator,name=$(SIMULATOR_NAME),OS=$(SIMULATOR_OS)' \ + | xcpretty + +# TODO: Add automation to set up SwiftLint +format: + swiftlint --fix --format diff --git a/Sources/Track.swift b/Sources/Track.swift index 9292c73..94ae2e8 100644 --- a/Sources/Track.swift +++ b/Sources/Track.swift @@ -22,8 +22,7 @@ class Track { parselyTracker.startFlushTimer(); pixel.beacon(event: event) - os_log("Sending an event from Track", log: OSLog.tracker, type:.debug) - dump(event.toDict()) + os_log_sending_event(event) } func pageview(url: String, urlref: String = "", metadata: ParselyMetadata?, extra_data: Dictionary?, idsite: String) { @@ -82,3 +81,18 @@ class Track { videoManager.sendHeartbeats() } } + +/// Utitlity to log sending event with a dump of the event. +private func os_log_sending_event(_ event: Event, log: OSLog = .tracker, type: OSLogType = .debug) { + var eventDump = DumpOutput() + dump(event.toDict(), to: &eventDump) + os_log("Sending an event from Track:\n%@", log: log, type: type, eventDump.content) +} + +private struct DumpOutput: TextOutputStream { + private(set) var content = "" + + mutating func write(_ string: String) { + content.append(string) + } +} diff --git a/Tests/EngagedTimeTests.swift b/Tests/EngagedTimeTests.swift index fa4bd27..c5a9e31 100644 --- a/Tests/EngagedTimeTests.swift +++ b/Tests/EngagedTimeTests.swift @@ -6,6 +6,10 @@ class EngagedTimeTests: ParselyTestCase { let testUrl: String = "http://parsely-stuff.com" + func testFailOnPurpose() { + XCTAssert(false) + } + func testHeartbeatFn() { let parsely = makePareslyTracker() let engagedTime = EngagedTime(trackerInstance: parsely)