Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/third_party/closure/goog/promise/testsuiteadapter.js
2868 views
1
// Copyright 2013 The Closure Library Authors. All Rights Reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS-IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
/**
16
* @fileoverview Test adapter for testing Closure Promises against the
17
* Promises/A+ Compliance Test Suite, which is implemented as a Node.js module.
18
*
19
* This test suite adapter may not be run in Node.js directly, but must first be
20
* compiled with the Closure Compiler to pull in the required dependencies.
21
*
22
* @see https://npmjs.org/package/promises-aplus-tests
23
*/
24
25
goog.provide('goog.promise.testSuiteAdapter');
26
27
goog.require('goog.Promise');
28
29
goog.setTestOnly('goog.promise.testSuiteAdapter');
30
31
32
var promisesAplusTests = /** @type {function(!Object, function(*))} */ (
33
require('promises_aplus_tests'));
34
35
36
/**
37
* Adapter for specifying Promise-creating functions to the Promises test suite.
38
* @const
39
*/
40
goog.promise.testSuiteAdapter = {
41
/** @type {function(*): !goog.Promise} */
42
'resolved': goog.Promise.resolve,
43
44
/** @type {function(*): !goog.Promise} */
45
'rejected': goog.Promise.reject,
46
47
/** @return {!Object} */
48
'deferred': function() {
49
var promiseObj = {};
50
promiseObj['promise'] = new goog.Promise(function(resolve, reject) {
51
promiseObj['resolve'] = resolve;
52
promiseObj['reject'] = reject;
53
});
54
return promiseObj;
55
}
56
};
57
58
59
// Node.js defines setTimeout globally, but Closure relies on finding it
60
// defined on goog.global.
61
goog.exportSymbol('setTimeout', setTimeout);
62
63
64
// Rethrowing an error to the global scope kills Node immediately. Suppress
65
// error rethrowing for running this test suite.
66
goog.Promise.setUnhandledRejectionHandler(goog.nullFunction);
67
68
69
// Run the tests, exiting with a failure code if any of the tests fail.
70
promisesAplusTests(goog.promise.testSuiteAdapter, function(err) {
71
if (err) {
72
process.exit(1);
73
}
74
});
75
76