1 | 'use strict';
|
---|
2 | /**
|
---|
3 | * @license Angular v12.0.0-next.0
|
---|
4 | * (c) 2010-2020 Google LLC. https://angular.io/
|
---|
5 | * License: MIT
|
---|
6 | */
|
---|
7 | (function (factory) {
|
---|
8 | typeof define === 'function' && define.amd ? define(factory) :
|
---|
9 | factory();
|
---|
10 | }((function () {
|
---|
11 | 'use strict';
|
---|
12 | /**
|
---|
13 | * @license
|
---|
14 | * Copyright Google LLC All Rights Reserved.
|
---|
15 | *
|
---|
16 | * Use of this source code is governed by an MIT-style license that can be
|
---|
17 | * found in the LICENSE file at https://angular.io/license
|
---|
18 | */
|
---|
19 | Zone.__load_patch('mocha', function (global, Zone) {
|
---|
20 | var Mocha = global.Mocha;
|
---|
21 | if (typeof Mocha === 'undefined') {
|
---|
22 | // return if Mocha is not available, because now zone-testing
|
---|
23 | // will load mocha patch with jasmine/jest patch
|
---|
24 | return;
|
---|
25 | }
|
---|
26 | if (typeof Zone === 'undefined') {
|
---|
27 | throw new Error('Missing Zone.js');
|
---|
28 | }
|
---|
29 | var ProxyZoneSpec = Zone['ProxyZoneSpec'];
|
---|
30 | var SyncTestZoneSpec = Zone['SyncTestZoneSpec'];
|
---|
31 | if (!ProxyZoneSpec) {
|
---|
32 | throw new Error('Missing ProxyZoneSpec');
|
---|
33 | }
|
---|
34 | if (Mocha['__zone_patch__']) {
|
---|
35 | throw new Error('"Mocha" has already been patched with "Zone".');
|
---|
36 | }
|
---|
37 | Mocha['__zone_patch__'] = true;
|
---|
38 | var rootZone = Zone.current;
|
---|
39 | var syncZone = rootZone.fork(new SyncTestZoneSpec('Mocha.describe'));
|
---|
40 | var testZone = null;
|
---|
41 | var suiteZone = rootZone.fork(new ProxyZoneSpec());
|
---|
42 | var mochaOriginal = {
|
---|
43 | after: Mocha.after,
|
---|
44 | afterEach: Mocha.afterEach,
|
---|
45 | before: Mocha.before,
|
---|
46 | beforeEach: Mocha.beforeEach,
|
---|
47 | describe: Mocha.describe,
|
---|
48 | it: Mocha.it
|
---|
49 | };
|
---|
50 | function modifyArguments(args, syncTest, asyncTest) {
|
---|
51 | var _loop_1 = function (i) {
|
---|
52 | var arg = args[i];
|
---|
53 | if (typeof arg === 'function') {
|
---|
54 | // The `done` callback is only passed through if the function expects at
|
---|
55 | // least one argument.
|
---|
56 | // Note we have to make a function with correct number of arguments,
|
---|
57 | // otherwise mocha will
|
---|
58 | // think that all functions are sync or async.
|
---|
59 | args[i] = (arg.length === 0) ? syncTest(arg) : asyncTest(arg);
|
---|
60 | // Mocha uses toString to view the test body in the result list, make sure we return the
|
---|
61 | // correct function body
|
---|
62 | args[i].toString = function () {
|
---|
63 | return arg.toString();
|
---|
64 | };
|
---|
65 | }
|
---|
66 | };
|
---|
67 | for (var i = 0; i < args.length; i++) {
|
---|
68 | _loop_1(i);
|
---|
69 | }
|
---|
70 | return args;
|
---|
71 | }
|
---|
72 | function wrapDescribeInZone(args) {
|
---|
73 | var syncTest = function (fn) {
|
---|
74 | return function () {
|
---|
75 | return syncZone.run(fn, this, arguments);
|
---|
76 | };
|
---|
77 | };
|
---|
78 | return modifyArguments(args, syncTest);
|
---|
79 | }
|
---|
80 | function wrapTestInZone(args) {
|
---|
81 | var asyncTest = function (fn) {
|
---|
82 | return function (done) {
|
---|
83 | return testZone.run(fn, this, [done]);
|
---|
84 | };
|
---|
85 | };
|
---|
86 | var syncTest = function (fn) {
|
---|
87 | return function () {
|
---|
88 | return testZone.run(fn, this);
|
---|
89 | };
|
---|
90 | };
|
---|
91 | return modifyArguments(args, syncTest, asyncTest);
|
---|
92 | }
|
---|
93 | function wrapSuiteInZone(args) {
|
---|
94 | var asyncTest = function (fn) {
|
---|
95 | return function (done) {
|
---|
96 | return suiteZone.run(fn, this, [done]);
|
---|
97 | };
|
---|
98 | };
|
---|
99 | var syncTest = function (fn) {
|
---|
100 | return function () {
|
---|
101 | return suiteZone.run(fn, this);
|
---|
102 | };
|
---|
103 | };
|
---|
104 | return modifyArguments(args, syncTest, asyncTest);
|
---|
105 | }
|
---|
106 | global.describe = global.suite = Mocha.describe = function () {
|
---|
107 | return mochaOriginal.describe.apply(this, wrapDescribeInZone(arguments));
|
---|
108 | };
|
---|
109 | global.xdescribe = global.suite.skip = Mocha.describe.skip = function () {
|
---|
110 | return mochaOriginal.describe.skip.apply(this, wrapDescribeInZone(arguments));
|
---|
111 | };
|
---|
112 | global.describe.only = global.suite.only = Mocha.describe.only = function () {
|
---|
113 | return mochaOriginal.describe.only.apply(this, wrapDescribeInZone(arguments));
|
---|
114 | };
|
---|
115 | global.it = global.specify = global.test = Mocha.it = function () {
|
---|
116 | return mochaOriginal.it.apply(this, wrapTestInZone(arguments));
|
---|
117 | };
|
---|
118 | global.xit = global.xspecify = Mocha.it.skip = function () {
|
---|
119 | return mochaOriginal.it.skip.apply(this, wrapTestInZone(arguments));
|
---|
120 | };
|
---|
121 | global.it.only = global.test.only = Mocha.it.only = function () {
|
---|
122 | return mochaOriginal.it.only.apply(this, wrapTestInZone(arguments));
|
---|
123 | };
|
---|
124 | global.after = global.suiteTeardown = Mocha.after = function () {
|
---|
125 | return mochaOriginal.after.apply(this, wrapSuiteInZone(arguments));
|
---|
126 | };
|
---|
127 | global.afterEach = global.teardown = Mocha.afterEach = function () {
|
---|
128 | return mochaOriginal.afterEach.apply(this, wrapTestInZone(arguments));
|
---|
129 | };
|
---|
130 | global.before = global.suiteSetup = Mocha.before = function () {
|
---|
131 | return mochaOriginal.before.apply(this, wrapSuiteInZone(arguments));
|
---|
132 | };
|
---|
133 | global.beforeEach = global.setup = Mocha.beforeEach = function () {
|
---|
134 | return mochaOriginal.beforeEach.apply(this, wrapTestInZone(arguments));
|
---|
135 | };
|
---|
136 | (function (originalRunTest, originalRun) {
|
---|
137 | Mocha.Runner.prototype.runTest = function (fn) {
|
---|
138 | var _this = this;
|
---|
139 | Zone.current.scheduleMicroTask('mocha.forceTask', function () {
|
---|
140 | originalRunTest.call(_this, fn);
|
---|
141 | });
|
---|
142 | };
|
---|
143 | Mocha.Runner.prototype.run = function (fn) {
|
---|
144 | this.on('test', function (e) {
|
---|
145 | testZone = rootZone.fork(new ProxyZoneSpec());
|
---|
146 | });
|
---|
147 | this.on('fail', function (test, err) {
|
---|
148 | var proxyZoneSpec = testZone && testZone.get('ProxyZoneSpec');
|
---|
149 | if (proxyZoneSpec && err) {
|
---|
150 | try {
|
---|
151 | // try catch here in case err.message is not writable
|
---|
152 | err.message += proxyZoneSpec.getAndClearPendingTasksInfo();
|
---|
153 | }
|
---|
154 | catch (error) {
|
---|
155 | }
|
---|
156 | }
|
---|
157 | });
|
---|
158 | return originalRun.call(this, fn);
|
---|
159 | };
|
---|
160 | })(Mocha.Runner.prototype.runTest, Mocha.Runner.prototype.run);
|
---|
161 | });
|
---|
162 | })));
|
---|