Improve web tests

* Provide a favicon so chrome doesn't block waiting for one
* Provide accurate content type so chrome doesn't warn
This commit is contained in:
Andy Hanson 2016-07-01 13:34:15 -07:00
parent bd25c130ca
commit f94025d855
3 changed files with 24 additions and 15 deletions

View File

@ -3,22 +3,23 @@
<meta charset="utf-8">
<title>Mocha Tests</title>
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
<link rel="icon" href="./webhost/favicon-32x32.png"/>
</head>
<body>
<div id='setup'>
<div id='setup'>
<div>
<button id='selectCompilerBtn' onclick='location.href="http://localhost:8888/tests/webTestResults.html?grep=compiler"'>Select Compiler Tests</button>
<button id='selectFourslashBtn' onclick='location.href="http://localhost:8888/tests/webTestResults.html?grep=fourslash"'>Select Fourslash Tests</button>
<button id='selectCompilerBtn' onclick='location.href="http://localhost:8888/tests/webTestResults.html?grep=compiler"'>Select Compiler Tests</button>
<button id='selectFourslashBtn' onclick='location.href="http://localhost:8888/tests/webTestResults.html?grep=fourslash"'>Select Fourslash Tests</button>
</div>
<button id='runTestBtn' onclick='runTests()'>Run Tests</button>
<button id='runTestBtn' onclick='runTests()'>Run Tests</button>
</div>
<div id="mocha"></div>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.0.js"></script>
<script src="../node_modules/mocha/mocha.js"></script>
<script>mocha.setup('bdd')</script>
<script src="../built/local/bundle.js"></script>
<script>
// mocha is going to call this on every test result and make the results page unusable for a long
// time after the tests are already done, doesn't seem necessary

View File

@ -111,7 +111,7 @@ function writeFile(path: string, data: any, opts: { recursive: boolean }) {
/// Request Handling ///
function handleResolutionRequest(filePath: string, res: http.ServerResponse) {
function handleResolutionRequest(filePath: string, res: http.ServerResponse) {
var resolvedPath = path.resolve(filePath, '');
resolvedPath = resolvedPath.substring(resolvedPath.indexOf('tests'));
resolvedPath = switchToForwardSlashes(resolvedPath);
@ -202,14 +202,13 @@ function handleRequestOperation(req: http.ServerRequest, res: http.ServerRespons
break;
case RequestType.GetFile:
fs.readFile(reqPath, function (err, file) {
var ext = reqPath.substr(reqPath.lastIndexOf('.'));
var contentType = 'binary';
if (ext === '.js') contentType = 'text/javascript'
else if (ext === '.css') contentType = 'text/javascript'
else if (ext === '.html') contentType = 'text/html'
err
? send('fail', res, err.message, contentType)
: send('success', res, (<any>file), contentType);
const contentType = contentTypeForExtension(path.extname(reqPath));
if (err) {
send('fail', res, err.message, contentType);
}
else {
send('success', res, <any>file, contentType);
}
});
break;
case RequestType.ResolveFile:
@ -249,6 +248,15 @@ function handleRequestOperation(req: http.ServerRequest, res: http.ServerRespons
send('unknown', res, null);
break;
}
function contentTypeForExtension(ext: string) {
switch (ext) {
case '.js': return 'text/javascript';
case '.css': return 'text/css';
case '.html': return 'text/html';
default: return 'binary';
}
}
}
console.log("Static file server running at\n => http://localhost:" + port + "/\nCTRL + C to shutdown");

Binary file not shown.

After

Width:  |  Height:  |  Size: 800 B