Skip to content

Commit

Permalink
test: make expectations work for npm 5 to 7
Browse files Browse the repository at this point in the history
This addresses the following changes in behavior.

Saved GitHub URL format in package.json:
- npm 6: git+https://github.com/apache/cordova-android.git#4.1.x
- npm 7: github:apache/cordova-android#4.1.x

Empty devDependencies format in package.json:
- npm 6: `{}`
- npm 7: `undefined`
  • Loading branch information
raphinesse committed Oct 16, 2020
1 parent d42544b commit 362eb29
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions spec/fetch.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function expectNotToBeInstalled (pkgName) {

function expectDevDependenciesToBe (deps) {
const rootPJ = fs.readJsonSync(path.join(tmpDir, 'package.json'));
expect(rootPJ.devDependencies).toEqual(deps);
expect(rootPJ.devDependencies || {}).toEqual(deps);
}

describe('fetch/uninstall tests via npm & git', () => {
Expand Down Expand Up @@ -101,7 +101,7 @@ describe('fetch/uninstall with --save', () => {
name: 'cordova-ios',
version: '5.0.1'
}))
.then(_ => expectDevDependenciesToBe({ 'cordova-ios': 'git+https://github.com/apache/cordova-ios.git#rel/5.0.1' }))
.then(_ => expectDevDependenciesToBe({ 'cordova-ios': jasmine.stringMatching('#rel/5.0.1') }))
.then(_ => uninstall('cordova-ios', tmpDir, opts))
.then(_ => expectDevDependenciesToBe({}))
.then(_ => expectNotToBeInstalled('cordova-ios'))
Expand All @@ -111,18 +111,19 @@ describe('fetch/uninstall with --save', () => {
name: 'cordova-android',
version: '4.1.1'
}))
.then(_ => expectDevDependenciesToBe({ 'cordova-android': 'git+https://github.com/apache/cordova-android.git#4.1.x' }))
.then(_ => expectDevDependenciesToBe({ 'cordova-android': jasmine.stringMatching('#4.1.x') }))
.then(_ => uninstall('cordova-android', tmpDir, opts));
}, 150000);

it('should fetch and uninstall a cordova plugin via git commit sha', () => {
const URL = 'https://github.com/apache/cordova-plugin-contacts.git#7db612115755c2be73a98dda76ff4c5fd9d8a575';
const SHA = '7db612115755c2be73a98dda76ff4c5fd9d8a575';
const URL = `https://github.com/apache/cordova-plugin-contacts.git#${SHA}`;
return Promise.resolve()
.then(_ => fetchAndMatch(URL, {
name: 'cordova-plugin-contacts',
version: '2.0.2-dev'
}))
.then(_ => expectDevDependenciesToBe({ 'cordova-plugin-contacts': `git+${URL}` }))
.then(_ => expectDevDependenciesToBe({ 'cordova-plugin-contacts': jasmine.stringMatching(`#${SHA}`) }))
.then(_ => uninstall('cordova-plugin-contacts', tmpDir, opts))
.then(_ => expectDevDependenciesToBe({}))
.then(_ => expectNotToBeInstalled('cordova-plugin-contacts'));
Expand Down

0 comments on commit 362eb29

Please sign in to comment.