mas.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. 'use strict'
  2. const fs = require('fs-extra')
  3. const packager = require('..')
  4. const path = require('path')
  5. const plist = require('plist')
  6. const util = require('./_util')
  7. if (!(process.env.CI && process.platform === 'win32')) {
  8. const masOpts = {
  9. name: 'masTest',
  10. dir: util.fixtureSubdir('basic'),
  11. electronVersion: '2.0.0-beta.1',
  12. arch: 'x64',
  13. platform: 'mas'
  14. }
  15. util.packagerTest('warn if building for mas and not signing', (t, baseOpts) => {
  16. const warningLog = console.warn
  17. let output = ''
  18. console.warn = message => { output += message }
  19. const finalize = err => {
  20. console.warn = warningLog
  21. if (err) throw err
  22. }
  23. return packager(Object.assign({}, baseOpts, masOpts))
  24. .then(() =>
  25. t.truthy(output.match(/signing is required for mas builds/), 'the correct warning is emitted')
  26. ).then(finalize)
  27. .catch(finalize)
  28. })
  29. util.packagerTest('update Login Helper if it exists', (t, baseOpts) => {
  30. let contentsPath
  31. let plistPath
  32. const helperName = `${masOpts.name} Login Helper`
  33. return packager(Object.assign({}, baseOpts, masOpts))
  34. .then(paths => {
  35. contentsPath = path.join(paths[0], `${masOpts.name}.app`, 'Contents', 'Library', 'LoginItems', `${helperName}.app`, 'Contents')
  36. return fs.pathExists(contentsPath)
  37. }).then(exists => {
  38. t.true(exists, 'renamed Login Helper app exists')
  39. plistPath = path.join(contentsPath, 'Info.plist')
  40. return fs.pathExists(contentsPath)
  41. }).then(exists => {
  42. t.true(exists, 'Login Helper Info.plist exists')
  43. return fs.readFile(plistPath, 'utf8')
  44. }).then(plistXML => {
  45. const plistData = plist.parse(plistXML)
  46. t.is(plistData.CFBundleExecutable, helperName, 'CFBundleExecutable is renamed Login Helper')
  47. t.is(plistData.CFBundleName, helperName, 'CFBundleName is renamed Login Helper')
  48. t.is(plistData.CFBundleIdentifier, 'com.electron.mastest.loginhelper')
  49. return fs.pathExists(path.join(contentsPath, 'MacOS', helperName))
  50. }).then(exists => t.true(exists, 'renamed Login Helper executable exists'))
  51. })
  52. }