-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: convert test webserver to module
- Loading branch information
1 parent
3066804
commit ef6ed5d
Showing
6 changed files
with
70 additions
and
88 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,63 @@ | ||
var express = require('express'), | ||
cors = require('cors'); | ||
|
||
/** | ||
* Runs a simple web server that runs the mocha.html tests | ||
* This is useful if you need to run the mocha tests visually | ||
* via a tunnel to your localhost server | ||
* | ||
* @param playwrightTest - used to let this script know that tests are | ||
* running in a playwright context. When truthy, a different html document is | ||
* returned on 'GET /' and console logging is skipped. | ||
*/ | ||
|
||
class MochaServer { | ||
constructor(playwrightTest) { | ||
this.playwrightTest = playwrightTest; | ||
} | ||
|
||
async listen() { | ||
const server = express(); | ||
this.server = server; | ||
server.use(function (req, res, next) { | ||
if (!this.playwrightTest) console.log('%s %s %s', req.method, req.url, req.path); | ||
next(); | ||
}); | ||
|
||
server.use(cors()); | ||
|
||
server.get('/', function (req, res) { | ||
if (this.playwrightTest) { | ||
res.redirect('/playwright.html'); | ||
} else { | ||
res.redirect('/mocha.html'); | ||
} | ||
}); | ||
|
||
server.use('/node_modules', express.static(__dirname + '/../node_modules')); | ||
server.use('/test', express.static(__dirname)); | ||
server.use('/browser', express.static(__dirname + '/../src/web')); | ||
server.use('/build', express.static(__dirname + '/../build')); | ||
server.use(express.static(__dirname)); | ||
|
||
var port = process.env.PORT || 3000; | ||
server.listen(port); | ||
|
||
console.log('Mocha test server listening on http://localhost:3000/'); | ||
|
||
await new Promise((resolve) => { | ||
process.on('SIGTERM', () => { | ||
resolve(); | ||
}); | ||
process.on('SIGINT', () => { | ||
resolve(); | ||
}); | ||
}); | ||
} | ||
|
||
close() { | ||
this.server.close(); | ||
} | ||
} | ||
|
||
module.exports = MochaServer; |