feat: make mocha a zone module. (#34719)

PR Close #34719
This commit is contained in:
JiaLiPassion 2020-01-31 22:54:44 +09:00 committed by Kara Erickson
parent 81241af7ac
commit 332937ef24
3 changed files with 33 additions and 24 deletions

View File

@ -55,6 +55,12 @@ Below is the full list of currently supported modules.
|handleUnhandledPromiseRejection|NodeJS handle unhandledPromiseRejection from ZoneAwarePromise|__Zone_disable_handleUnhandledPromiseRejection = true| |handleUnhandledPromiseRejection|NodeJS handle unhandledPromiseRejection from ZoneAwarePromise|__Zone_disable_handleUnhandledPromiseRejection = true|
|crypto|NodeJS patch crypto function as macroTask|__Zone_disable_crypto = true| |crypto|NodeJS patch crypto function as macroTask|__Zone_disable_crypto = true|
- Test Framework
|Module Name|Behavior with zone.js patch|How to disable|
|--|--|--|
|Jasmine|Jasmine APIs patch|__Zone_disable_jasmine = true|
|Mocha|Mocha APIs patch|__Zone_disable_mocha = true|
- on_property - on_property
You can also disable specific on_properties by setting `__Zone_ignore_on_properties` as follows: for example, You can also disable specific on_properties by setting `__Zone_ignore_on_properties` as follows: for example,

View File

@ -8,11 +8,13 @@
'use strict'; 'use strict';
((context: any) => { Zone.__load_patch('mocha', (global: any, Zone: ZoneType) => {
const Mocha = context.Mocha; const Mocha = global.Mocha;
if (typeof Mocha === 'undefined') { if (typeof Mocha === 'undefined') {
throw new Error('Missing Mocha.js'); // return if Mocha is not available, because now zone-testing
// will load mocha patch with jasmine/jest patch
return;
} }
if (typeof Zone === 'undefined') { if (typeof Zone === 'undefined') {
@ -97,42 +99,42 @@
return modifyArguments(args, syncTest, asyncTest); return modifyArguments(args, syncTest, asyncTest);
} }
context.describe = context.suite = Mocha.describe = function() { global.describe = global.suite = Mocha.describe = function() {
return mochaOriginal.describe.apply(this, wrapDescribeInZone(arguments)); return mochaOriginal.describe.apply(this, wrapDescribeInZone(arguments));
}; };
context.xdescribe = context.suite.skip = Mocha.describe.skip = function() { global.xdescribe = global.suite.skip = Mocha.describe.skip = function() {
return mochaOriginal.describe.skip.apply(this, wrapDescribeInZone(arguments)); return mochaOriginal.describe.skip.apply(this, wrapDescribeInZone(arguments));
}; };
context.describe.only = context.suite.only = Mocha.describe.only = function() { global.describe.only = global.suite.only = Mocha.describe.only = function() {
return mochaOriginal.describe.only.apply(this, wrapDescribeInZone(arguments)); return mochaOriginal.describe.only.apply(this, wrapDescribeInZone(arguments));
}; };
context.it = context.specify = context.test = global.it = global.specify = global.test =
Mocha.it = function() { return mochaOriginal.it.apply(this, wrapTestInZone(arguments)); }; Mocha.it = function() { return mochaOriginal.it.apply(this, wrapTestInZone(arguments)); };
context.xit = context.xspecify = Mocha.it.skip = function() { global.xit = global.xspecify = Mocha.it.skip = function() {
return mochaOriginal.it.skip.apply(this, wrapTestInZone(arguments)); return mochaOriginal.it.skip.apply(this, wrapTestInZone(arguments));
}; };
context.it.only = context.test.only = Mocha.it.only = function() { global.it.only = global.test.only = Mocha.it.only = function() {
return mochaOriginal.it.only.apply(this, wrapTestInZone(arguments)); return mochaOriginal.it.only.apply(this, wrapTestInZone(arguments));
}; };
context.after = context.suiteTeardown = Mocha.after = function() { global.after = global.suiteTeardown = Mocha.after = function() {
return mochaOriginal.after.apply(this, wrapSuiteInZone(arguments)); return mochaOriginal.after.apply(this, wrapSuiteInZone(arguments));
}; };
context.afterEach = context.teardown = Mocha.afterEach = function() { global.afterEach = global.teardown = Mocha.afterEach = function() {
return mochaOriginal.afterEach.apply(this, wrapTestInZone(arguments)); return mochaOriginal.afterEach.apply(this, wrapTestInZone(arguments));
}; };
context.before = context.suiteSetup = Mocha.before = function() { global.before = global.suiteSetup = Mocha.before = function() {
return mochaOriginal.before.apply(this, wrapSuiteInZone(arguments)); return mochaOriginal.before.apply(this, wrapSuiteInZone(arguments));
}; };
context.beforeEach = context.setup = Mocha.beforeEach = function() { global.beforeEach = global.setup = Mocha.beforeEach = function() {
return mochaOriginal.beforeEach.apply(this, wrapTestInZone(arguments)); return mochaOriginal.beforeEach.apply(this, wrapTestInZone(arguments));
}; };
@ -158,4 +160,4 @@
return originalRun.call(this, fn); return originalRun.call(this, fn);
}; };
})(Mocha.Runner.prototype.runTest, Mocha.Runner.prototype.run); })(Mocha.Runner.prototype.runTest, Mocha.Runner.prototype.run);
})(typeof window !== 'undefined' && window || typeof self !== 'undefined' && self || global); });

View File

@ -12,6 +12,7 @@ import '../zone-spec/proxy';
import '../zone-spec/sync-test'; import '../zone-spec/sync-test';
import '../jasmine/jasmine'; import '../jasmine/jasmine';
import '../jest/jest'; import '../jest/jest';
import '../mocha/mocha';
import './async-testing'; import './async-testing';
import './fake-async'; import './fake-async';
import './promise-testing'; import './promise-testing';