Skip to content

Commit 046e9ea

Browse files
author
Andy
authored
Merge pull request #9895 from Microsoft/better_web_test
Improve web tests
2 parents bd25c13 + f94025d commit 046e9ea

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

tests/webTestResults.html

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@
33
<meta charset="utf-8">
44
<title>Mocha Tests</title>
55
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
6+
<link rel="icon" href="./webhost/favicon-32x32.png"/>
67
</head>
78
<body>
8-
<div id='setup'>
9+
<div id='setup'>
910
<div>
10-
<button id='selectCompilerBtn' onclick='location.href="http://localhost:8888/tests/webTestResults.html?grep=compiler"'>Select Compiler Tests</button>
11-
<button id='selectFourslashBtn' onclick='location.href="http://localhost:8888/tests/webTestResults.html?grep=fourslash"'>Select Fourslash Tests</button>
11+
<button id='selectCompilerBtn' onclick='location.href="http://localhost:8888/tests/webTestResults.html?grep=compiler"'>Select Compiler Tests</button>
12+
<button id='selectFourslashBtn' onclick='location.href="http://localhost:8888/tests/webTestResults.html?grep=fourslash"'>Select Fourslash Tests</button>
1213
</div>
13-
<button id='runTestBtn' onclick='runTests()'>Run Tests</button>
14+
<button id='runTestBtn' onclick='runTests()'>Run Tests</button>
1415
</div>
15-
16+
1617
<div id="mocha"></div>
1718
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.0.js"></script>
1819
<script src="../node_modules/mocha/mocha.js"></script>
1920
<script>mocha.setup('bdd')</script>
2021
<script src="../built/local/bundle.js"></script>
21-
22+
2223
<script>
2324
// mocha is going to call this on every test result and make the results page unusable for a long
2425
// time after the tests are already done, doesn't seem necessary

tests/webTestServer.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function writeFile(path: string, data: any, opts: { recursive: boolean }) {
111111

112112
/// Request Handling ///
113113

114-
function handleResolutionRequest(filePath: string, res: http.ServerResponse) {
114+
function handleResolutionRequest(filePath: string, res: http.ServerResponse) {
115115
var resolvedPath = path.resolve(filePath, '');
116116
resolvedPath = resolvedPath.substring(resolvedPath.indexOf('tests'));
117117
resolvedPath = switchToForwardSlashes(resolvedPath);
@@ -202,14 +202,13 @@ function handleRequestOperation(req: http.ServerRequest, res: http.ServerRespons
202202
break;
203203
case RequestType.GetFile:
204204
fs.readFile(reqPath, function (err, file) {
205-
var ext = reqPath.substr(reqPath.lastIndexOf('.'));
206-
var contentType = 'binary';
207-
if (ext === '.js') contentType = 'text/javascript'
208-
else if (ext === '.css') contentType = 'text/javascript'
209-
else if (ext === '.html') contentType = 'text/html'
210-
err
211-
? send('fail', res, err.message, contentType)
212-
: send('success', res, (<any>file), contentType);
205+
const contentType = contentTypeForExtension(path.extname(reqPath));
206+
if (err) {
207+
send('fail', res, err.message, contentType);
208+
}
209+
else {
210+
send('success', res, <any>file, contentType);
211+
}
213212
});
214213
break;
215214
case RequestType.ResolveFile:
@@ -249,6 +248,15 @@ function handleRequestOperation(req: http.ServerRequest, res: http.ServerRespons
249248
send('unknown', res, null);
250249
break;
251250
}
251+
252+
function contentTypeForExtension(ext: string) {
253+
switch (ext) {
254+
case '.js': return 'text/javascript';
255+
case '.css': return 'text/css';
256+
case '.html': return 'text/html';
257+
default: return 'binary';
258+
}
259+
}
252260
}
253261

254262
console.log("Static file server running at\n => http://localhost:" + port + "/\nCTRL + C to shutdown");

tests/webhost/favicon-32x32.png

800 Bytes
Loading

0 commit comments

Comments
 (0)