0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-11-29 11:24:18 +01:00
Bootstrap/build/saucelabs-unit-test.js

111 lines
3.0 KiB
JavaScript
Raw Normal View History

/*!
* Script to run our Sauce Labs tests.
* Copyright 2017 The Bootstrap Authors
* Copyright 2017 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
*/
/*
Docs: https://wiki.saucelabs.com/display/DOCS/Platform+Configurator
Mac Opera is not currently supported by Sauce Labs
Win Opera 15+ is not currently supported by Sauce Labs
iOS Chrome is not currently supported by Sauce Labs
*/
2017-09-28 17:18:20 +02:00
'use strict'
const path = require('path')
const JSUnitSaucelabs = require('jsunitsaucelabs')
2017-09-28 15:18:29 +02:00
const jsUnitSaucelabs = new JSUnitSaucelabs({
username: process.env.SAUCE_USERNAME,
2017-09-28 16:01:06 +02:00
password: process.env.SAUCE_ACCESS_KEY,
build: process.env.TRAVIS_JOB_ID
})
const testURL = 'http://localhost:3000/js/tests/index.html?hidepassed'
2017-09-28 17:18:20 +02:00
const browsersFile = require(path.resolve(__dirname, './sauce_browsers.json'))
let jobsDone = 0
let jobsSucceeded = 0
2017-09-28 17:18:20 +02:00
const waitingCallback = (error, body, id) => {
if (error) {
console.error(error)
process.exit(1)
}
2017-09-28 17:18:20 +02:00
if (typeof body !== 'undefined') {
if (!body.completed) {
setTimeout(() => {
jsUnitSaucelabs.getStatus(id, (error, body) => {
waitingCallback(error, body, id)
})
}, 2000)
} else {
const test = body['js tests'][0]
let passed = false
let errorStr = false
2017-09-28 15:18:29 +02:00
2017-09-28 17:18:20 +02:00
if (test.result !== null) {
if (typeof test.result === 'string' && test.result === 'Test exceeded maximum duration') {
errorStr = test.result
} else {
passed = test.result.total === test.result.passed
}
2017-09-28 17:18:20 +02:00
}
2017-09-28 17:18:20 +02:00
console.log(`Tested ${testURL}`)
console.log(`Platform: ${test.platform.join(', ')}`)
2017-09-28 17:18:20 +02:00
console.log(`Passed: ${passed.toString()}`)
console.log(`URL: ${test.url}\n`)
if (errorStr) {
console.error(errorStr)
}
2017-09-28 17:18:20 +02:00
if (passed) {
jobsSucceeded++
}
2017-09-28 17:18:20 +02:00
jobsDone++
2017-09-28 17:18:20 +02:00
// Exit
if (jobsDone === browsersFile.length - 1) {
jsUnitSaucelabs.stop()
2017-10-10 11:50:55 +02:00
if (jobsDone > jobsSucceeded) {
const failedTest = jobsDone - jobsSucceeded
throw new Error(`Some test(s) failed (${failedTest})`)
}
console.log('All tests passed')
process.exit(0)
}
}
2017-09-28 17:18:20 +02:00
}
}
jsUnitSaucelabs.on('tunnelCreated', () => {
browsersFile.forEach((tmpBrowser) => {
const browsersPlatform = typeof tmpBrowser.platform === 'undefined' ? tmpBrowser.platformName : tmpBrowser.platform
const browsersArray = [browsersPlatform, tmpBrowser.browserName, tmpBrowser.version]
jsUnitSaucelabs.start([browsersArray], testURL, 'qunit', (error, success) => {
2017-09-28 17:18:20 +02:00
if (typeof success !== 'undefined') {
const taskIds = success['js tests']
if (!taskIds || !taskIds.length) {
throw new Error('Error starting tests through Sauce Labs API')
2017-09-28 17:18:20 +02:00
}
2017-09-28 17:18:20 +02:00
taskIds.forEach((id) => {
jsUnitSaucelabs.getStatus(id, (error, body) => {
waitingCallback(error, body, id)
})
})
} else {
console.error(error)
}
})
2017-09-28 17:18:20 +02:00
})
})
2017-09-28 17:18:20 +02:00
jsUnitSaucelabs.initTunnel()