Path: blob/trunk/third_party/closure/goog/promise/testsuiteadapter.js
2868 views
// Copyright 2013 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview Test adapter for testing Closure Promises against the16* Promises/A+ Compliance Test Suite, which is implemented as a Node.js module.17*18* This test suite adapter may not be run in Node.js directly, but must first be19* compiled with the Closure Compiler to pull in the required dependencies.20*21* @see https://npmjs.org/package/promises-aplus-tests22*/2324goog.provide('goog.promise.testSuiteAdapter');2526goog.require('goog.Promise');2728goog.setTestOnly('goog.promise.testSuiteAdapter');293031var promisesAplusTests = /** @type {function(!Object, function(*))} */ (32require('promises_aplus_tests'));333435/**36* Adapter for specifying Promise-creating functions to the Promises test suite.37* @const38*/39goog.promise.testSuiteAdapter = {40/** @type {function(*): !goog.Promise} */41'resolved': goog.Promise.resolve,4243/** @type {function(*): !goog.Promise} */44'rejected': goog.Promise.reject,4546/** @return {!Object} */47'deferred': function() {48var promiseObj = {};49promiseObj['promise'] = new goog.Promise(function(resolve, reject) {50promiseObj['resolve'] = resolve;51promiseObj['reject'] = reject;52});53return promiseObj;54}55};565758// Node.js defines setTimeout globally, but Closure relies on finding it59// defined on goog.global.60goog.exportSymbol('setTimeout', setTimeout);616263// Rethrowing an error to the global scope kills Node immediately. Suppress64// error rethrowing for running this test suite.65goog.Promise.setUnhandledRejectionHandler(goog.nullFunction);666768// Run the tests, exiting with a failure code if any of the tests fail.69promisesAplusTests(goog.promise.testSuiteAdapter, function(err) {70if (err) {71process.exit(1);72}73});747576