Skip to content

Commit

Permalink
test(functions): increase code coverage (#647)
Browse files Browse the repository at this point in the history
  • Loading branch information
grdsdev authored Jan 27, 2025
1 parent b13788c commit 3053599
Show file tree
Hide file tree
Showing 19 changed files with 635 additions and 180 deletions.
14 changes: 1 addition & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,10 @@ jobs:
run: sudo xcode-select -s /Applications/Xcode_${{ matrix.xcode }}.app
- name: List available devices
run: xcrun simctl list devices available
- name: Cache derived data
uses: actions/cache@v3
with:
path: |
~/.derivedData
key: |
deriveddata-xcodebuild-${{ matrix.platform }}-${{ matrix.xcode }}-${{ matrix.command }}-${{ hashFiles('**/Sources/**/*.swift', '**/Tests/**/*.swift') }}
restore-keys: |
deriveddata-xcodebuild-${{ matrix.platform }}-${{ matrix.xcode }}-${{ matrix.command }}-
- name: Set IgnoreFileSystemDeviceInodeChanges flag
run: defaults write com.apple.dt.XCBuild IgnoreFileSystemDeviceInodeChanges -bool YES
- name: Update mtime for incremental builds
uses: chetan/git-restore-mtime-action@v2
- run: make dot-env
- name: Debug
run: make XCODEBUILD_ARGUMENT="${{ matrix.command }}" CONFIG=Debug PLATFORM="${{ matrix.platform }}" xcodebuild
- name: Release
Expand All @@ -62,7 +52,6 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
file: lcov.info


xcodebuild:
name: xcodebuild (15)
runs-on: macos-14
Expand All @@ -77,6 +66,7 @@ jobs:
- { xcode: 15.2, platform: TVOS }
- { xcode: 15.2, platform: VISIONOS }
- { xcode: 15.2, platform: WATCHOS }
- { command: test, platform: WATCHOS }
include:
- { command: test, skip_release: 1 }
steps:
Expand Down Expand Up @@ -105,7 +95,6 @@ jobs:
run: defaults write com.apple.dt.XCBuild IgnoreFileSystemDeviceInodeChanges -bool YES
- name: Update mtime for incremental builds
uses: chetan/git-restore-mtime-action@v2
- run: make dot-env
- name: Debug
run: make XCODEBUILD_ARGUMENT="${{ matrix.command }}" CONFIG=Debug PLATFORM="${{ matrix.platform }}" xcodebuild
- name: Release
Expand All @@ -132,7 +121,6 @@ jobs:
# build-spm-linux-${{ matrix.swift-version }}-${{ hashFiles('**/Sources/**/*.swift', '**/Tests/**/*.swift', '**/Package.resolved') }}
# restore-keys: |
# build-spm-linux-${{ matrix.swift-version }}-
# - run: make dot-env
# - name: Run tests
# run: swift test --skip IntegrationTests

Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,5 @@ iOSInjectionProject/
# Environment
.env
Secrets.swift
DotEnv.swift
lcov.info
temp_coverage
47 changes: 46 additions & 1 deletion .swiftpm/xcode/xcshareddata/xcschemes/Supabase.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,52 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
codeCoverageEnabled = "YES"
onlyGenerateCoverageForSpecifiedTargets = "YES">
<CodeCoverageTargets>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "Auth"
BuildableName = "Auth"
BlueprintName = "Auth"
ReferencedContainer = "container:">
</BuildableReference>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "Functions"
BuildableName = "Functions"
BlueprintName = "Functions"
ReferencedContainer = "container:">
</BuildableReference>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "PostgREST"
BuildableName = "PostgREST"
BlueprintName = "PostgREST"
ReferencedContainer = "container:">
</BuildableReference>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "Realtime"
BuildableName = "Realtime"
BlueprintName = "Realtime"
ReferencedContainer = "container:">
</BuildableReference>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "Storage"
BuildableName = "Storage"
BlueprintName = "Storage"
ReferencedContainer = "container:">
</BuildableReference>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "Supabase"
BuildableName = "Supabase"
BlueprintName = "Supabase"
ReferencedContainer = "container:">
</BuildableReference>
</CodeCoverageTargets>
<Testables>
<TestableReference
skipped = "NO">
Expand Down
23 changes: 5 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,13 @@ endif

TEST_RUNNER_CI = $(CI)

export SECRETS
define SECRETS
enum DotEnv {
static let SUPABASE_URL = "$(SUPABASE_URL)"
static let SUPABASE_ANON_KEY = "$(SUPABASE_ANON_KEY)"
static let SUPABASE_SERVICE_ROLE_KEY = "$(SUPABASE_SERVICE_ROLE_KEY)"
}
endef

xcodebuild:
$(XCODEBUILD)

load-env:
@. ./scripts/load_env.sh

dot-env:
@echo "$$SECRETS" > Tests/IntegrationTests/DotEnv.swift

test-integration: dot-env
$(MAKE) TEST_PLAN=Integration xcodebuild
test-integration:
cd Tests/IntegrationTests && supabase start && supabase db reset
swift test --filter IntegrationTests
cd Tests/IntegrationTests && supabase stop

build-for-library-evolution:
swift build \
Expand Down Expand Up @@ -107,4 +94,4 @@ coverage:

define udid_for
$(shell xcrun simctl list devices available '$(1)' | grep '$(2)' | sort -r | head -1 | awk -F '[()]' '{ print $$(NF-3) }')
endef
endef
9 changes: 9 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
{
"pins" : [
{
"identity" : "mocker",
"kind" : "remoteSourceControl",
"location" : "https://github.com/WeTransfer/Mocker",
"state" : {
"revision" : "95fa785c751f6bc40c49e112d433c3acf8417a97",
"version" : "3.0.2"
}
},
{
"identity" : "swift-asn1",
"kind" : "remoteSourceControl",
Expand Down
35 changes: 24 additions & 11 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ let package = Package(
targets: ["Supabase", "Functions", "PostgREST", "Auth", "Realtime", "Storage"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-http-types.git", from: "1.3.0"),
.package(url: "https://github.com/apple/swift-crypto.git", "1.0.0"..<"4.0.0"),
.package(url: "https://github.com/apple/swift-http-types.git", from: "1.3.0"),
.package(url: "https://github.com/pointfreeco/swift-clocks", from: "1.0.0"),
.package(url: "https://github.com/pointfreeco/swift-concurrency-extras", from: "1.1.0"),
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "1.3.2"),
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.17.2"),
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.17.0"),
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.2.2"),
.package(url: "https://github.com/pointfreeco/swift-clocks", from: "1.0.0"),
.package(url: "https://github.com/WeTransfer/Mocker", from: "3.0.0"),
],
targets: [
.target(
Expand All @@ -39,6 +40,7 @@ let package = Package(
.product(name: "ConcurrencyExtras", package: "swift-concurrency-extras"),
.product(name: "HTTPTypes", package: "swift-http-types"),
.product(name: "Clocks", package: "swift-clocks"),
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
]
),
.testTarget(
Expand All @@ -60,11 +62,11 @@ let package = Package(
name: "AuthTests",
dependencies: [
.product(name: "CustomDump", package: "swift-custom-dump"),
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
.product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing"),
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
"Helpers",
"Auth",
"Helpers",
"TestHelpers",
],
exclude: [
Expand All @@ -82,12 +84,13 @@ let package = Package(
name: "FunctionsTests",
dependencies: [
.product(name: "ConcurrencyExtras", package: "swift-concurrency-extras"),
.product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing"),
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
"Functions",
"Mocker",
"TestHelpers",
],
exclude: ["__Snapshots__"]
]
),
.testTarget(
name: "IntegrationTests",
Expand All @@ -99,7 +102,10 @@ let package = Package(
"Supabase",
"TestHelpers",
],
resources: [.process("Fixtures")]
resources: [
.process("Fixtures"),
.process("supabase"),
]
),
.target(
name: "PostgREST",
Expand All @@ -111,11 +117,13 @@ let package = Package(
.testTarget(
name: "PostgRESTTests",
dependencies: [
.product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing"),
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
"Helpers",
"Mocker",
"PostgREST",
],
exclude: ["__Snapshots__"]
"TestHelpers",
]
),
.target(
name: "Realtime",
Expand All @@ -129,8 +137,8 @@ let package = Package(
name: "RealtimeTests",
dependencies: [
.product(name: "CustomDump", package: "swift-custom-dump"),
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
.product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing"),
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
"PostgREST",
"Realtime",
"TestHelpers",
Expand All @@ -149,6 +157,9 @@ let package = Package(
.product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing"),
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
"Storage",
],
resources: [
.copy("sadcat.jpg")
]
),
.target(
Expand All @@ -174,8 +185,10 @@ let package = Package(
name: "TestHelpers",
dependencies: [
.product(name: "ConcurrencyExtras", package: "swift-concurrency-extras"),
.product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing"),
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
"Auth",
"Mocker",
]
),
]
Expand Down
Loading

0 comments on commit 3053599

Please sign in to comment.