Last active
May 12, 2016 01:16
-
-
Save MoOx/286b71cc9e4df023ce5e to your computer and use it in GitHub Desktop.
Run tap/tape tests using saucelabs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
language: node_js | |
node_js: | |
- iojs | |
env: | |
global: | |
# https://docs.saucelabs.com/ci-integrations/travis-ci/ | |
# SAUCE_USERNAME | |
- secure: Daa... | |
# SAUCE_ACCESS_KEY | |
- secure: Cf6Gx3... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import colors from "chalk" | |
export default (tapOutput) => { | |
if(tapOutput == null || !tapOutput.split) { | |
return colors.blue(tapOutput) | |
} | |
return tapOutput.split("\n").map((line) => { | |
// error | |
if ( | |
line.indexOf("not ok") === 0 || | |
line.indexOf("# not ok") === 0 || | |
line.indexOf("# fail") === 0 | |
) { | |
line = colors.red(line) | |
} | |
// | |
// success | |
else if ( | |
line === "# ok" | |
) { | |
line = colors.green(line) | |
} | |
// normal tap comment | |
else if ( | |
line.indexOf("#") === 0 | |
) { | |
line = colors.gray(line) | |
} | |
return line | |
}).join("\n") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"...": "..." | |
"scripts": { | |
"saucelabs": "babel-node --stage 0 scripts/tests/saucelabs" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fs from "fs" | |
import Runner from "sauce-tap-runner" | |
import async from "async" | |
import colors from "chalk" | |
import colorTap from "./color-tap" | |
export default function(options, callback) { | |
callback = callback || (() => {}) | |
if (!options) { | |
throw new Error("must supply an options object") | |
} | |
if (!options.name) { | |
throw new Error("must supply a project `name` option") | |
} | |
options.user = options.user || process.env.SAUCE_USERNAME | |
if (!options.user) { | |
throw new Error("must supply a saucelabs `user` option") | |
} | |
options.accessKey = options.accessKey || process.env.SAUCE_ACCESS_KEY | |
if (!options.accessKey) { | |
throw new Error("must supply a saucelabs `accessKey` option") | |
} | |
if (!options.src) { | |
throw new Error("must supply a `src` file option") | |
} | |
if (!options.desiredCapabilities) { | |
throw new Error("must supply a `desiredCapabilities` array option") | |
} | |
if (!options.build) { | |
options.build = String(Date.now()) | |
} | |
options.limit = options.limit || 3 | |
const log = options.log || console.log | |
const info = (...args) => log(colors.grey(...args)) | |
const src = fs.readFileSync(options.src, {encoding: "utf-8"}) | |
const tests = new Runner(options.user, options.accessKey) | |
tests.on("tunnel-connect", () => log( | |
colors.grey("# Starting to connect the Sauce Connect tunnel...") | |
)) | |
tests.on("tunnel", (tunnel) => log( | |
colors.grey("# The Sauce Connect tunnel has been connected!") | |
)) | |
tests.on("tunnel-error", (e) => log( | |
colors.grey("# An error occurred when connecting the Sauce Connect tunnel") | |
)) | |
tests.on("browser", (browser) => log( | |
colors.grey("# Successfully connected to a new browser") | |
)) | |
tests.on("results", (results) => log( | |
colors.grey("# Test run has finished") | |
)) | |
tests.on("close", () => log( | |
colors.grey("# The runner has been closed") | |
)) | |
const runs = options.desiredCapabilities.map( | |
(capabilities) => { | |
const comboName = | |
`${capabilities.platform} ${capabilities.browserName} ` + | |
`${capabilities.version || "latest"}` | |
capabilities = { | |
...capabilities, | |
name: `${options.name} ${comboName}`, | |
"capture-html": true, | |
build: options.build, | |
} | |
return (cb) => { | |
log() | |
log() | |
log(colors.grey.bold(`# Running ${comboName}...`)) | |
log() | |
tests.run( | |
src, | |
capabilities, | |
options.options || {}, | |
(err, results) => { | |
if (err) {throw err} | |
log() | |
log() | |
log(colors.grey.bold(`# ${capabilities.name}`)) | |
log() | |
log(colorTap(results.raw)) | |
log() | |
cb(null, results) | |
} | |
) | |
} | |
} | |
) | |
// we could imagine to run parallel tests | |
// https://github.com/conradz/sauce-tap-runner/issues/2 | |
// async.parallelLimit( | |
async.series( | |
runs, | |
// if parallel can be used, this arguments must be added | |
// options.limit, | |
(err, results) => { | |
if (err) {throw err} | |
// TODO: add a summary | |
const allOk = results.some((result) => result.ok) | |
log(colors[allOk ? "green" : "red"]("# All tests run completed")) | |
tests.close(() => { | |
if (callback) { | |
return callback(err) | |
} | |
}) | |
} | |
) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pkg from "../package" | |
import test from "./saucelabs-tap-runner" | |
test({ | |
name: pkg.name, | |
src: "dist/__dev__/tests.js", | |
desiredCapabilities: [ | |
{ | |
browserName: "internet explorer", | |
platform: "Windows 8.1", | |
version: "11", | |
}, | |
{ | |
browserName: "chrome", | |
platform: "Windows 8.1", | |
}, | |
{ | |
browserName: "firefox", | |
platform: "Windows 8.1", | |
}, | |
{ | |
browserName: "safari", | |
platform: "OS X 10.10", | |
}, | |
{ | |
browserName: "iphone", | |
}, | |
{ | |
browserName: "ipad", | |
}, | |
], | |
options: { | |
timeout: 60 * 1000, | |
}, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment