Skip to content

Commit

Permalink
Download chromedriver and run integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio Scandurra committed Aug 11, 2016
1 parent 3e42e65 commit 6f9a820
Showing 4 changed files with 60 additions and 3 deletions.
1 change: 1 addition & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ machine:
XCODE_SCHEME: test
XCODE_WORKSPACE: test
XCODE_PROJECT: test
ATOM_INTEGRATION_TESTS_ENABLED: true

xcode:
version: 7.3
56 changes: 56 additions & 0 deletions script/lib/download-chromedriver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
'use strict'

const assert = require('assert')
const childProcess = require('child_process')
const downloadFileFromGithub = require('./download-file-from-github')
const fs = require('fs-extra')
const path = require('path')
const semver = require('semver')
const syncRequest = require('sync-request')

const CONFIG = require('../config')

module.exports = function () {
if (process.platform === 'darwin') {
// Chromedriver is only distributed with the first patch release for any given
// major and minor version of electron.
const electronVersion = semver.parse(CONFIG.appMetadata.electronVersion)
const electronVersionWithChromedriver = `${electronVersion.major}.${electronVersion.minor}.0`
const electronAssets = getElectronAssetsForVersion(electronVersionWithChromedriver)
const chromedriverAssets = electronAssets.filter(e => /chromedriver.*darwin-x64/.test(e.name))
assert(chromedriverAssets.length === 1, 'Found more than one chrome driver asset to download!')
const chromedriverAsset = chromedriverAssets[0]

const chromedriverZipPath = path.join(CONFIG.electronDownloadPath, chromedriverAsset.name)
if (!fs.existsSync(chromedriverZipPath)) {
downloadFileFromGithub(chromedriverAsset.url, chromedriverZipPath)
}

const chromedriverDirPath = path.join(CONFIG.electronDownloadPath, 'chromedriver')
unzipPath(chromedriverZipPath, chromedriverDirPath)
} else {
throw new Error('Downloading chromedriver for platforms other than macOS is unsupported!')
}
}

function getElectronAssetsForVersion (version) {
const releaseURL = `https://api.github.com/repos/electron/electron/releases/tags/v${version}`
const response = syncRequest('GET', releaseURL, {'headers': {'User-Agent': 'Atom Build'}})

if (response.statusCode === 200) {
const release = JSON.parse(response.body)
return release.assets.map(a => { return {name: a.name, url: a.browser_download_url} })
} else {
throw new Error(`Error getting assets for ${releaseURL}. HTTP Status ${response.statusCode}.`)
}
}

function unzipPath (inputPath, outputPath) {
if (fs.existsSync(outputPath)) {
console.log(`Removing "${outputPath}"`)
fs.removeSync(outputPath)
}

console.log(`Unzipping "${inputPath}" to "${outputPath}"`)
childProcess.spawnSync('unzip', [inputPath, '-d', outputPath])
}
3 changes: 3 additions & 0 deletions script/test
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
require('colors')
const async = require('async')
const childProcess = require('child_process')
const downloadChromedriver = require('./lib/download-chromedriver')
const fs = require('fs')
const path = require('path')

@@ -15,6 +16,8 @@ const packagedAppPath = path.resolve(__dirname, '..', 'out', `${appName}.app`)
const executablePath = path.join(packagedAppPath, 'Contents', 'MacOS', appName)
const resourcePath = CONFIG.repositoryRootPath

downloadChromedriver()

function runCoreMainProcessTests (callback) {
const testPath = path.join(CONFIG.repositoryRootPath, 'spec', 'main-process')
const testArguments = [
3 changes: 0 additions & 3 deletions spec/integration/startup-spec.coffee
Original file line number Diff line number Diff line change
@@ -2,9 +2,6 @@
#
# ATOM_INTEGRATION_TESTS_ENABLED=true apm test
return unless process.env.ATOM_INTEGRATION_TESTS_ENABLED
# Integration tests require a fast machine and, for now, we cannot afford to
# run them on Travis.
return if process.env.CI

fs = require 'fs-plus'
path = require 'path'

0 comments on commit 6f9a820

Please sign in to comment.