Skip to content
This repository has been archived by the owner on Dec 6, 2022. It is now read-only.

Commit

Permalink
Fix issue with test.only hiding failures
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Dec 31, 2016
1 parent 83b3f64 commit ff55b4e
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions test/int/testSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,37 @@ let dc: DebugClient;

let unhandledAdapterErrors: string[];
const origTest = test;
const checkLogTest = (expectation: string, testCallback?: any, testFn: Function = origTest): Mocha.ITest => {
const checkLogTest = (title: string, testCallback?: any, testFn: Function = origTest): Mocha.ITest => {
// Hack to always check logs after a test runs, can simplify after this issue:
// https://github.com/mochajs/mocha/issues/1635
if (!testCallback) {
return origTest(expectation, testCallback);
return origTest(title, testCallback);
}

function runTest(): Promise<any> {
return new Promise((resolve, reject) => {
const maybeP = testCallback(resolve);
const optionalCallback = e => {
if (e) reject(e)
else resolve();
};

const maybeP = testCallback(optionalCallback);
if (maybeP && maybeP.then) {
maybeP.then(resolve, reject);
}
});
}

return testFn(expectation, done => {
runTest()
return testFn(title, () => {
return runTest()
.then(() => {
// If any unhandled errors were logged, then ensure the test fails
if (unhandledAdapterErrors.length) {
const errStr = unhandledAdapterErrors.length === 1 ? unhandledAdapterErrors[0] :
JSON.stringify(unhandledAdapterErrors);
throw new Error(errStr);
}
})
.then(done, done)
});
});
};
(<Mocha.ITestDefinition>checkLogTest).only = (expectation, assertion) => checkLogTest(expectation, assertion, origTest.only);
Expand Down

0 comments on commit ff55b4e

Please sign in to comment.