Skip to content

Commit 2fc90d0

Browse files
committed
Merge pull request #2925 from Microsoft/properMochaUseInProjectRunner
wrap project runner tests in 'it' instead of executing them in 'describe'
2 parents 824808c + b562973 commit 2fc90d0

File tree

1 file changed

+56
-38
lines changed

1 file changed

+56
-38
lines changed

src/harness/projectsRunner.ts

Lines changed: 56 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,9 @@ class ProjectRunner extends RunnerBase {
328328
return Harness.Compiler.getErrorBaseline(inputFiles, diagnostics);
329329
}
330330

331-
describe('Compiling project for ' + testCase.scenario + ': testcase ' + testCaseFileName, () => {
331+
var name = 'Compiling project for ' + testCase.scenario + ': testcase ' + testCaseFileName;
332+
333+
describe(name, () => {
332334
function verifyCompilerResults(compilerResult: BatchCompileProjectTestCaseResult) {
333335
function getCompilerResolutionInfo() {
334336
var resolutionInfo: ProjectRunnerTestCaseResolutionInfo = {
@@ -405,51 +407,67 @@ class ProjectRunner extends RunnerBase {
405407
}
406408
}
407409

408-
// Compile using node
409-
var nodeCompilerResult = batchCompilerProjectTestCase(ts.ModuleKind.CommonJS);
410-
verifyCompilerResults(nodeCompilerResult);
410+
var nodeCompilerResult: BatchCompileProjectTestCaseResult;
411+
var amdCompilerResult: BatchCompileProjectTestCaseResult;
412+
413+
it(name + ": node", () => {
414+
// Compile using node
415+
nodeCompilerResult = batchCompilerProjectTestCase(ts.ModuleKind.CommonJS);
416+
verifyCompilerResults(nodeCompilerResult);
417+
});
411418

412-
// Compile using amd
413-
var amdCompilerResult = batchCompilerProjectTestCase(ts.ModuleKind.AMD);
414-
verifyCompilerResults(amdCompilerResult);
419+
420+
it(name + ": amd", () => {
421+
// Compile using amd
422+
amdCompilerResult = batchCompilerProjectTestCase(ts.ModuleKind.AMD);
423+
verifyCompilerResults(amdCompilerResult);
424+
});
415425

416426
if (testCase.runTest) {
417-
//TODO(ryanca/danquirk): Either support this or remove this option from the interface as well as test case json files
418-
// Node results
419-
assert.isTrue(!nodeCompilerResult.nonSubfolderDiskFiles, "Cant run test case that generates parent folders/absolute path");
420-
//it("runs without error: (" + moduleNameToString(nodeCompilerResult.moduleKind) + ')', function (done: any) {
421-
// Exec.exec("node.exe", ['"' + baseLineLocalPath(nodeCompilerResult.outputFiles[0].diskRelativeName, nodeCompilerResult.moduleKind) + '"'], function (res) {
422-
// Harness.Assert.equal(res.stdout, "");
423-
// Harness.Assert.equal(res.stderr, "");
424-
// done();
425-
// })
426-
//});
427-
428-
// Amd results
429-
assert.isTrue(!amdCompilerResult.nonSubfolderDiskFiles, "Cant run test case that generates parent folders/absolute path");
430-
//var amdDriverTemplate = "var requirejs = require('../r.js');\n\n" +
431-
// "requirejs.config({\n" +
432-
// " nodeRequire: require\n" +
433-
// "});\n\n" +
434-
// "requirejs(['{0}'],\n" +
435-
// "function ({0}) {\n" +
436-
// "});";
437-
//var moduleName = baseLineLocalPath(amdCompilerResult.outputFiles[0].diskRelativeName, amdCompilerResult.moduleKind).replace(/\.js$/, "");
438-
//sys.writeFile(testCase.projectRoot + '/driver.js', amdDriverTemplate.replace(/\{0}/g, moduleName));
439-
//it("runs without error (" + moduleNameToString(amdCompilerResult.moduleKind) + ')', function (done: any) {
440-
// Exec.exec("node.exe", ['"' + testCase.projectRoot + '/driver.js"'], function (res) {
441-
// Harness.Assert.equal(res.stdout, "");
442-
// Harness.Assert.equal(res.stderr, "");
443-
// done();
444-
// })
445-
//});
427+
it(name + ": runTest", () => {
428+
if (!nodeCompilerResult || !amdCompilerResult) {
429+
return;
430+
}
431+
//TODO(ryanca/danquirk): Either support this or remove this option from the interface as well as test case json files
432+
// Node results
433+
assert.isTrue(!nodeCompilerResult.nonSubfolderDiskFiles, "Cant run test case that generates parent folders/absolute path");
434+
//it("runs without error: (" + moduleNameToString(nodeCompilerResult.moduleKind) + ')', function (done: any) {
435+
// Exec.exec("node.exe", ['"' + baseLineLocalPath(nodeCompilerResult.outputFiles[0].diskRelativeName, nodeCompilerResult.moduleKind) + '"'], function (res) {
436+
// Harness.Assert.equal(res.stdout, "");
437+
// Harness.Assert.equal(res.stderr, "");
438+
// done();
439+
// })
440+
//});
441+
442+
// Amd results
443+
assert.isTrue(!amdCompilerResult.nonSubfolderDiskFiles, "Cant run test case that generates parent folders/absolute path");
444+
//var amdDriverTemplate = "var requirejs = require('../r.js');\n\n" +
445+
// "requirejs.config({\n" +
446+
// " nodeRequire: require\n" +
447+
// "});\n\n" +
448+
// "requirejs(['{0}'],\n" +
449+
// "function ({0}) {\n" +
450+
// "});";
451+
//var moduleName = baseLineLocalPath(amdCompilerResult.outputFiles[0].diskRelativeName, amdCompilerResult.moduleKind).replace(/\.js$/, "");
452+
//sys.writeFile(testCase.projectRoot + '/driver.js', amdDriverTemplate.replace(/\{0}/g, moduleName));
453+
//it("runs without error (" + moduleNameToString(amdCompilerResult.moduleKind) + ')', function (done: any) {
454+
// Exec.exec("node.exe", ['"' + testCase.projectRoot + '/driver.js"'], function (res) {
455+
// Harness.Assert.equal(res.stdout, "");
456+
// Harness.Assert.equal(res.stderr, "");
457+
// done();
458+
// })
459+
//});
460+
});
461+
462+
after(() => {
463+
nodeCompilerResult = undefined;
464+
amdCompilerResult = undefined;
465+
});
446466
}
447467

448468
after(() => {
449469
// Mocha holds onto the closure environment of the describe callback even after the test is done.
450470
// Therefore we have to clean out large objects after the test is done.
451-
nodeCompilerResult = undefined;
452-
amdCompilerResult = undefined;
453471
testCase = undefined;
454472
testFileText = undefined;
455473
testCaseJustName = undefined;

0 commit comments

Comments
 (0)