mirror of
https://github.com/atom/atom.git
synced 2026-02-05 20:25:04 -05:00
Move build to script
This commit is contained in:
80
script/test.js
Executable file
80
script/test.js
Executable file
@@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
'use strict'
|
||||
|
||||
require('colors')
|
||||
const async = require('async')
|
||||
const childProcess = require('child_process')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const CONFIG = require('./config')
|
||||
|
||||
const packagedAppPath = path.resolve(__dirname, '..', 'out', 'Atom-darwin-x64')
|
||||
const executablePath = path.join(packagedAppPath, 'Atom.app', 'Contents', 'MacOS', 'Atom')
|
||||
const resourcePath = CONFIG.repositoryRootPath
|
||||
|
||||
function runCoreMainProcessTests (callback) {
|
||||
const testPath = path.join(CONFIG.repositoryRootPath, 'spec', 'main-process')
|
||||
const testArguments = [
|
||||
'--resource-path', resourcePath,
|
||||
'--test', '--main-process', testPath
|
||||
]
|
||||
|
||||
console.log('Executing core main 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) })
|
||||
}
|
||||
|
||||
function runCoreRenderProcessTests (callback) {
|
||||
const testPath = path.join(CONFIG.repositoryRootPath, 'spec')
|
||||
const testArguments = [
|
||||
'--resource-path', resourcePath,
|
||||
'--test', testPath
|
||||
]
|
||||
|
||||
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
|
||||
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
|
||||
]
|
||||
|
||||
console.log(`Executing ${packageName} tests...`.bold.green)
|
||||
const cp = childProcess.spawn(executablePath, testArguments)
|
||||
let stderrOutput = ''
|
||||
cp.stderr.on('data', data => stderrOutput += data)
|
||||
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)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const testSuitesToRun = [runCoreMainProcessTests, runCoreRenderProcessTests].concat(packageTestSuites)
|
||||
|
||||
async.parallelLimit(testSuitesToRun, 2, function (err, exitCodes) {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
process.exit(1)
|
||||
} else {
|
||||
const testsPassed = exitCodes.every(exitCode => exitCode === 0)
|
||||
process.exit(testsPassed ? 0 : 1)
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user