Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contribution Question - How to run plugin unit tests #2248

Closed
akanda-via opened this issue Nov 19, 2024 · 1 comment
Closed

Contribution Question - How to run plugin unit tests #2248

akanda-via opened this issue Nov 19, 2024 · 1 comment

Comments

@akanda-via
Copy link

Bug Report

I am new to iOS development and I see that the plugins here are using the SPM template rather than the CocoaPods one.
I would like to know how a contributor could add unit tests to any of these plugins and run them - ideally without a host/example app.

What is the expected developer setup and workflow when working on an iOS plugin in isolation?

Plugin(s)

All plugins in this repo, though using filesystem as an example.

Capacitor Version

Run from capacitor-plugins/filesystem

$ npx cap doctor
💊   Capacitor Doctor  💊 

Latest Dependencies:

  @capacitor/cli: 6.1.2
  @capacitor/core: 6.1.2
  @capacitor/android: 6.1.2
  @capacitor/ios: 6.1.2

Installed Dependencies:

  @capacitor/cli: not installed
  @capacitor/core: not installed
  @capacitor/android: not installed
  @capacitor/ios: not installed

Platform(s)

iOS

Current Behavior

No (obvious) way to run existing placeholder unit tests.

Expected Behavior

Some sort of test command like npm test or ./gradlew test equivalent to run all iOS unit tests and accompanying setup instructions (or a link to them).

Code Reproduction

cd filesystem
swift test

Results in errors like:

  1 | import Foundation
  2 | import Capacitor
    |        `- error: no such module 'Capacitor'
  3 | 
  4 | @objc public class Filesystem: NSObject {

Other Technical Details

I couldn't run the tests in Xcode as I get this build error:

/Users/akanda/Library/Developer/Xcode/DerivedData/filesystem-fycybfztoqcatdftjshlbslyvbwn/SourcePackages/artifacts/capacitor-swift-pm/Capacitor/Capacitor.xcframework:1:1 While building for macOS, no library for this platform was found in '/Users/akanda/Library/Developer/Xcode/DerivedData/filesystem-fycybfztoqcatdftjshlbslyvbwn/SourcePackages/artifacts/capacitor-swift-pm/Capacitor/Capacitor.xcframework'.

I could successfully run npm run verify:ios, but that only builds.

Additional Context

If this is something obvious, then perhaps all that's needed is a contributions documentation update.

@jcesarmobile
Copy link
Member

Please, don't use GitHub issues to ask questions, just to report issues.

You can ask questions on the Ionic Forums, on Ionic discord or on the discussions section of capacitor repository

But answering your question, doesn't look like swift test works because of Capacitor being a mixed source (Objective-C + Swift) project.
Opening the Package.swift and running the tests from Xcode works fine for me, I don't get the error you mentioned.
You could also run xcodebuild test -scheme CapacitorFilesystem -destination "platform=iOS Simulator,name=iPhone 16".

But none of the plugins have native tests to run, so that's why plugins don't have a npm test script to be run.
Only device plugin have tests at the moment and they are typescript tests, that can be run with npm run test, but no native tests.

@jcesarmobile jcesarmobile closed this as not planned Won't fix, can't repro, duplicate, stale Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants