-
Notifications
You must be signed in to change notification settings - Fork 242
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
CB-12361 : added tests for plugin/save.js #584
Conversation
1d529e5
to
65303a9
Compare
6e03a40
to
5c46599
Compare
5c46599
to
cf309c7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a bunch of feedback.
Also, need to add tests for the helper methods getPluginVariables
& versionString
.
spec/cordova/plugin/save.spec.js
Outdated
it('should only add top-level plugins to config.xml'); | ||
it('should write individual plugin specs to config.xml'); | ||
it('should write individual plugin variables to config.xml'); | ||
it('should remove all plugins from config.xml and re-add new ones based on those retrieved from fetch.json', function (done) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test checks that the plugins get removed but not if the new ones get re-added (based on description). I think the description should be updated to just check that existing plugins are getting removed
spec/cordova/plugin/save.spec.js
Outdated
|
||
fs.readFileSync.and.returnValue(JSON.stringify(fake_fetch_json)); | ||
save(projectRoot).then(function () { | ||
expect(cfg_parser_mock.prototype.addPlugin).toHaveBeenCalledWith(Object({ name: 'VRPlugin' }), [ ]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add another expect to show that the non top level plugin didn't get installed. Something like
expect(cfg_parser_mock.prototype.addPlugin).toHaveBeenCalledWith(Object({ name: 'MastodonSocialPlugin' }), [ ]);```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe for this test, you can redo the checks from the first test. That is confirm that these two expects are run before the addPlugin one
expect(cfg_parser_mock.prototype.removePlugin).toHaveBeenCalledWith('VRPlugin');
expect(cfg_parser_mock.prototype.removePlugin).toHaveBeenCalledWith('MastodonSocialPlugin');
I think they should pass. If they do, you can also update the description of this test to reflect that the plugins are being removed first and then only top level plugins are being restored.
spec/cordova/plugin/save.spec.js
Outdated
fs.readFileSync.and.returnValue(JSON.stringify(fake_fetch_json)); | ||
spyOn(save, 'getSpec'); | ||
save(projectRoot).then(function (result) { | ||
expect(save.getSpec).toHaveBeenCalledWith(Object({ url: 'https://git-wip-us.apache.org/repos/asf/cordova-plugin-camera.git' }), '/some/path', 'VRPlugin'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need one more expect here. We need to confirm save.getSpec
returned the url. I think you can use returnValue
or toEqual
expect(save.getSpec).and.returnValue('https://git-wip-us.apache.org/repos/asf/cordova-plugin-camera.git')
spec/cordova/plugin/save.spec.js
Outdated
'is_top_level': true }}; | ||
fs.readFileSync.and.returnValue(JSON.stringify(fake_fetch_json)); | ||
save(projectRoot).then(function () { | ||
expect(save.versionString).toHaveBeenCalledWith('^1.1.0'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above, this test needs to check that getSpec is returning the version. Need something like:
expect(save.getSpec).and.returnValue('^1.1.0')
expect(e).toBeUndefined(); | ||
fail('did not expect fail handler to be invoked'); | ||
}).done(done); | ||
}); | ||
}); | ||
describe('getSpec helper method', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So with all of these getSpec
tests, you want to test getSpec directly. Right now, you are doing save(projectRoot)
but instead you want to do save.getSpec({ url: 'https://git-wip-us.apache.org/repos/asf/cordova-plugin-camera.git' }, '/some/path', 'VRPlugin')
spec/cordova/plugin/save.spec.js
Outdated
fs.readFileSync.and.returnValue(JSON.stringify(fake_fetch_json)); | ||
spyOn(save, 'getSpec').and.callThrough(); | ||
save(projectRoot).then(function () { | ||
expect(save.getSpec).toHaveBeenCalledWith(Object({ type: 'registry', id: '@scoped/package@^1.0.0' }), '/some/path', 'cordova-plugin-camera'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, need to check what save.getSpec
returns. First you need to change line 181 from save(projectRoot)
to save.getSpec({ url: 'https://git-wip-us.apache.org/repos/asf/cordova-plugin-camera.git' }, '/some/path', 'VRPlugin')
Make sure to run |
847c10d
to
57eceea
Compare
spec/cordova/plugin/save.spec.js
Outdated
}); | ||
it('return version passed in, if it is within the valid range', function () { | ||
save.versionString.and.callThrough(); | ||
spyOn(semver, 'valid').and.returnValue('', false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
semver.valid
returns null when the version isn't valid (just looked it up at https://github.com/npm/node-semver.
spyOn(semver, 'valid').and.returnValue(null);
spec/cordova/plugin/save.spec.js
Outdated
}); | ||
it('should check and return a valid version', function () { | ||
save.versionString.and.callThrough(); | ||
spyOn(semver, 'valid').and.returnValue('1.3.2', true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just set returnValue to 1.3.2
. No need for second argument of true
spec/cordova/plugin/save.spec.js
Outdated
save.versionString.and.callThrough(); | ||
spyOn(semver, 'valid').and.returnValue('', false); | ||
spyOn(semver, 'validRange').and.returnValue('1.3.0', true); | ||
expect(save.versionString('1.3.2')).toBe('1.3.2'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be
spyOn(semver, 'validRange').and.returnValue('^1.3.2');
expect(save.versionString('^1.3.2')).toBe('^1.3.2');
semver.validRange
takes in a range (^1.3.2
) and returns it if it is valid. Returns null
if it is invalid. So for testing, we need to pass in a range and expect the range to be returned (like my example)
spec/cordova/plugin/save.spec.js
Outdated
it('if no version, should return null', function () { | ||
save.versionString.and.callThrough(); | ||
spyOn(semver, 'valid').and.returnValue('', false); | ||
spyOn(semver, 'validRange').and.returnValue('', false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set the returnValue for 176 and 177 to null
c45a3fd
to
681c8dd
Compare
681c8dd
to
760f47f
Compare
760f47f
to
a4d91e4
Compare
Platforms affected
What does this PR do?
added tests for plugin/save.js
What testing has been done on this change?
Checklist