/
configSpec.js
194 lines (168 loc) · 8.36 KB
/
configSpec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*********
* Modules
*********/
// Core
var path = require('path');
var fs = require('fs');
// helper
var fileHelper = require('./helper/file.js')();
var toolHelper = require('./helper/tool.js')();
var reporter = require('./helper/reporter.js');
//lib
var credentialsToObfuscate = [
process.env.GITHUB_PASSWORD,
process.env.GITHUB_ACCESS_TOKEN
];
var logger = require('../lib/logger.js')();
logger.setCredentialsToObfuscate(credentialsToObfuscate);
// 3rd party
var semver = require('semver');
jasmine.DEFAULT_TIMEOUT_INTERVAL = 240000;
toolHelper.setStaticArgs(
' --nospinner'+
' --github-username="'+process.env.GITHUB_USERNAME+'"'+
' --github-password="'+process.env.GITHUB_PASSWORD+'"'+
' --obfuscate-credentials="'+credentialsToObfuscate.join(' ')+'"');
describe("A spec for targeting config.xml", function() {
beforeAll(function(done) {
fileHelper.resetPlatforms(done);
});
beforeEach(function(done) {
fileHelper.reset(done);
});
it("should use config.xml as the target for plugin versions when the --target=config CLI argument is specified", function(done){
fileHelper.addPlugins([
'cordova-plugin-camera', // up-to-date
'cordova-plugin-geolocation@1.0.0', // newer installed
'cordova.plugins.diagnostic@3' //newer config
], function(results){
fileHelper.addPlugins([
'cordova-plugin-network-information' // new installed
], function(results){
fileHelper.forceLocalPluginVersion('cordova-plugin-geolocation', '2.0.0'); // newer installed
fileHelper.forceLocalPluginVersion('cordova.plugins.diagnostic', '2.0.0'); // newer config
fileHelper.addPluginToConfig('cordova-plugin-device', '~1.1.3'); // new config
toolHelper.run('--target=config', function(err, stdout, stderr, output){
expect(output.section.upToDate['cordova-plugin-camera']).toBeDefined();
expect(output.section.newerInstalled['cordova-plugin-geolocation']).toBeDefined();
expect(output.section.newerTarget['cordova.plugins.diagnostic']).toBeDefined();
expect(output.section.newInstalled['cordova-plugin-network-information']).toBeDefined();
expect(output.section.newTarget['cordova-plugin-device']).toBeDefined();
done();
});
},{
save: false
});
},{
save: true
});
});
it("should NOT downdate plugins when the --allow-downdate argument is NOT specified", function(done){
fileHelper.addPlugin(
'cordova-plugin-geolocation@1.0.0', // newer installed
function(results){
fileHelper.forceLocalPluginVersion('cordova-plugin-geolocation', '2.0.0'); // newer installed
toolHelper.run('--target=config --update=cordova-plugin-geolocation', function(err, stdout, stderr, output){
expect(output.section.newerInstalled['cordova-plugin-geolocation']).toBeDefined();
fileHelper.listPlugins(function(plugins){
expect(semver.eq(plugins['cordova-plugin-geolocation'].version, '2.0.0')).toBeTruthy();
expect(true).toBeTruthy();
done();
});
}
);
},{
save: true
}
);
});
it("should downdate plugins when the --allow-downdate argument is specified", function(done){
fileHelper.addPlugin(
'cordova-plugin-geolocation@1.0.0', // newer installed
function(results){
fileHelper.forceLocalPluginVersion('cordova-plugin-geolocation', '2.0.0'); // newer installed
toolHelper.run('--target=config --update=cordova-plugin-geolocation --allow-downdate', function(err, stdout, stderr, output){
expect(output.section.newerInstalled['cordova-plugin-geolocation']).toBeDefined();
fileHelper.listPlugins(function(plugins){
expect(semver.eq(plugins['cordova-plugin-geolocation'].version, '1.0.0')).toBeTruthy();
done();
});
}
);
},{
save: true
}
);
});
it("should log an error and continue if a <plugin> tag specified in the config.xml is malformed (missing either 'name' or 'spec')", function(done){
fileHelper.addPlugin(
'cordova-plugin-geolocation@1.0.0',
function(results){
var configXml = fileHelper.readConfigXml();
configXml = configXml.replace('</widget>', '<plugin invalid="attributes" /></widget>');
fileHelper.writeConfigXml(configXml);
toolHelper.run('--target=config', function(err, stdout, stderr, output){
expect(err).toBeFalsy();
expect(stdout).toContain('Malformed <plugin> tag found in config.xml');
done();
});
},{
save: true
}
);
});
describe("when updating plugins from config.xml", function() {
it("should log an error and continue if a plugin ID specified in the config.xml does not exist remotely", function(done){
fileHelper.addPlugin(
'cordova-plugin-geolocation@1.0.0',
function(results){
var configXml = fileHelper.readConfigXml();
configXml = configXml.replace('</widget>', '<plugin name="cordova-plugin-invalid" spec="~1.0.0" /></widget>');
fileHelper.writeConfigXml(configXml);
toolHelper.run('--target=config --update=auto', function(err, stdout, stderr, output){
expect(err).toBeFalsy();
expect(stdout).toContain("Failed to update plugin 'cordova-plugin-invalid'");
done();
});
},{
save: true
}
);
});
it("should log an error and continue if the plugin version/spec specified in the config.xml does not exist remotely", function(done){
fileHelper.addPlugin(
'cordova-plugin-geolocation@2.0.0',
function(results){
fileHelper.forceLocalPluginVersion('cordova-plugin-geolocation', '1.0.0'); // newer config
fileHelper.addPluginToConfig('cordova-plugin-device', '~100.0.0'); // invalid npm version
fileHelper.addPluginToConfig('cordova.plugins.diagnostic', 'https://github.com/invalid_user/cordova-diagnostic-plugin'); // invalid git repo
toolHelper.run('--target=config --update=auto', function(err, stdout, stderr, output){
expect(err).toBeFalsy();
expect(stdout).toContain("Failed to update plugin 'cordova.plugins.diagnostic'");
expect(stdout).toContain("Failed to update plugin 'cordova-plugin-device'");
fileHelper.listPlugins(function(plugins){
expect(semver.eq(plugins['cordova-plugin-geolocation'].version, '2.0.0')).toBeTruthy(); //successfully updated from 1.0.0 to 2.0.0
done();
});
});
},{
save: true
}
);
});
it("should preserve any plugin variables specified when updating plugins from config.xml", function(done){
fileHelper.addPlugin('cordova-plugin-file', function(err, stdout, stderr){
fileHelper.forceLocalPluginVersion('cordova-plugin-file', '2.0.0');
toolHelper.run('--target=config --update=auto --save', function(err, stdout, stderr, output){
expect(fileHelper.readConfigXml().match('<variable name="FOO" value="bar" />')).toBeTruthy();
done();
});
},{
save: true,
variables:{
"FOO": "bar"
}
});
});
});
});