Skip to content

Commit 58831cc

Browse files
committed
fix
1 parent 7dfbc48 commit 58831cc

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

spec/helper.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ if (dns.setDefaultResultOrder) {
2525
jasmine.DEFAULT_TIMEOUT_INTERVAL = process.env.PARSE_SERVER_TEST_TIMEOUT || 10000;
2626
jasmine.getEnv().addReporter(new CurrentSpecReporter());
2727
jasmine.getEnv().addReporter(new SpecReporter());
28+
global.normalizeAsyncTests();
2829
global.on_db = (db, callback, elseCallback) => {
2930
if (process.env.PARSE_SERVER_TEST_DB == db) {
3031
return callback();

spec/support/CurrentSpecReporter.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,27 @@ global.displayTestStats = function() {
4343
console.log('\n');
4444
};
4545

46+
/**
47+
* Wraps test functions that use both `async` and a `done` callback, which Jasmine
48+
* does not support. This converts `async (done) => { ... }` to a promise-based
49+
* function so Jasmine does not throw:
50+
* "An asynchronous before/it/after function was defined with the async keyword
51+
* but also took a done callback."
52+
*/
53+
global.normalizeAsyncTests = function() {
54+
const originalSpecConstructor = jasmine.Spec;
55+
jasmine.Spec = function(attrs) {
56+
const spec = new originalSpecConstructor(attrs);
57+
const originalTestFn = spec.queueableFn.fn;
58+
if (originalTestFn.length > 0) {
59+
spec.queueableFn.fn = function() {
60+
return new Promise((resolve) => {
61+
originalTestFn(resolve);
62+
});
63+
};
64+
}
65+
return spec;
66+
};
67+
};
68+
4669
module.exports = CurrentSpecReporter;

0 commit comments

Comments
 (0)