/
_setup.js
106 lines (93 loc) · 3.15 KB
/
_setup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
'use strict'
const common = require('../common')
const download = require('../download')
const config = require('./config.json')
const { exec } = require('mz/child_process')
const fs = require('fs-extra')
const os = require('os')
const path = require('path')
const targets = require('../targets')
function fixtureSubdir (subdir) {
return path.join(__dirname, 'fixtures', subdir)
}
/**
* Skip testing darwin/mas target on Windows since Electron Packager itself skips it
* (see https://github.com/electron-userland/electron-packager/issues/71)
*/
function skipDownloadingMacZips (platform, arch) {
return common.isPlatformMac(platform) && process.platform === 'win32'
}
function downloadAll (version) {
console.log(`Calling electron-download for ${version} before running tests...`)
const combinations = download.createDownloadCombos({ electronVersion: config.version, all: true }, targets.officialPlatforms, targets.officialArchs, skipDownloadingMacZips)
return Promise.all(combinations.map(combination => downloadElectronZip(version, combination)))
}
function downloadElectronZip (version, options) {
return download.downloadElectronZip(Object.assign({}, options, {
cache: path.join(os.homedir(), '.electron'),
quiet: !!process.env.CI,
version: version
}))
}
function downloadMASLoginHelperElectronZip () {
if (process.platform !== 'win32') {
const version = '2.0.0-beta.1'
console.log(`Calling electron-download for ${version} (MAS only) before running tests...`)
return downloadElectronZip(version, { platform: 'mas', arch: 'x64' })
}
}
/**
* Download all Electron distributions before running tests to avoid timing out due to network
* speed. Most tests run with the config.json version, but we have some tests using 0.37.4, an
* `electron` module specific test using 1.3.1., and an MAS-specific test using 2.0.0-beta.1.
*/
function preDownloadElectron () {
const versions = [
config.version,
'0.37.4',
'1.3.1'
]
return Promise.all(versions.map(downloadAll))
.then(downloadMASLoginHelperElectronZip)
}
function npmInstallForFixture (fixture) {
const fixtureDir = fixtureSubdir(fixture)
return fs.exists(path.join(fixtureDir, 'node_modules'))
.then(exists => {
if (exists) {
return true
} else {
console.log(`Running npm install in fixtures/${fixture}...`)
return exec('npm install --no-bin-links', { cwd: fixtureDir })
}
})
}
function npmInstallForFixtures () {
const fixtures = [
'asar-prebuilt',
'basic',
'basic-renamed-to-electron',
'electron-in-dependencies',
'infer-missing-version-only',
'el-0374'
]
return Promise.all(fixtures.map(npmInstallForFixture))
}
const WORK_CWD = path.join(__dirname, 'work')
function ensureEmptyWorkDirExists () {
return fs.remove(WORK_CWD)
.then(() => fs.mkdirs(WORK_CWD))
}
module.exports = {
fixtureSubdir: fixtureSubdir,
setupTestsuite: function setupTestsuite () {
return preDownloadElectron()
.then(npmInstallForFixtures)
.catch(error => {
console.error(error.stack || error)
return process.exit(1)
})
.then(ensureEmptyWorkDirExists)
},
WORK_CWD: WORK_CWD
}