-- readCapacitorAppID --.
(t *testing.T)
| 2776 | // -- readCapacitorAppID --. |
| 2777 | |
| 2778 | func TestReadCapacitorAppID(t *testing.T) { |
| 2779 | t.Run("reads appId from capacitor.config.json", func(t *testing.T) { |
| 2780 | dir := t.TempDir() |
| 2781 | writeTestFile(t, dir, "capacitor.config.json", `{"appId":"com.example.ionic","appName":"MyApp"}`) |
| 2782 | assert.Equal(t, "com.example.ionic", readCapacitorAppID(dir)) |
| 2783 | }) |
| 2784 | |
| 2785 | t.Run("missing file returns empty", func(t *testing.T) { |
| 2786 | assert.Empty(t, readCapacitorAppID(t.TempDir())) |
| 2787 | }) |
| 2788 | |
| 2789 | t.Run("malformed JSON returns empty", func(t *testing.T) { |
| 2790 | dir := t.TempDir() |
| 2791 | writeTestFile(t, dir, "capacitor.config.json", `not valid json`) |
| 2792 | assert.Empty(t, readCapacitorAppID(dir)) |
| 2793 | }) |
| 2794 | |
| 2795 | t.Run("missing appId field returns empty", func(t *testing.T) { |
| 2796 | dir := t.TempDir() |
| 2797 | writeTestFile(t, dir, "capacitor.config.json", `{"appName":"MyApp"}`) |
| 2798 | assert.Empty(t, readCapacitorAppID(dir)) |
| 2799 | }) |
| 2800 | |
| 2801 | t.Run("reads appId from capacitor.config.ts (Capacitor v3+ default)", func(t *testing.T) { |
| 2802 | dir := t.TempDir() |
| 2803 | writeTestFile(t, dir, "capacitor.config.ts", `import { CapacitorConfig } from '@capacitor/cli'; |
| 2804 | const config: CapacitorConfig = { |
| 2805 | appId: 'com.example.tsapp', |
| 2806 | appName: 'MyApp', |
| 2807 | webDir: 'www', |
| 2808 | }; |
| 2809 | export default config;`) |
| 2810 | assert.Equal(t, "com.example.tsapp", readCapacitorAppID(dir)) |
| 2811 | }) |
| 2812 | |
| 2813 | t.Run("reads double-quoted appId from capacitor.config.ts", func(t *testing.T) { |
| 2814 | dir := t.TempDir() |
| 2815 | writeTestFile(t, dir, "capacitor.config.ts", `import { CapacitorConfig } from '@capacitor/cli'; |
| 2816 | const config: CapacitorConfig = { |
| 2817 | appId: "com.example.dqapp", |
| 2818 | appName: 'MyApp', |
| 2819 | }; |
| 2820 | export default config;`) |
| 2821 | assert.Equal(t, "com.example.dqapp", readCapacitorAppID(dir)) |
| 2822 | }) |
| 2823 | |
| 2824 | t.Run("skips commented appId line in capacitor.config.ts", func(t *testing.T) { |
| 2825 | dir := t.TempDir() |
| 2826 | writeTestFile(t, dir, "capacitor.config.ts", `import { CapacitorConfig } from '@capacitor/cli'; |
| 2827 | const config: CapacitorConfig = { |
| 2828 | // appId: 'com.example.old', |
| 2829 | appId: 'com.example.actual', |
| 2830 | }; |
| 2831 | export default config;`) |
| 2832 | assert.Equal(t, "com.example.actual", readCapacitorAppID(dir)) |
| 2833 | }) |
| 2834 | |
| 2835 | t.Run("json config takes priority over ts config", func(t *testing.T) { |
nothing calls this directly
no test coverage detected