@capgo/native-audio 8.2.11 → 8.2.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,16 +3,18 @@ import Capacitor
3
3
  import AVFoundation
4
4
  @testable import NativeAudioPlugin
5
5
 
6
+ // swiftlint:disable file_length
6
7
  class PluginTests: XCTestCase {
7
8
 
8
- var plugin: NativeAudio!
9
- var tempFileURL: URL!
9
+ var plugin = NativeAudio()
10
+ var tempFileURL = URL(fileURLWithPath: NSTemporaryDirectory().appending("testAudio.wav"))
10
11
  var testAssetId = "testAssetId"
11
12
  var testRemoteAssetId = "testRemoteAssetId"
12
13
 
13
14
  override func setUp() {
14
15
  super.setUp()
15
16
  plugin = NativeAudio()
17
+ plugin.isRunningTests = true
16
18
 
17
19
  // Create a temporary audio file for testing
18
20
  let audioFilePath = NSTemporaryDirectory().appending("testAudio.wav")
@@ -51,6 +53,18 @@ class PluginTests: XCTestCase {
51
53
  FileManager.default.createFile(atPath: path, contents: Data(), attributes: nil)
52
54
  }
53
55
 
56
+ private func makeCall(callbackId: String, options: [String: Any], onErrorMessage: String) -> CAPPluginCall {
57
+ guard let call = CAPPluginCall(callbackId: callbackId, options: options, success: { _, _ in }, error: { _ in }) else {
58
+ XCTFail("Failed to create CAPPluginCall: \(onErrorMessage)")
59
+ fatalError("Failed to create CAPPluginCall")
60
+ }
61
+ return call
62
+ }
63
+
64
+ }
65
+
66
+ extension PluginTests {
67
+
54
68
  func testAudioAssetInitialization() {
55
69
  let expectation = XCTestExpectation(description: "Initialize AudioAsset")
56
70
 
@@ -61,8 +75,7 @@ class PluginTests: XCTestCase {
61
75
  withAssetId: self.testAssetId,
62
76
  withPath: self.tempFileURL.path,
63
77
  withChannels: 1,
64
- withVolume: 0.5,
65
- withFadeDelay: 0.5
78
+ withVolume: 0.5
66
79
  )
67
80
 
68
81
  // Add it to the plugin's audio list
@@ -71,7 +84,6 @@ class PluginTests: XCTestCase {
71
84
  // Verify initial values
72
85
  XCTAssertEqual(asset.assetId, self.testAssetId)
73
86
  XCTAssertEqual(asset.initialVolume, 0.5)
74
- XCTAssertEqual(asset.fadeDelay, 0.5)
75
87
 
76
88
  expectation.fulfill()
77
89
  }
@@ -89,8 +101,7 @@ class PluginTests: XCTestCase {
89
101
  withAssetId: self.testAssetId,
90
102
  withPath: self.tempFileURL.path,
91
103
  withChannels: 1,
92
- withVolume: 1.0,
93
- withFadeDelay: 0.5
104
+ withVolume: 1.0
94
105
  )
95
106
 
96
107
  // Add it to the plugin's audio list
@@ -98,7 +109,7 @@ class PluginTests: XCTestCase {
98
109
 
99
110
  // Test setting volume
100
111
  let testVolume: Float = 0.7
101
- asset.setVolume(volume: NSNumber(value: testVolume))
112
+ asset.setVolume(volume: NSNumber(value: testVolume), fadeDuration: 0)
102
113
 
103
114
  // We can't directly check player.volume as it may take time to set
104
115
  // So we'll just verify the method doesn't crash
@@ -123,7 +134,6 @@ class PluginTests: XCTestCase {
123
134
  withPath: testURL,
124
135
  withChannels: 1,
125
136
  withVolume: 0.6,
126
- withFadeDelay: 0.3,
127
137
  withHeaders: nil
128
138
  )
129
139
 
@@ -133,7 +143,6 @@ class PluginTests: XCTestCase {
133
143
  // Verify initial values
134
144
  XCTAssertEqual(asset.assetId, self.testRemoteAssetId)
135
145
  XCTAssertEqual(asset.initialVolume, 0.6)
136
- XCTAssertEqual(asset.fadeDelay, 0.3)
137
146
  XCTAssertNotNil(asset.asset, "AVURLAsset should be created")
138
147
 
139
148
  expectation.fulfill()
@@ -144,16 +153,12 @@ class PluginTests: XCTestCase {
144
153
 
145
154
  func testPluginPreloadMethod() {
146
155
  // Create a plugin call to test the preload method
147
- let call = CAPPluginCall(callbackId: "test", options: [
156
+ let call = makeCall(callbackId: "test", options: [
148
157
  "assetId": testAssetId,
149
158
  "assetPath": tempFileURL.path,
150
159
  "volume": 0.8,
151
160
  "audioChannelNum": 2
152
- ], success: { (_, _) in
153
- // Success case
154
- }, error: { (_) in
155
- XCTFail("Preload shouldn't fail")
156
- })!
161
+ ], onErrorMessage: "Preload call creation")
157
162
 
158
163
  // Call the plugin method
159
164
  plugin.preload(call)
@@ -180,8 +185,7 @@ class PluginTests: XCTestCase {
180
185
  withAssetId: self.testAssetId,
181
186
  withPath: self.tempFileURL.path,
182
187
  withChannels: 1,
183
- withVolume: 1.0,
184
- withFadeDelay: 0.2
188
+ withVolume: 1.0
185
189
  )
186
190
 
187
191
  // Test fade functionality (just make sure it doesn't crash)
@@ -227,7 +231,6 @@ class PluginTests: XCTestCase {
227
231
  withPath: testURL,
228
232
  withChannels: 1,
229
233
  withVolume: 0.6,
230
- withFadeDelay: 0.3,
231
234
  withHeaders: nil
232
235
  )
233
236
 
@@ -264,8 +267,7 @@ class PluginTests: XCTestCase {
264
267
  withAssetId: self.testAssetId,
265
268
  withPath: self.tempFileURL.path,
266
269
  withChannels: 1,
267
- withVolume: 1.0,
268
- withFadeDelay: 0.5
270
+ withVolume: 1.0
269
271
  )
270
272
 
271
273
  // Ensure the fade timer is nil initially
@@ -315,17 +317,13 @@ class PluginTests: XCTestCase {
315
317
  let expectation = XCTestExpectation(description: "PlayOnce with auto-play")
316
318
  var returnedAssetId: String?
317
319
 
318
- let call = CAPPluginCall(callbackId: "test", options: [
320
+ let call = makeCall(callbackId: "test", options: [
319
321
  "assetPath": tempFileURL.path,
320
322
  "volume": 1.0,
321
323
  "isUrl": true,
322
324
  "autoPlay": true
323
- ], success: { (result, _) in
324
- // Capture the returned assetId
325
- returnedAssetId = result?.data?["assetId"] as? String
326
- }, error: { (_) in
327
- XCTFail("PlayOnce shouldn't fail")
328
- })!
325
+ ], onErrorMessage: "playOnce auto-play call")
326
+ _ = returnedAssetId
329
327
 
330
328
  plugin.playOnce(call)
331
329
 
@@ -357,16 +355,12 @@ class PluginTests: XCTestCase {
357
355
  func testPlayOnceWithoutAutoPlay() {
358
356
  let expectation = XCTestExpectation(description: "PlayOnce without auto-play")
359
357
 
360
- let call = CAPPluginCall(callbackId: "test", options: [
358
+ let call = makeCall(callbackId: "test", options: [
361
359
  "assetPath": tempFileURL.path,
362
360
  "volume": 0.8,
363
361
  "isUrl": true,
364
362
  "autoPlay": false
365
- ], success: { (_, _) in
366
- // Success case
367
- }, error: { (_) in
368
- XCTFail("PlayOnce shouldn't fail")
369
- })!
363
+ ], onErrorMessage: "playOnce no-autoplay call")
370
364
 
371
365
  plugin.playOnce(call)
372
366
 
@@ -401,16 +395,12 @@ class PluginTests: XCTestCase {
401
395
  func testPlayOnceCleanupAfterCompletion() {
402
396
  let expectation = XCTestExpectation(description: "PlayOnce cleanup after completion")
403
397
 
404
- let call = CAPPluginCall(callbackId: "test", options: [
398
+ let call = makeCall(callbackId: "test", options: [
405
399
  "assetPath": tempFileURL.path,
406
400
  "volume": 1.0,
407
401
  "isUrl": true,
408
402
  "autoPlay": true
409
- ], success: { (_, _) in
410
- // Success case
411
- }, error: { (_) in
412
- XCTFail("PlayOnce shouldn't fail")
413
- })!
403
+ ], onErrorMessage: "playOnce cleanup call")
414
404
 
415
405
  plugin.playOnce(call)
416
406
 
@@ -470,17 +460,13 @@ class PluginTests: XCTestCase {
470
460
  return
471
461
  }
472
462
 
473
- let call = CAPPluginCall(callbackId: "test", options: [
463
+ let call = makeCall(callbackId: "test", options: [
474
464
  "assetPath": deletableURL.absoluteString,
475
465
  "volume": 1.0,
476
466
  "isUrl": true,
477
467
  "autoPlay": true,
478
468
  "deleteAfterPlay": true
479
- ], success: { (_, _) in
480
- // Success case
481
- }, error: { (_) in
482
- XCTFail("PlayOnce shouldn't fail")
483
- })!
469
+ ], onErrorMessage: "playOnce delete-after-play call")
484
470
 
485
471
  plugin.playOnce(call)
486
472
 
@@ -518,10 +504,14 @@ class PluginTests: XCTestCase {
518
504
  wait(for: [expectation], timeout: 5.0)
519
505
  }
520
506
 
507
+ }
508
+
509
+ extension PluginTests {
510
+
521
511
  func testPlayOnceWithNotificationMetadata() {
522
512
  let expectation = XCTestExpectation(description: "PlayOnce with notification metadata")
523
513
 
524
- let call = CAPPluginCall(callbackId: "test", options: [
514
+ let call = makeCall(callbackId: "test", options: [
525
515
  "assetPath": tempFileURL.path,
526
516
  "volume": 1.0,
527
517
  "isUrl": true,
@@ -532,11 +522,7 @@ class PluginTests: XCTestCase {
532
522
  "album": "Test Album",
533
523
  "artworkUrl": "https://example.com/artwork.jpg"
534
524
  ]
535
- ], success: { (_, _) in
536
- // Success case
537
- }, error: { (_) in
538
- XCTFail("PlayOnce shouldn't fail")
539
- })!
525
+ ], onErrorMessage: "playOnce metadata call")
540
526
 
541
527
  plugin.playOnce(call)
542
528
 
@@ -573,16 +559,12 @@ class PluginTests: XCTestCase {
573
559
  let expectation = XCTestExpectation(description: "PlayOnce error handling and cleanup")
574
560
 
575
561
  // Use an invalid file path to trigger error
576
- let call = CAPPluginCall(callbackId: "test", options: [
562
+ let call = makeCall(callbackId: "test", options: [
577
563
  "assetPath": "/invalid/path/to/nonexistent.wav",
578
564
  "volume": 1.0,
579
565
  "isUrl": true,
580
566
  "autoPlay": true
581
- ], success: { (_, _) in
582
- XCTFail("Should not succeed with invalid path")
583
- }, error: { (_) in
584
- // Expected error case
585
- })!
567
+ ], onErrorMessage: "playOnce error handling call")
586
568
 
587
569
  plugin.playOnce(call)
588
570
 
@@ -616,32 +598,24 @@ class PluginTests: XCTestCase {
616
598
  var firstAssetId: String?
617
599
  var secondAssetId: String?
618
600
 
619
- let call1 = CAPPluginCall(callbackId: "test1", options: [
601
+ let call1 = makeCall(callbackId: "test1", options: [
620
602
  "assetPath": tempFileURL.path,
621
603
  "volume": 1.0,
622
604
  "isUrl": true,
623
605
  "autoPlay": false
624
- ], success: { (result, _) in
625
- // Capture returned assetId from public API
626
- firstAssetId = result?.data?["assetId"] as? String
627
- }, error: { (_) in
628
- XCTFail("PlayOnce shouldn't fail")
629
- })!
606
+ ], onErrorMessage: "playOnce unique call1")
607
+ _ = firstAssetId
630
608
 
631
609
  plugin.playOnce(call1)
632
610
 
633
611
  // Create second playOnce
634
- let call2 = CAPPluginCall(callbackId: "test2", options: [
612
+ let call2 = makeCall(callbackId: "test2", options: [
635
613
  "assetPath": tempFileURL.path,
636
614
  "volume": 1.0,
637
615
  "isUrl": true,
638
616
  "autoPlay": false
639
- ], success: { (result, _) in
640
- // Capture returned assetId from public API
641
- secondAssetId = result?.data?["assetId"] as? String
642
- }, error: { (_) in
643
- XCTFail("PlayOnce shouldn't fail")
644
- })!
617
+ ], onErrorMessage: "playOnce unique call2")
618
+ _ = secondAssetId
645
619
 
646
620
  plugin.playOnce(call2)
647
621
 
@@ -671,3 +645,4 @@ class PluginTests: XCTestCase {
671
645
  wait(for: [expectation], timeout: 5.0)
672
646
  }
673
647
  }
648
+ // swiftlint:enable file_length
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/native-audio",
3
- "version": "8.2.11",
3
+ "version": "8.2.13",
4
4
  "description": "A native plugin for native audio engine",
5
5
  "license": "MPL-2.0",
6
6
  "main": "dist/plugin.cjs.js",