forked from atom/atom
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest
More file actions
executable file
·184 lines (160 loc) · 6.72 KB
/
test
File metadata and controls
executable file
·184 lines (160 loc) · 6.72 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env node
'use strict'
require('colors')
const argv = require('yargs').argv
const assert = require('assert')
const async = require('async')
const childProcess = require('child_process')
const fs = require('fs-extra')
const glob = require('glob')
const path = require('path')
const CONFIG = require('./config')
const backupNodeModules = require('./lib/backup-node-modules')
const runApmInstall = require('./lib/run-apm-install')
const resourcePath = CONFIG.repositoryRootPath
let executablePath
if (process.platform === 'darwin') {
const executablePaths = glob.sync(path.join(CONFIG.buildOutputPath, '*.app'))
assert(executablePaths.length === 1, `More than one application to run tests against was found. ${executablePaths.join(',')}`)
executablePath = path.join(executablePaths[0], 'Contents', 'MacOS', path.basename(executablePaths[0], '.app'))
} else if (process.platform === 'linux') {
const executablePaths = glob.sync(path.join(CONFIG.buildOutputPath, '**', 'atom'))
assert(executablePaths.length === 1, `More than one application to run tests against was found. ${executablePaths.join(',')}`)
executablePath = executablePaths[0]
} else if (process.platform === 'win32') {
const executablePaths = glob.sync(path.join(CONFIG.buildOutputPath, '**', 'atom.exe'))
assert(executablePaths.length === 1, `More than one application to run tests against was found. ${executablePaths.join(',')}`)
executablePath = executablePaths[0]
} else {
throw new Error('Running tests on this platform is not supported.')
}
function prepareEnv (suiteName) {
const env = Object.assign({}, process.env)
if (process.env.TEST_JUNIT_XML_ROOT) {
// Tell Jasmine to output this suite's results as a JUnit XML file to a subdirectory of the root, so that a
// CI system can interpret it.
const outputPath = path.join(process.env.TEST_JUNIT_XML_ROOT, suiteName, 'test-results.xml')
env.TEST_JUNIT_XML_PATH = outputPath
}
return env
}
function runCoreMainProcessTests (callback) {
const testPath = path.join(CONFIG.repositoryRootPath, 'spec', 'main-process')
const testArguments = [
'--resource-path', resourcePath,
'--test', '--main-process', testPath
]
const testEnv = Object.assign({}, prepareEnv('core-main-process'), {ATOM_GITHUB_INLINE_GIT_EXEC: 'true'})
console.log('Executing core main process tests'.bold.green)
const cp = childProcess.spawn(executablePath, testArguments, {stdio: 'inherit', env: testEnv})
cp.on('error', error => { callback(error) })
cp.on('close', exitCode => { callback(null, exitCode) })
}
function runCoreRenderProcessTests (callback) {
const testPath = path.join(CONFIG.repositoryRootPath, 'spec')
const testArguments = [
'--resource-path', resourcePath,
'--test', testPath
]
const testEnv = prepareEnv('core-render-process')
console.log('Executing core render process tests'.bold.green)
const cp = childProcess.spawn(executablePath, testArguments, {stdio: 'inherit', env: testEnv})
cp.on('error', error => { callback(error) })
cp.on('close', exitCode => { callback(null, exitCode) })
}
// Build an array of functions, each running tests for a different bundled package
const packageTestSuites = []
for (let packageName in CONFIG.appMetadata.packageDependencies) {
if (process.env.ATOM_PACKAGES_TO_TEST) {
const packagesToTest = process.env.ATOM_PACKAGES_TO_TEST.split(',').map(pkg => pkg.trim())
if (!packagesToTest.includes(packageName)) continue
}
const repositoryPackagePath = path.join(CONFIG.repositoryRootPath, 'node_modules', packageName)
const testSubdir = ['spec', 'test'].find(subdir => fs.existsSync(path.join(repositoryPackagePath, subdir)))
if (!testSubdir) {
packageTestSuites.push(function (callback) {
console.log(`Skipping tests for ${packageName} because no test folder was found`.bold.yellow)
callback(null, 0)
})
continue
}
const testFolder = path.join(repositoryPackagePath, testSubdir)
packageTestSuites.push(function (callback) {
const testArguments = [
'--resource-path', resourcePath,
'--test', testFolder
]
const testEnv = prepareEnv(`bundled-package-${packageName}`)
const pkgJsonPath = path.join(repositoryPackagePath, 'package.json')
const nodeModulesPath = path.join(repositoryPackagePath, 'node_modules')
let finalize = () => null
if (require(pkgJsonPath).atomTestRunner) {
console.log(`Installing test runner dependencies for ${packageName}`.bold.green)
if (fs.existsSync(nodeModulesPath)) {
const backup = backupNodeModules(repositoryPackagePath)
finalize = backup.restore
} else {
finalize = () => fs.removeSync(nodeModulesPath)
}
runApmInstall(repositoryPackagePath)
console.log(`Executing ${packageName} tests`.green)
} else {
console.log(`Executing ${packageName} tests`.bold.green)
}
const cp = childProcess.spawn(executablePath, testArguments, {env: testEnv})
let stderrOutput = ''
cp.stderr.on('data', data => { stderrOutput += data })
cp.stdout.on('data', data => { stderrOutput += data })
cp.on('error', error => {
finalize()
callback(error)
})
cp.on('close', exitCode => {
if (exitCode !== 0) {
console.log(`Package tests failed for ${packageName}:`.red)
console.log(stderrOutput)
}
finalize()
callback(null, exitCode)
})
})
}
function runBenchmarkTests (callback) {
const benchmarksPath = path.join(CONFIG.repositoryRootPath, 'benchmarks')
const testArguments = ['--benchmark-test', benchmarksPath]
const testEnv = prepareEnv('benchmark')
console.log('Executing benchmark tests'.bold.green)
const cp = childProcess.spawn(executablePath, testArguments, {stdio: 'inherit', env: testEnv})
cp.on('error', error => { callback(error) })
cp.on('close', exitCode => { callback(null, exitCode) })
}
let testSuitesToRun = testSuitesForPlatform(process.platform)
function testSuitesForPlatform (platform) {
let suites = [];
switch (platform) {
case 'darwin':
suites = [runCoreMainProcessTests, runCoreRenderProcessTests, runBenchmarkTests].concat(packageTestSuites)
break
case 'win32':
suites = (process.arch === 'x64') ? [runCoreMainProcessTests, runCoreRenderProcessTests] : [runCoreMainProcessTests]
break
case 'linux':
suites = [runCoreMainProcessTests]
break
default:
console.log(`Unrecognized platform: ${platform}`)
}
if (argv.skipMainProcessTests) {
suites = suites.filter(suite => suite !== runCoreMainProcessTests);
}
return suites;
}
async.series(testSuitesToRun, function (err, exitCodes) {
if (err) {
console.error(err)
process.exit(1)
} else {
const testsPassed = exitCodes.every(exitCode => exitCode === 0)
process.exit(testsPassed ? 0 : 1)
}
})