From 362eb2933d10ff4edc2cb3877e4cf6dba6b87dc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20von=20der=20Gr=C3=BCn?= Date: Fri, 16 Oct 2020 00:05:15 +0200 Subject: [PATCH] test: make expectations work for npm 5 to 7 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` --- spec/fetch.spec.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/spec/fetch.spec.js b/spec/fetch.spec.js index e6cddd4..2d89d37 100644 --- a/spec/fetch.spec.js +++ b/spec/fetch.spec.js @@ -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', () => { @@ -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')) @@ -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'));