Repository: electron/electron-packager
Pull request #1085 (2019-11-25 21:38:39)

test: fix infer test coverage
* [x] I have read the [contribution documentation](https://github.com/electron/electron-packager/blob/master/CONTRIBUTING.md) for this project.
* [x] I agree to follow the [code of conduct](https://github.com/electron/electron/blob/master/CODE_OF_CONDUCT.md) that this project follows, as appropriate.
* [x] The changes have sufficient test coverage (if applicable).
* [x] The testsuite passes successfully on my local machine (if applicable).

**Summarize your changes:**

#1079 inadvertently decreased test coverage. This PR fixes that.


Patch:
diff --git a/src/infer.js b/src/infer.js
index a3daea7..ae65808 100644
--- a/src/infer.js
+++ b/src/infer.js
@@ -26,6 +26,7 @@ function errorMessageForProperty (prop) {
       hash = 'appversion'
       propDescription = 'application version'
       break
+    /* istanbul ignore next */
     default:
       hash = ''
       propDescription = `[Unknown Property (${prop})]`
@@ -108,7 +109,8 @@ async function handleMetadata (opts, result) {
     }
   }
 
-  if (result.values['dependencies.electron']) {
+  // eslint-disable-next-line no-prototype-builtins
+  if (result.values.hasOwnProperty('dependencies.electron')) {
     return getVersion(opts, result.source['dependencies.electron'])
   } else {
     return Promise.resolve()


Test patch:
diff --git a/test/fixtures/infer-missing-electron-version/package.json b/test/fixtures/infer-missing-electron-version/package.json
new file mode 100644
index 0000000..fdc171d
--- /dev/null
+++ b/test/fixtures/infer-missing-electron-version/package.json
@@ -0,0 +1,7 @@
+{
+  "name": "Missing electron version",
+  "version": "0.0.1",
+  "dependencies": {
+    "run-series": "^1.1.1"
+  }
+}
diff --git a/test/fixtures/infer-missing-fields/package.json b/test/fixtures/infer-missing-name/package.json
similarity index 68%
rename from test/fixtures/infer-missing-fields/package.json
rename to test/fixtures/infer-missing-name/package.json
index 1730344..3daab6f 100644
--- a/test/fixtures/infer-missing-fields/package.json
+++ b/test/fixtures/infer-missing-name/package.json
@@ -1,5 +1,6 @@
 {
   "dependencies": {
+    "electron": "6.0.0",
     "run-series": "^1.1.1"
   }
 }
diff --git a/test/fixtures/infer-missing-package-json/.gitkeep b/test/fixtures/infer-missing-package-json/.gitkeep
new file mode 100644
index 0000000..e69de29
diff --git a/test/infer.js b/test/infer.js
index f69e5f1..c0428c9 100644
--- a/test/infer.js
+++ b/test/infer.js
@@ -32,12 +32,12 @@ async function copyFixtureToTempDir (t, fixtureSubdir) {
   return tmpdir
 }
 
-async function inferFailureTest (t, opts, fixtureSubdir) {
+async function inferFailureTest (t, opts, fixtureSubdir, errorMatcher) {
   opts.dir = await copyFixtureToTempDir(t, fixtureSubdir)
   delete opts.name
   delete opts.electronVersion
 
-  return t.throwsAsync(packager(opts))
+  return t.throwsAsync(packager(opts), errorMatcher)
 }
 
 async function inferMissingVersionTest (t, opts) {
@@ -110,9 +110,11 @@ test('do not infer win32metadata.CompanyName when author is an object without a
 
   return testInferWin32metadataAuthorObject(t, opts, author, expected, 'win32metadata.CompanyName should not have been inferred')
 }))
-test('infer missing fields test', util.testSinglePlatform(inferFailureTest, 'infer-missing-fields'))
-test('infer with bad fields test', util.testSinglePlatform(inferFailureTest, 'infer-bad-fields'))
-test('infer with malformed JSON test', util.testSinglePlatform(async (t, opts) => {
+test('missing name from package.json', util.testSinglePlatform(inferFailureTest, 'infer-missing-name', /^Unable to determine application name/))
+test('missing Electron version from package.json', util.testSinglePlatform(inferFailureTest, 'infer-missing-electron-version', /^Unable to determine Electron version/))
+test('missing package.json', util.testSinglePlatform(inferFailureTest, 'infer-missing-package-json', /^Could not locate a package\.json file/))
+test('infer with bad fields', util.testSinglePlatform(inferFailureTest, 'infer-bad-fields', /^Cannot find module/))
+test('infer with malformed JSON', util.testSinglePlatform(async (t, opts) => {
   opts.dir = await copyFixtureToTempDir(t, 'infer-malformed-json')
   delete opts.name
   delete opts.electronVersion
@@ -123,4 +125,4 @@ test('infer with malformed JSON test', util.testSinglePlatform(async (t, opts) =
 
   return t.throwsAsync(packager(opts), /^Unexpected token/)
 }))
-test('infer using a non-specific `electron-prebuilt-compile` package version when the package did not have a main file', util.testSinglePlatform(inferFailureTest, 'infer-invalid-non-specific-electron-prebuilt-compile'))
+test('infer using a non-specific `electron-prebuilt-compile` package version when the package did not have a main file', util.testSinglePlatform(inferFailureTest, 'infer-invalid-non-specific-electron-prebuilt-compile', /^Using electron-prebuilt-compile/))