targets.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. 'use strict'
  2. const config = require('./config.json')
  3. const sinon = require('sinon')
  4. const targets = require('../targets')
  5. const test = require('ava')
  6. const util = require('./_util')
  7. function createMultiTargetOptions (extraOpts) {
  8. return Object.assign({
  9. name: 'targetTest',
  10. dir: util.fixtureSubdir('basic'),
  11. electronVersion: config.version
  12. }, extraOpts)
  13. }
  14. function testMultiTarget (testcaseDescription, extraOpts, expectedPackageCount, packageExistenceMessage) {
  15. test(testcaseDescription, t => {
  16. const opts = createMultiTargetOptions(extraOpts)
  17. const platforms = targets.validateListFromOptions(opts, 'platform')
  18. const archs = targets.validateListFromOptions(opts, 'arch')
  19. const combinations = targets.createPlatformArchPairs(opts, platforms, archs)
  20. t.is(combinations.length, expectedPackageCount, packageExistenceMessage)
  21. })
  22. }
  23. function testCombinations (testcaseDescription, arch, platform) {
  24. testMultiTarget(testcaseDescription, {arch: arch, platform: platform}, 4,
  25. 'Packages should be generated for all combinations of specified archs and platforms')
  26. }
  27. test('allOfficialArchsForPlatformAndVersion is undefined for unknown platforms', t => {
  28. t.is(targets.allOfficialArchsForPlatformAndVersion('unknown', '1.0.0'), undefined)
  29. })
  30. test('allOfficialArchsForPlatformAndVersion returns the correct arches for a known platform', t => {
  31. t.deepEqual(targets.allOfficialArchsForPlatformAndVersion('darwin', '1.0.0'), ['x64'])
  32. })
  33. test('allOfficialArchsForPlatformAndVersion returns arm64 when the correct version is specified', t => {
  34. t.not(targets.allOfficialArchsForPlatformAndVersion('linux', '1.8.0').indexOf('arm64'), -1,
  35. 'should be found when version is >= 1.8.0')
  36. t.is(targets.allOfficialArchsForPlatformAndVersion('linux', '1.7.0').indexOf('arm64'), -1,
  37. 'should not be found when version is < 1.8.0')
  38. })
  39. test('allOfficialArchsForPlatformAndVersion returns mips64el when the correct version is specified', t => {
  40. t.not(targets.allOfficialArchsForPlatformAndVersion('linux', '1.8.2').indexOf('mips64el'), -1,
  41. 'should be found when version is >= 1.8.2-beta.5')
  42. t.is(targets.allOfficialArchsForPlatformAndVersion('linux', '1.8.0').indexOf('mips64el'), -1,
  43. 'should not be found when version is < 1.8.2-beta.5')
  44. })
  45. test('validateListFromOptions does not take non-Array/String values', t => {
  46. targets.supported.digits = new Set(['64', '65'])
  47. t.false(targets.validateListFromOptions({digits: 64}, 'digits') instanceof Array,
  48. 'should not be an Array')
  49. delete targets.supported.digits
  50. })
  51. test('validateListFromOptions works for armv7l host and target arch', t => {
  52. const sandbox = sinon.createSandbox()
  53. sandbox.stub(process, 'arch').value('arm')
  54. sandbox.stub(process, 'config').value({variables: {arm_version: '7'}})
  55. t.deepEqual(targets.validateListFromOptions({}, 'arch'), ['armv7l'])
  56. sandbox.restore()
  57. })
  58. testMultiTarget('build for all available official targets', {all: true, electronVersion: '1.8.2'},
  59. util.allPlatformArchCombosCount,
  60. 'Packages should be generated for all possible platforms')
  61. testMultiTarget('build for all available official targets for a version without arm64 or mips64el support',
  62. {all: true},
  63. util.allPlatformArchCombosCount - 2,
  64. 'Packages should be generated for all possible platforms (except arm64 and mips64el)')
  65. testMultiTarget('platform=all (one arch)', {arch: 'ia32', platform: 'all'}, 2,
  66. 'Packages should be generated for both 32-bit platforms')
  67. testMultiTarget('arch=all test (one platform)', {arch: 'all', platform: 'linux'}, 3,
  68. 'Packages should be generated for all expected architectures')
  69. testCombinations('multi-platform / multi-arch test, from arrays', ['ia32', 'x64'], ['linux', 'win32'])
  70. testCombinations('multi-platform / multi-arch test, from strings', 'ia32,x64', 'linux,win32')
  71. testCombinations('multi-platform / multi-arch test, from strings with spaces', 'ia32, x64', 'linux, win32')
  72. test('fails with invalid arch', util.invalidOptionTest({
  73. arch: 'z80',
  74. platform: 'linux'
  75. }))
  76. test('fails with invalid platform', util.invalidOptionTest({
  77. arch: 'ia32',
  78. platform: 'dos'
  79. }))
  80. test('hostArch detects incorrectly configured armv7l Node', t => {
  81. const sandbox = sinon.createSandbox()
  82. sandbox.stub(targets, 'unameArch').returns('armv7l')
  83. sandbox.stub(process, 'arch').value('arm')
  84. sandbox.stub(process, 'config').value({variables: {arm_version: '6'}})
  85. t.is(targets.hostArch(), 'armv7l')
  86. sandbox.restore()
  87. })
  88. test('hostArch detects correctly configured armv7l Node', t => {
  89. const sandbox = sinon.createSandbox()
  90. sandbox.stub(process, 'arch').value('arm')
  91. sandbox.stub(process, 'config').value({variables: {arm_version: '7'}})
  92. t.is(targets.hostArch(), 'armv7l')
  93. sandbox.restore()
  94. })
  95. test('hostArch cannot determine ARM version', t => {
  96. const sandbox = sinon.createSandbox()
  97. sandbox.stub(process, 'arch').value('arm')
  98. sandbox.stub(process, 'config').value({variables: {arm_version: '99'}})
  99. t.is(targets.hostArch(), 'arm')
  100. sandbox.restore()
  101. })
  102. testMultiTarget('invalid official combination', {arch: 'ia32', platform: 'darwin'}, 0, 'Package should not be generated for invalid official combination')
  103. testMultiTarget('platform=linux and arch=arm64 with a supported official Electron version', {arch: 'arm64', platform: 'linux', electronVersion: '1.8.0'}, 1, 'Package should be generated for arm64')
  104. testMultiTarget('platform=linux and arch=arm64 with an unsupported official Electron version', {arch: 'arm64', platform: 'linux'}, 0, 'Package should not be generated for arm64')
  105. testMultiTarget('platform=linux and arch=mips64el with a supported official Electron version', {arch: 'mips64el', platform: 'linux', electronVersion: '1.8.2-beta.5'}, 1, 'Package should be generated for mips64el')
  106. testMultiTarget('platform=linux and arch=mips64el with an unsupported official Electron version', {arch: 'mips64el', platform: 'linux'}, 0, 'Package should not be generated for mips64el')
  107. testMultiTarget('unofficial arch', {arch: 'z80', platform: 'linux', download: {mirror: 'mirror'}}, 1,
  108. 'Package should be generated for non-standard arch from non-official mirror')
  109. testMultiTarget('unofficial platform', {arch: 'ia32', platform: 'minix', download: {mirror: 'mirror'}}, 1,
  110. 'Package should be generated for non-standard platform from non-official mirror')