2016-07-29 18:42:56 +03:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
'use strict'
|
|
|
|
|
|
|
|
require('colors')
|
2019-01-09 04:36:27 +03:00
|
|
|
const argv = require('yargs')
|
|
|
|
.option('core-main', {
|
|
|
|
describe: 'Run core main process tests',
|
|
|
|
boolean: true,
|
|
|
|
default: false
|
|
|
|
})
|
|
|
|
.option('skip-main', {
|
|
|
|
describe: 'Skip main process tests if they would otherwise run on your platform',
|
|
|
|
boolean: true,
|
|
|
|
default: false,
|
|
|
|
conflicts: 'core-main'
|
|
|
|
})
|
|
|
|
.option('core-renderer', {
|
|
|
|
describe: 'Run core renderer process tests',
|
|
|
|
boolean: true,
|
|
|
|
default: false
|
|
|
|
})
|
|
|
|
.option('core-benchmark', {
|
|
|
|
describe: 'Run core benchmarks',
|
|
|
|
boolean: true,
|
|
|
|
default: false
|
|
|
|
})
|
|
|
|
.option('package', {
|
|
|
|
describe: 'Run bundled package specs',
|
|
|
|
boolean: true,
|
|
|
|
default: false
|
|
|
|
})
|
|
|
|
.help()
|
|
|
|
.argv
|
|
|
|
|
2016-09-09 12:05:51 +03:00
|
|
|
const assert = require('assert')
|
2016-07-29 21:23:28 +03:00
|
|
|
const async = require('async')
|
2016-07-29 18:42:56 +03:00
|
|
|
const childProcess = require('child_process')
|
2017-05-09 16:21:26 +03:00
|
|
|
const fs = require('fs-extra')
|
2016-09-09 12:05:51 +03:00
|
|
|
const glob = require('glob')
|
2016-07-29 21:23:28 +03:00
|
|
|
const path = require('path')
|
|
|
|
|
2016-07-29 18:42:56 +03:00
|
|
|
const CONFIG = require('./config')
|
2017-05-17 16:51:19 +03:00
|
|
|
const backupNodeModules = require('./lib/backup-node-modules')
|
2017-05-09 16:21:26 +03:00
|
|
|
const runApmInstall = require('./lib/run-apm-install')
|
2016-07-29 18:42:56 +03:00
|
|
|
|
|
|
|
const resourcePath = CONFIG.repositoryRootPath
|
2016-09-09 12:05:51 +03:00
|
|
|
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') {
|
2018-05-07 19:53:31 +03:00
|
|
|
const executablePaths = glob.sync(path.join(CONFIG.buildOutputPath, 'atom-*', 'atom'))
|
2016-09-09 12:05:51 +03:00
|
|
|
assert(executablePaths.length === 1, `More than one application to run tests against was found. ${executablePaths.join(',')}`)
|
|
|
|
executablePath = executablePaths[0]
|
2016-09-09 13:07:03 +03:00
|
|
|
} 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.')
|
2016-09-09 12:05:51 +03:00
|
|
|
}
|
2016-07-29 21:10:05 +03:00
|
|
|
|
2017-07-29 03:56:27 +03:00
|
|
|
function prepareEnv (suiteName) {
|
2017-07-29 23:42:53 +03:00
|
|
|
const env = Object.assign({}, process.env)
|
2017-07-29 03:56:27 +03:00
|
|
|
|
2017-07-29 23:35:00 +03:00
|
|
|
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.
|
2019-02-16 00:09:27 +03:00
|
|
|
const fileName = suiteName + '.xml'
|
2019-02-12 19:59:20 +03:00
|
|
|
const outputPath = path.join(process.env.TEST_JUNIT_XML_ROOT, fileName)
|
2017-07-29 03:56:27 +03:00
|
|
|
env.TEST_JUNIT_XML_PATH = outputPath
|
|
|
|
}
|
|
|
|
|
|
|
|
return env
|
|
|
|
}
|
|
|
|
|
2016-07-29 21:10:05 +03:00
|
|
|
function runCoreMainProcessTests (callback) {
|
|
|
|
const testPath = path.join(CONFIG.repositoryRootPath, 'spec', 'main-process')
|
|
|
|
const testArguments = [
|
|
|
|
'--resource-path', resourcePath,
|
|
|
|
'--test', '--main-process', testPath
|
|
|
|
]
|
2019-02-16 00:09:27 +03:00
|
|
|
const testEnv = Object.assign({}, prepareEnv('core-main-process'), {ATOM_GITHUB_INLINE_GIT_EXEC: 'true'})
|
2017-07-31 22:07:05 +03:00
|
|
|
|
2016-08-08 16:18:21 +03:00
|
|
|
console.log('Executing core main process tests'.bold.green)
|
2017-07-29 03:56:27 +03:00
|
|
|
const cp = childProcess.spawn(executablePath, testArguments, {stdio: 'inherit', env: testEnv})
|
2016-07-29 21:10:05 +03:00
|
|
|
cp.on('error', error => { callback(error) })
|
2019-04-12 13:52:55 +03:00
|
|
|
cp.on('close', exitCode => { callback(null, {exitCode}) })
|
2016-07-29 21:10:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function runCoreRenderProcessTests (callback) {
|
|
|
|
const testPath = path.join(CONFIG.repositoryRootPath, 'spec')
|
|
|
|
const testArguments = [
|
|
|
|
'--resource-path', resourcePath,
|
|
|
|
'--test', testPath
|
|
|
|
]
|
2019-02-16 00:09:27 +03:00
|
|
|
const testEnv = prepareEnv('core-render-process')
|
2016-07-29 21:10:05 +03:00
|
|
|
|
2016-08-08 16:18:21 +03:00
|
|
|
console.log('Executing core render process tests'.bold.green)
|
2017-07-29 03:56:27 +03:00
|
|
|
const cp = childProcess.spawn(executablePath, testArguments, {stdio: 'inherit', env: testEnv})
|
2016-07-29 21:00:34 +03:00
|
|
|
cp.on('error', error => { callback(error) })
|
2019-04-12 13:52:55 +03:00
|
|
|
cp.on('close', exitCode => { callback(null, {exitCode}) })
|
2016-07-29 21:00:34 +03:00
|
|
|
}
|
|
|
|
|
2016-07-29 21:32:40 +03:00
|
|
|
// Build an array of functions, each running tests for a different bundled package
|
2016-07-29 21:23:28 +03:00
|
|
|
const packageTestSuites = []
|
|
|
|
for (let packageName in CONFIG.appMetadata.packageDependencies) {
|
2017-05-10 13:55:10 +03:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2017-05-09 16:21:26 +03:00
|
|
|
const repositoryPackagePath = path.join(CONFIG.repositoryRootPath, 'node_modules', packageName)
|
2017-05-10 08:46:31 +03:00
|
|
|
const testSubdir = ['spec', 'test'].find(subdir => fs.existsSync(path.join(repositoryPackagePath, subdir)))
|
2017-05-09 16:21:26 +03:00
|
|
|
|
|
|
|
if (!testSubdir) {
|
2017-05-10 08:46:31 +03:00
|
|
|
packageTestSuites.push(function (callback) {
|
|
|
|
console.log(`Skipping tests for ${packageName} because no test folder was found`.bold.yellow)
|
2019-04-12 13:52:55 +03:00
|
|
|
callback(null, {exitCode: 0})
|
2017-05-10 08:46:31 +03:00
|
|
|
})
|
2017-05-09 16:21:26 +03:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2017-05-10 08:46:31 +03:00
|
|
|
const testFolder = path.join(repositoryPackagePath, testSubdir)
|
2016-07-29 21:23:28 +03:00
|
|
|
|
|
|
|
packageTestSuites.push(function (callback) {
|
|
|
|
const testArguments = [
|
|
|
|
'--resource-path', resourcePath,
|
2017-05-10 08:46:31 +03:00
|
|
|
'--test', testFolder
|
2016-07-29 21:23:28 +03:00
|
|
|
]
|
2019-02-16 00:09:27 +03:00
|
|
|
const testEnv = prepareEnv(`bundled-package-${packageName}`)
|
2016-07-29 21:23:28 +03:00
|
|
|
|
2017-05-10 08:46:31 +03:00
|
|
|
const pkgJsonPath = path.join(repositoryPackagePath, 'package.json')
|
2017-05-10 13:55:55 +03:00
|
|
|
const nodeModulesPath = path.join(repositoryPackagePath, 'node_modules')
|
|
|
|
let finalize = () => null
|
2017-05-10 08:09:04 +03:00
|
|
|
if (require(pkgJsonPath).atomTestRunner) {
|
2017-05-10 08:46:31 +03:00
|
|
|
console.log(`Installing test runner dependencies for ${packageName}`.bold.green)
|
2017-05-10 13:55:55 +03:00
|
|
|
if (fs.existsSync(nodeModulesPath)) {
|
2017-05-17 20:01:36 +03:00
|
|
|
const backup = backupNodeModules(repositoryPackagePath)
|
|
|
|
finalize = backup.restore
|
2017-05-10 13:55:55 +03:00
|
|
|
} else {
|
|
|
|
finalize = () => fs.removeSync(nodeModulesPath)
|
|
|
|
}
|
2017-05-10 08:46:31 +03:00
|
|
|
runApmInstall(repositoryPackagePath)
|
2017-05-10 08:09:04 +03:00
|
|
|
console.log(`Executing ${packageName} tests`.green)
|
|
|
|
} else {
|
|
|
|
console.log(`Executing ${packageName} tests`.bold.green)
|
|
|
|
}
|
2017-07-29 03:56:27 +03:00
|
|
|
const cp = childProcess.spawn(executablePath, testArguments, {env: testEnv})
|
2016-07-29 21:32:40 +03:00
|
|
|
let stderrOutput = ''
|
2017-03-24 18:38:11 +03:00
|
|
|
cp.stderr.on('data', data => { stderrOutput += data })
|
2017-05-30 22:40:02 +03:00
|
|
|
cp.stdout.on('data', data => { stderrOutput += data })
|
2017-05-10 13:55:55 +03:00
|
|
|
cp.on('error', error => {
|
|
|
|
finalize()
|
|
|
|
callback(error)
|
|
|
|
})
|
2016-07-29 21:32:40 +03:00
|
|
|
cp.on('close', exitCode => {
|
|
|
|
if (exitCode !== 0) {
|
|
|
|
console.log(`Package tests failed for ${packageName}:`.red)
|
|
|
|
console.log(stderrOutput)
|
|
|
|
}
|
2017-05-10 13:55:55 +03:00
|
|
|
finalize()
|
2019-04-12 13:52:55 +03:00
|
|
|
callback(null, {exitCode})
|
2016-07-29 21:32:40 +03:00
|
|
|
})
|
2016-07-29 21:23:28 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-10-14 12:01:35 +03:00
|
|
|
function runBenchmarkTests (callback) {
|
|
|
|
const benchmarksPath = path.join(CONFIG.repositoryRootPath, 'benchmarks')
|
|
|
|
const testArguments = ['--benchmark-test', benchmarksPath]
|
2017-07-29 03:56:27 +03:00
|
|
|
const testEnv = prepareEnv('benchmark')
|
2016-10-14 12:01:35 +03:00
|
|
|
|
|
|
|
console.log('Executing benchmark tests'.bold.green)
|
2017-07-29 03:56:27 +03:00
|
|
|
const cp = childProcess.spawn(executablePath, testArguments, {stdio: 'inherit', env: testEnv})
|
2016-10-14 12:01:35 +03:00
|
|
|
cp.on('error', error => { callback(error) })
|
2019-04-12 13:52:55 +03:00
|
|
|
cp.on('close', exitCode => { callback(null, {exitCode}) })
|
2016-10-14 12:01:35 +03:00
|
|
|
}
|
|
|
|
|
2019-01-09 04:36:27 +03:00
|
|
|
let testSuitesToRun = requestedTestSuites() || testSuitesForPlatform(process.platform)
|
|
|
|
|
|
|
|
function requestedTestSuites () {
|
|
|
|
const suites = []
|
|
|
|
if (argv.coreMain) {
|
|
|
|
suites.push(runCoreMainProcessTests)
|
|
|
|
}
|
|
|
|
if (argv.coreRenderer) {
|
|
|
|
suites.push(runCoreRenderProcessTests)
|
|
|
|
}
|
|
|
|
if (argv.coreBenchmark) {
|
|
|
|
suites.push(runBenchmarkTests)
|
|
|
|
}
|
|
|
|
if (argv.package) {
|
|
|
|
suites.push(...packageTestSuites)
|
|
|
|
}
|
|
|
|
return suites.length > 0 ? suites : null
|
|
|
|
}
|
2016-11-23 02:18:47 +03:00
|
|
|
|
2017-08-02 15:18:25 +03:00
|
|
|
function testSuitesForPlatform (platform) {
|
2019-01-09 04:36:27 +03:00
|
|
|
let suites = []
|
2017-08-02 15:18:25 +03:00
|
|
|
switch (platform) {
|
|
|
|
case 'darwin':
|
2017-08-23 05:05:12 +03:00
|
|
|
suites = [runCoreMainProcessTests, runCoreRenderProcessTests, runBenchmarkTests].concat(packageTestSuites)
|
|
|
|
break
|
2017-08-02 15:18:25 +03:00
|
|
|
case 'win32':
|
2017-08-23 05:05:12 +03:00
|
|
|
suites = (process.arch === 'x64') ? [runCoreMainProcessTests, runCoreRenderProcessTests] : [runCoreMainProcessTests]
|
|
|
|
break
|
2017-08-02 15:18:25 +03:00
|
|
|
case 'linux':
|
2017-08-23 05:05:12 +03:00
|
|
|
suites = [runCoreMainProcessTests]
|
|
|
|
break
|
2017-08-02 15:18:25 +03:00
|
|
|
default:
|
|
|
|
console.log(`Unrecognized platform: ${platform}`)
|
2016-11-23 02:18:47 +03:00
|
|
|
}
|
2017-08-23 05:05:12 +03:00
|
|
|
|
2017-09-09 01:56:48 +03:00
|
|
|
if (argv.skipMainProcessTests) {
|
2019-01-09 04:36:27 +03:00
|
|
|
suites = suites.filter(suite => suite !== runCoreMainProcessTests)
|
2017-08-23 05:05:12 +03:00
|
|
|
}
|
|
|
|
|
2019-02-16 00:09:27 +03:00
|
|
|
return suites
|
2016-09-09 12:05:51 +03:00
|
|
|
}
|
2016-07-29 21:10:05 +03:00
|
|
|
|
2019-04-12 13:52:55 +03:00
|
|
|
async.series(testSuitesToRun, function (err, results) {
|
2016-07-29 21:00:34 +03:00
|
|
|
if (err) {
|
|
|
|
console.error(err)
|
|
|
|
process.exit(1)
|
|
|
|
} else {
|
2019-04-12 13:52:55 +03:00
|
|
|
const testsPassed = results.every(({exitCode}) => exitCode === 0)
|
2016-07-29 21:00:34 +03:00
|
|
|
process.exit(testsPassed ? 0 : 1)
|
|
|
|
}
|
|
|
|
})
|