@@ -27,56 +27,102 @@ tmp.setGracefulCleanup();
27
27
const fixturePackage = fs . readFileSync ( path . join ( __dirname , 'fixtures' , 'test-Package.swift' ) , 'utf-8' ) ;
28
28
29
29
describe ( 'SwiftPackage' , ( ) => {
30
+ let tmpDir ;
31
+ beforeEach ( ( ) => {
32
+ tmpDir = tmp . dirSync ( ) ;
33
+ } ) ;
34
+
35
+ afterEach ( ( ) => {
36
+ fs . rmSync ( tmpDir . name , { recursive : true , force : true } ) ;
37
+ } ) ;
38
+
30
39
it ( 'should error if Package.swift file does not exist' , ( ) => {
31
40
expect ( ( ) => {
32
- const _ = new SwiftPackage ( 'dummypath' ) ;
41
+ const _ = new SwiftPackage ( tmpDir . name ) ;
33
42
expect ( _ ) . not . toEqual ( null ) ; // To avoid ESLINT error "Do not use 'new' for side effects"
34
43
} ) . toThrow ( ) ;
35
44
} ) ;
36
45
37
46
describe ( 'addPlugin' , ( ) => {
38
47
const my_plugin = {
39
- id : 'my-plugin'
48
+ id : 'my-plugin' ,
49
+ dir : path . join ( __dirname , 'fixtures' , 'org.test.plugins.swiftpackageplugin' )
40
50
} ;
41
51
42
52
let pkg ;
43
- let tmpFile ;
44
53
beforeEach ( ( ) => {
45
- tmpFile = tmp . fileSync ( { discardDescriptor : true } ) ;
46
- fs . writeFileSync ( tmpFile . name , fixturePackage , 'utf8' ) ;
54
+ fs . mkdirSync ( path . join ( tmpDir . name , 'CordovaPlugins' ) ) ;
55
+ fs . writeFileSync ( path . join ( tmpDir . name , 'CordovaPlugins' , 'Package.swift' ) , fixturePackage , 'utf8' ) ;
47
56
48
- pkg = new SwiftPackage ( tmpFile . name ) ;
57
+ pkg = new SwiftPackage ( tmpDir . name ) ;
49
58
} ) ;
50
59
51
60
it ( 'should add plugin references to the package file' , ( ) => {
52
61
pkg . addPlugin ( my_plugin ) ;
53
62
54
- const content = fs . readFileSync ( tmpFile . name , 'utf8' ) ;
55
- expect ( content ) . toContain ( '.package(name: "my-plugin"' ) ;
63
+ const pkgPath = path . join ( tmpDir . name , 'CordovaPlugins' , 'Package.swift' ) ;
64
+ const content = fs . readFileSync ( pkgPath , 'utf8' ) ;
65
+ expect ( content ) . toContain ( '.package(name: "my-plugin", path: "../packages/my-plugin")' ) ;
56
66
expect ( content ) . toContain ( '.product(name: "my-plugin", package: "my-plugin")' ) ;
57
67
} ) ;
68
+
69
+ it ( 'should copy the plugin into the packages directory' , ( ) => {
70
+ pkg . addPlugin ( my_plugin ) ;
71
+
72
+ expect ( fs . existsSync ( path . join ( tmpDir . name , 'packages' , 'my-plugin' ) ) ) . toBeTruthy ( ) ;
73
+ } ) ;
74
+
75
+ it ( 'should add plugin references to the package file when linked' , ( ) => {
76
+ pkg . addPlugin ( my_plugin , { link : true } ) ;
77
+
78
+ const pkgPath = path . join ( tmpDir . name , 'CordovaPlugins' , 'Package.swift' ) ;
79
+ const content = fs . readFileSync ( pkgPath , 'utf8' ) ;
80
+
81
+ expect ( content ) . toContain ( '.package(name: "my-plugin", path: "' ) ;
82
+ expect ( content ) . not . toContain ( '.package(name: "my-plugin", path: "../packages/my-plugin")' ) ;
83
+ expect ( content ) . toContain ( '.product(name: "my-plugin", package: "my-plugin")' ) ;
84
+ } ) ;
85
+
86
+ it ( 'should copy a linked plugin into the packages directory' , ( ) => {
87
+ pkg . addPlugin ( my_plugin , { link : true } ) ;
88
+
89
+ expect ( fs . existsSync ( path . join ( tmpDir . name , 'packages' , 'my-plugin' ) ) ) . toBeFalsy ( ) ;
90
+ } ) ;
58
91
} ) ;
59
92
60
93
describe ( 'removePlugin' , ( ) => {
61
94
const my_plugin = {
62
- id : 'my-plugin'
95
+ id : 'my-plugin' ,
96
+ dir : path . join ( __dirname , 'fixtures' , 'org.test.plugins.swiftpackageplugin' )
63
97
} ;
64
98
65
99
let pkg ;
66
- let tmpFile ;
67
100
beforeEach ( ( ) => {
68
- tmpFile = tmp . fileSync ( { discardDescriptor : true } ) ;
101
+ fs . mkdirSync ( path . join ( tmpDir . name , 'CordovaPlugins' ) ) ;
102
+ const pkgPath = path . join ( tmpDir . name , 'CordovaPlugins' , 'Package.swift' ) ;
103
+ fs . writeFileSync ( pkgPath , fixturePackage , 'utf8' ) ;
69
104
70
- pkg = new SwiftPackage ( tmpFile . name ) ;
71
- fs . writeFileSync ( tmpFile . name , fixturePackage + pkg . _pluginReference ( my_plugin ) , 'utf8' ) ;
105
+ pkg = new SwiftPackage ( tmpDir . name ) ;
106
+ fs . writeFileSync ( pkgPath , fixturePackage + pkg . _pluginReference ( my_plugin ) , 'utf8' ) ;
72
107
} ) ;
73
108
74
- it ( 'should add plugin references to the package file' , ( ) => {
109
+ it ( 'should remove plugin references to the package file' , ( ) => {
75
110
pkg . removePlugin ( my_plugin ) ;
76
111
77
- const content = fs . readFileSync ( tmpFile . name , 'utf8' ) ;
112
+ const content = fs . readFileSync ( path . join ( tmpDir . name , 'CordovaPlugins' , 'Package.swift' ) , 'utf8' ) ;
78
113
expect ( content ) . not . toContain ( '.package(name: "my-plugin"' ) ;
79
114
expect ( content ) . not . toContain ( '.product(name: "my-plugin", package: "my-plugin")' ) ;
80
115
} ) ;
116
+
117
+ it ( 'should remove the plugin from the packages directory' , ( ) => {
118
+ fs . mkdirSync ( path . join ( tmpDir . name , 'packages' , 'my-plugin' ) , { recursive : true } ) ;
119
+ fs . writeFileSync ( path . join ( tmpDir . name , 'packages' , 'my-plugin' , 'test.txt' ) , 'Test' , 'utf-8' ) ;
120
+
121
+ expect ( fs . existsSync ( path . join ( tmpDir . name , 'packages' , 'my-plugin' ) ) ) . toBeTruthy ( ) ;
122
+
123
+ pkg . removePlugin ( my_plugin ) ;
124
+
125
+ expect ( fs . existsSync ( path . join ( tmpDir . name , 'packages' , 'my-plugin' ) ) ) . toBeFalsy ( ) ;
126
+ } ) ;
81
127
} ) ;
82
128
} ) ;
0 commit comments