pulsar/script/test

96 lines
3.3 KiB
Plaintext
Raw Normal View History

2016-07-29 18:42:56 +03:00
#!/usr/bin/env node
'use strict'
require('colors')
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')
2016-07-29 21:23:28 +03:00
const fs = require('fs')
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')
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') {
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]
}
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
]
2016-08-08 16:18:21 +03:00
console.log('Executing core main process tests'.bold.green)
2016-07-29 21:10:05 +03:00
const cp = childProcess.spawn(executablePath, testArguments, {stdio: 'inherit'})
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
]
2016-08-08 16:18:21 +03:00
console.log('Executing core render process tests'.bold.green)
const cp = childProcess.spawn(executablePath, testArguments, {stdio: 'inherit'})
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
2016-07-29 21:23:28 +03:00
const packageTestSuites = []
for (let packageName in CONFIG.appMetadata.packageDependencies) {
const packageSpecDirPath = path.join(CONFIG.repositoryRootPath, 'node_modules', packageName, 'spec')
if (!fs.existsSync(packageSpecDirPath)) continue
packageTestSuites.push(function (callback) {
const testArguments = [
'--resource-path', resourcePath,
'--test', packageSpecDirPath
]
2016-08-08 16:18:21 +03:00
console.log(`Executing ${packageName} tests`.bold.green)
const cp = childProcess.spawn(executablePath, testArguments)
let stderrOutput = ''
cp.stderr.on('data', data => stderrOutput += data)
2016-07-29 21:23:28 +03:00
cp.on('error', error => { callback(error) })
cp.on('close', exitCode => {
if (exitCode !== 0) {
console.log(`Package tests failed for ${packageName}:`.red)
console.log(stderrOutput)
}
callback(null, exitCode)
})
2016-07-29 21:23:28 +03:00
})
}
2016-09-09 12:05:51 +03:00
let testSuitesToRun
if (process.platform === 'darwin') {
testSuitesToRun = [runCoreMainProcessTests, runCoreRenderProcessTests].concat(packageTestSuites)
} else {
testSuitesToRun = [runCoreMainProcessTests]
}
2016-07-29 21:10:05 +03:00
2016-08-11 14:50:02 +03:00
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)
}
})