Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable browser tests with npm test (#108)
* Enable browser tests with npm test * Add chrome-unit script * Add sudo: true to .travis.yml to support chrome testing * Add back a safe amount of parallelism * Fix bug in testserver * Run node tests in script * chrome-unit -> unit
- Loading branch information
1 parent
cbf8dad
commit ce09bc0
Showing
5 changed files
with
78 additions
and
30 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const { major } = require("semver"); | ||
const { spawn, exec } = require("child_process"); | ||
const { join } = require("path"); | ||
|
||
const webpackDevServer = spawn(join(__dirname, "../node_modules/.bin/ts-node"), [join(__dirname, "../testserver")], { shell: true }) | ||
function cleanupDevServer() { | ||
webpackDevServer.stderr.destroy(); | ||
webpackDevServer.stdout.destroy(); | ||
webpackDevServer.kill(); | ||
}; | ||
|
||
let mochaRunning = false | ||
const webpackDevServerHandler = (data) => { | ||
if (!mochaRunning) { | ||
mochaRunning = true | ||
|
||
const mochaChromePromise = new Promise((resolve, reject) => { | ||
if (major(process.version) < 8) { | ||
// Skip browser tests in pre-node 8 | ||
resolve(); | ||
} else { | ||
const mochaChromeExecutable = join(__dirname, "../node_modules/.bin/mocha-chrome"); | ||
exec(`${mochaChromeExecutable} http://localhost:3001`, (err, stdout, stderr) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
console.log(stdout); | ||
console.error(stderr); | ||
resolve(); | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
const mochaPromise = new Promise((resolve, reject) => { | ||
const mochaExecutable = join(__dirname, "../node_modules/.bin/_mocha"); | ||
const mocha = exec(mochaExecutable, (err, stdout, stderr) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
console.log(stdout); | ||
console.error(stderr); | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
|
||
Promise.all([mochaPromise, mochaChromePromise]).then(res => { | ||
cleanupDevServer(); | ||
process.exit(0); | ||
}).catch((err) => { | ||
console.error(err); | ||
cleanupDevServer(); | ||
process.exit(1); | ||
}); | ||
} | ||
} | ||
|
||
webpackDevServer.stderr.on('data', data => { | ||
console.error("webpack dev server error:", data.toString()); | ||
}); | ||
|
||
webpackDevServer.stdout.on('data', webpackDevServerHandler); | ||
webpackDevServer.on('exit', webpackDevServerHandler); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
language: node_js | ||
sudo: false | ||
sudo: true | ||
addons: | ||
chrome: stable | ||
node_js: | ||
- "6" | ||
- "8" |
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
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
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