| <!doctype html> |
| <html> |
| <head> |
| <script src="../../http/tests/inspector/resources/protocol-test.js"></script> |
| <script> |
| function test() |
| { |
| ProtocolTest.suppressStackTraces = true; |
| |
| try { |
| let result = new AsyncTestSuite(this); |
| ProtocolTest.fail("instantiating AsyncTestSuite requires name argument."); |
| } catch (e) { |
| ProtocolTest.pass("instantiating AsyncTestSuite requires name argument."); |
| } |
| |
| try { |
| let result = new AsyncTestSuite(this, {}); |
| ProtocolTest.fail("instantiating AsyncTestSuite requires string name argument."); |
| } catch (e) { |
| ProtocolTest.pass("instantiating AsyncTestSuite requires string name argument."); |
| } |
| |
| try { |
| let result = new AsyncTestSuite(this, " "); |
| ProtocolTest.fail("instantiating AsyncTestSuite requires non-whitespace name argument."); |
| } catch (e) { |
| ProtocolTest.pass("instantiating AsyncTestSuite requires non-whitespace name argument."); |
| } |
| |
| try { |
| let result = new AsyncTestSuite("something", {}); |
| ProtocolTest.fail("instantiating AsyncTestSuite requires test harness argument."); |
| } catch (e) { |
| ProtocolTest.pass("instantiating AsyncTestSuite requires test harness argument."); |
| } |
| |
| let badArgsSuite = ProtocolTest.createAsyncSuite("dummy"); |
| try { |
| badArgsSuite.addTestCase(); |
| ProtocolTest.fail("should not be able to add empty test case."); |
| } catch (e) { |
| ProtocolTest.pass("should not be able to add empty test case."); |
| } |
| try { |
| badArgsSuite.addTestCase("string"); |
| ProtocolTest.fail("should not be able to add non-object test case."); |
| } catch (e) { |
| ProtocolTest.pass("should not be able to add non-object test case."); |
| } |
| try { |
| badArgsSuite.addTestCase({ |
| name: {}, |
| test() {}, |
| }); |
| ProtocolTest.fail("test case should require string name."); |
| } catch (e) { |
| ProtocolTest.pass("test case should require string name."); |
| } |
| try { |
| badArgsSuite.addTestCase({ |
| name: " ", |
| test() {}, |
| }); |
| ProtocolTest.fail("test case should require non-whitespace name."); |
| } catch (e) { |
| ProtocolTest.pass("test case should require non-whitespace name."); |
| } |
| try { |
| badArgsSuite.addTestCase({ |
| name: "foo", |
| test: null, |
| }); |
| ProtocolTest.fail("test case should require test function."); |
| } catch (e) { |
| ProtocolTest.pass("test case should require test function."); |
| } |
| try { |
| badArgsSuite.addTestCase({ |
| name: "foo", |
| test() {}, |
| setup: "astd" |
| }); |
| ProtocolTest.fail("should not be able to specify non-Function `setup` parameter."); |
| } catch (e) { |
| ProtocolTest.pass("should not be able to specify non-Function `setup` parameter."); |
| } |
| try { |
| badArgsSuite.addTestCase({ |
| name: "foo", |
| test() {}, |
| setup: 123 |
| }); |
| ProtocolTest.fail("should not be able to specify non-Function `setup` parameter."); |
| } catch (e) { |
| ProtocolTest.pass("should not be able to specify non-Function `setup` parameter."); |
| } |
| try { |
| badArgsSuite.addTestCase({ |
| name: "foo", |
| test() {}, |
| setup: {} |
| }); |
| ProtocolTest.fail("should not be able to specify non-Function `setup` parameter."); |
| } catch (e) { |
| ProtocolTest.pass("should not be able to specify non-Function `setup` parameter."); |
| } |
| try { |
| badArgsSuite.addTestCase({ |
| name: "foo", |
| test() {}, |
| teardown: "astd" |
| }); |
| ProtocolTest.fail("should not be able to specify non-Function `teardown` parameter."); |
| } catch (e) { |
| ProtocolTest.pass("should not be able to specify non-Function `teardown` parameter."); |
| } |
| try { |
| badArgsSuite.addTestCase({ |
| name: "foo", |
| test() {}, |
| teardown: 123 |
| }); |
| ProtocolTest.fail("should not be able to specify non-Function `teardown` parameter."); |
| } catch (e) { |
| ProtocolTest.pass("should not be able to specify non-Function `teardown` parameter."); |
| } |
| try { |
| badArgsSuite.addTestCase({ |
| name: "foo", |
| test() {}, |
| teardown: {} |
| }); |
| ProtocolTest.fail("should not be able to specify non-Function `teardown` parameter."); |
| } catch (e) { |
| ProtocolTest.pass("should not be able to specify non-Function `teardown` parameter."); |
| } |
| |
| let runEmptySuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.RunEmptySuite"); |
| try { |
| runEmptySuite.runTestCases(); |
| ProtocolTest.fail("should not be able to run empty test suite."); |
| } catch (e) { |
| ProtocolTest.pass("should not be able to run empty test suite."); |
| } |
| |
| let runTwiceSuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.RunTwiceSuite"); |
| runTwiceSuite.addTestCase({ |
| name: "DummyTest0", |
| description: "Check that a suite can't run more than once.", |
| test(resolve, reject) { resolve(); } |
| }); |
| |
| let result = runTwiceSuite.runTestCases(); |
| try { |
| // Test cases won't run in this event loop; this call should still throw. |
| // Later tests are chained to this suite to avoid nondeterminism. |
| runTwiceSuite.runTestCases(); |
| ProtocolTest.fail("should not be able to run a test suite twice."); |
| } catch (e) { |
| ProtocolTest.pass("should not be able to run a test suite twice."); |
| } |
| |
| let rejectToken = {"token": 666}; |
| let thrownError = new Error(rejectToken); |
| |
| let sequentialExecutionSuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.SequentialExecution"); |
| sequentialExecutionSuite.addTestCase({ |
| name: "DummyTest1", |
| description: "Check test case execution order.", |
| test(resolve, reject) { resolve(); } |
| }); |
| sequentialExecutionSuite.addTestCase({ |
| name: "DummyTest2", |
| description: "Check test case execution order.", |
| test(resolve, reject) { resolve(); } |
| }); |
| sequentialExecutionSuite.addTestCase({ |
| name: "DummyTest3", |
| description: "Check test case execution order.", |
| test(resolve, reject) { resolve(); } |
| }); |
| sequentialExecutionSuite.addTestCase({ |
| name: "FailingTest4", |
| description: "Check that test fails by throwing an Error instance.", |
| test(resolve, reject) { throw thrownError; } |
| }); |
| |
| let abortOnFailureSuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.AbortOnFailure"); |
| abortOnFailureSuite.addTestCase({ |
| name: "PassingTest5", |
| description: "This test is a dummy.", |
| test(resolve, reject) { resolve(); } |
| }); |
| abortOnFailureSuite.addTestCase({ |
| name: "FailingTest6", |
| description: "This test should fail by explicitly calling the `reject` callback.", |
| test(resolve, reject) { reject(rejectToken); } |
| }); |
| abortOnFailureSuite.addTestCase({ |
| name: "PassingTest7", |
| description: "This test should not executed when the preceding test fails.", |
| test(resolve, reject) { resolve(); } |
| }); |
| |
| result = result.then(() => { |
| let promise = sequentialExecutionSuite.runTestCases(); |
| ProtocolTest.expectThat(result instanceof Promise, "AsyncTestSuite.RunTestCases() should return a Promise."); |
| return promise; |
| }); |
| result = result.then(function resolved() { |
| ProtocolTest.fail("Promise from sequentialExecutionSuite.runTestCases() should reject when a test case fails."); |
| return Promise.resolve(); // Continue this test. |
| }, function rejected(e) { |
| ProtocolTest.pass("Promise from sequentialExecutionSuite.runTestCases() should reject when a test case fails."); |
| ProtocolTest.expectThat(e === thrownError, "Promise from sequentialExecutionSuite.runTestCases() should reject without altering its result value."); |
| |
| ProtocolTest.expectThat(sequentialExecutionSuite.runCount === 4, "sequentialExecutionSuite should have executed four tests."); |
| ProtocolTest.expectThat(sequentialExecutionSuite.passCount === 3, "sequentialExecutionSuite should have passed three tests."); |
| ProtocolTest.expectThat(sequentialExecutionSuite.failCount === 1, "sequentialExecutionSuite should have failed 1 test."); |
| ProtocolTest.expectThat(sequentialExecutionSuite.skipCount === 0, "sequentialExecutionSuite should have skipped zero tests."); |
| return Promise.resolve(); // Continue this test. |
| }); |
| |
| result = result.then(() => { |
| return abortOnFailureSuite.runTestCases(); |
| }).then(function resolved() { |
| ProtocolTest.fail("Promise from abortOnFailureSuite.runTestCases() should reject when a test case fails."); |
| return Promise.resolve(); // Continue this test. |
| }, function rejected(e) { |
| ProtocolTest.pass("Promise from abortOnFailureSuite.runTestCases() should reject when a test case fails."); |
| ProtocolTest.expectThat(e === rejectToken, "Promise from abortOnFailureSuite.runTestCases() should reject without altering its result value."); |
| ProtocolTest.expectThat(abortOnFailureSuite.runCount === 2, "abortOnFailureSuite should have executed two tests."); |
| ProtocolTest.expectThat(abortOnFailureSuite.passCount === 1, "abortOnFailureSuite should have passed one test."); |
| ProtocolTest.expectThat(abortOnFailureSuite.failCount === 1, "abortOnFailureSuite should have failed one test."); |
| ProtocolTest.expectThat(abortOnFailureSuite.skipCount === 1, "abortOnFailureSuite should have skipped one test."); |
| |
| return Promise.resolve(); // Continue this test. |
| }); |
| |
| var setupAndTeardownSymbol = Symbol("async-suite-setup-and-teardown-token"); |
| window[setupAndTeardownSymbol] = 0; |
| |
| let setupAndTeardownTestSuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.SetupAndTeardown"); |
| setupAndTeardownTestSuite.addTestCase({ |
| name: "TestWithSetupAndTeardown", |
| description: "Check execution order for setup and teardown actions.", |
| setup: (resolve, reject) => { |
| window[setupAndTeardownSymbol] = 1; |
| resolve(); |
| }, |
| test(resolve, reject) { |
| ProtocolTest.expectThat(window[setupAndTeardownSymbol] === 1, "Test should see side effects of running setup() action."); |
| window[setupAndTeardownSymbol] = 2; |
| resolve(); |
| }, |
| teardown: (resolve, reject) => { |
| ProtocolTest.expectThat(window[setupAndTeardownSymbol] === 2, "Teardown should see side effects of running setup() action."); |
| window[setupAndTeardownSymbol] = 3; |
| resolve(); |
| } |
| }); |
| setupAndTeardownTestSuite.addTestCase({ |
| name: "TestRunningAfterTeardown", |
| description: "Check execution order for test after a teardown action.", |
| test(resolve, reject) { |
| ProtocolTest.expectThat(window[setupAndTeardownSymbol] === 3, "Test should see side effects of previous test's teardown() action."); |
| resolve(); |
| }, |
| }); |
| |
| result = result.then(() => { |
| return setupAndTeardownTestSuite.runTestCases(); |
| }).then(function resolved() { |
| ProtocolTest.pass("Promise from setupAndTeardownTestSuite.runTestCases() should resolve."); |
| return Promise.resolve(); // Continue this test. |
| }, function rejected(e) { |
| ProtocolTest.fail("Promise from setupAndTeardownTestSuite.runTestCases() should resolve."); |
| return Promise.resolve(); // Continue this test. |
| }); |
| |
| let setupExceptionTestSuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.SetupException"); |
| setupExceptionTestSuite.addTestCase({ |
| name: "TestWithExceptionDuringSetup", |
| description: "Check execution order for setup action that throws an exception.", |
| setup: (resolve, reject) => { throw new Error() }, |
| test(resolve, reject) { |
| ProtocolTest.assert(false, "Test should not execute if its setup action threw an exception."); |
| reject(); |
| }, |
| teardown: (resolve, reject) => { |
| ProtocolTest.assert(false, "Teardown action should not execute if its setup action threw an exception."); |
| reject(); |
| } |
| }); |
| |
| result = result.then(() => { |
| return setupExceptionTestSuite.runTestCases(); |
| }).then(function resolved() { |
| ProtocolTest.fail("Promise from setupExceptionTestSuite.runTestCases() should reject."); |
| return Promise.resolve(); // Continue this test. |
| }, function rejected(e) { |
| ProtocolTest.pass("Promise from setupExceptionTestSuite.runTestCases() should reject."); |
| return Promise.resolve(); // Continue this test. |
| }); |
| |
| let setupFailureTestSuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.SetupFailure"); |
| setupFailureTestSuite.addTestCase({ |
| name: "TestWithFailureDuringSetup", |
| description: "Check execution order for setup action that has failed.", |
| setup: (resolve, reject) => { reject(); }, |
| test(resolve, reject) { |
| ProtocolTest.assert(false, "Test should not execute if its setup action failed.") |
| reject(); |
| }, |
| teardown: (resolve, reject) => { |
| ProtocolTest.assert(false, "Teardown action should not execute if its setup action failed.") |
| reject(); |
| } |
| }); |
| |
| result = result.then(() => { |
| return setupFailureTestSuite.runTestCases(); |
| }).then(function resolved() { |
| ProtocolTest.fail("Promise from setupFailureTestSuite.runTestCases() should reject."); |
| return Promise.resolve(); // Continue this test. |
| }, function rejected(e) { |
| ProtocolTest.pass("Promise from setupFailureTestSuite.runTestCases() should reject."); |
| return Promise.resolve(); // Continue this test. |
| }); |
| |
| let teardownExceptionTestSuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.TeardownException"); |
| teardownExceptionTestSuite.addTestCase({ |
| name: "TestWithExceptionDuringTeardown", |
| description: "Check execution order for teardown action that throws an exception.", |
| test(resolve, reject) { resolve(); }, |
| teardown: (resolve, reject) => { throw new Error() } |
| }); |
| teardownExceptionTestSuite.addTestCase({ |
| name: "TestAfterTeardownException", |
| descrption: "Check execution order for test after previous test's teardown throws an exception.", |
| setup: (resolve, reject) => { |
| ProtocolTest.assert(false, "Setup action should not execute if previous test's teardown action threw an exception."); |
| reject(); |
| }, |
| test(resolve, reject) { |
| ProtocolTest.assert(false, "Test should not execute if previous test's teardown action threw an exception."); |
| reject(); |
| } |
| }); |
| |
| result = result.then(() => { |
| return teardownExceptionTestSuite.runTestCases(); |
| }).then(function resolved() { |
| ProtocolTest.fail("Promise from teardownExceptionTestSuite.runTestCases() should reject."); |
| return Promise.resolve(); // Continue this test. |
| }, function rejected(e) { |
| ProtocolTest.pass("Promise from teardownExceptionTestSuite.runTestCases() should reject."); |
| return Promise.resolve(); // Continue this test. |
| }); |
| |
| let teardownFailureTestSuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.TeardownFailure"); |
| teardownFailureTestSuite.addTestCase({ |
| name: "TestWithExceptionDuringTeardown", |
| description: "Check execution order for teardown action that has failed.", |
| test(resolve, reject) { resolve(); }, |
| teardown: (resolve, reject) => { reject(); }, |
| }); |
| teardownFailureTestSuite.addTestCase({ |
| name: "TestAfterTeardownException", |
| description: "Check execution order for test after previous test's teardown throws an exception", |
| setup: (resolve, reject) => { |
| ProtocolTest.assert(false, "Setup action should not execute if previous test's teardown action failed."); |
| reject(); |
| }, |
| test(resolve, reject) { |
| ProtocolTest.assert(false, "Test should not execute if previous test's teardown action failed."); |
| reject(); |
| } |
| }); |
| |
| result = result.then(() => { |
| return teardownFailureTestSuite.runTestCases(); |
| }).then(function resolved() { |
| ProtocolTest.fail("Promise from teardownFailureTestSuite.runTestCases() should reject."); |
| return Promise.resolve(); // Continue this test. |
| }, function rejected(e) { |
| ProtocolTest.pass("Promise from teardownFailureTestSuite.runTestCases() should reject."); |
| return Promise.resolve(); // Continue this test. |
| }); |
| |
| // Async test functions. |
| let asyncFunctionSuccessTestSuiteDidEvaluate = false; |
| let asyncFunctionSuccessTestSuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.AsyncFunctionSuccess"); |
| asyncFunctionSuccessTestSuite.addTestCase({ |
| name: "AsyncFunctionSuccess", |
| description: "Check that an async suite with async test functions can succeed", |
| async test() { |
| asyncFunctionSuccessTestSuiteDidEvaluate = true; |
| return 42; |
| } |
| }); |
| |
| result = result.then(() => { |
| return asyncFunctionSuccessTestSuite.runTestCases(); |
| }).then(function resolve(x) { |
| ProtocolTest.pass("Promise from asyncFunctionSuccessTestSuite.runTestCases() should succeed."); |
| ProtocolTest.expectThat(asyncFunctionSuccessTestSuiteDidEvaluate, "Promise did evaluate the async test function."); |
| ProtocolTest.expectEqual(x, 42, "Resolved value should be 42."); |
| return Promise.resolve(); // Continue this test. |
| }, function rejected(e) { |
| ProtocolTest.fail("Promise from asyncFunctionSuccessTestSuite.runTestCases() should succeed."); |
| return Promise.resolve(); // Continue this test. |
| }); |
| |
| let asyncFunctionExplicitFailureTestSuiteDidEvaluate = false; |
| let asyncFunctionExplicitFailureTestSuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.AsyncFunctionExplicitFailure"); |
| asyncFunctionExplicitFailureTestSuite.addTestCase({ |
| name: "AsyncFunctionFailure", |
| description: "Check that an async suite with async test functions that throws will reject", |
| async test() { |
| asyncFunctionExplicitFailureTestSuiteDidEvaluate = true; |
| throw "AsyncFunctionFailure Exception Message"; |
| } |
| }); |
| |
| result = result.then(() => { |
| return asyncFunctionExplicitFailureTestSuite.runTestCases(); |
| }).then(function resolve() { |
| ProtocolTest.fail("Promise from asyncFunctionExplicitFailureTestSuite.runTestCases() should reject."); |
| return Promise.resolve(); // Continue this test. |
| }, function rejected(e) { |
| ProtocolTest.pass("Promise from asyncFunctionExplicitFailureTestSuite.runTestCases() should reject."); |
| ProtocolTest.expectThat(asyncFunctionExplicitFailureTestSuiteDidEvaluate, "Promise did evaluate the async test function."); |
| ProtocolTest.expectEqual(e, "AsyncFunctionFailure Exception Message", "Rejected value should be thrown exception."); |
| return Promise.resolve(); // Continue this test. |
| }); |
| |
| let asyncFunctionRuntimeFailureTestSuiteDidEvaluate = false; |
| let asyncFunctionRuntimeFailureTestSuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.AsyncFunctionRuntimeFailure"); |
| asyncFunctionRuntimeFailureTestSuite.addTestCase({ |
| name: "AsyncFunctionFailure", |
| description: "Check that an async suite with async test functions that throws with a runtime error will reject", |
| async test() { |
| asyncFunctionRuntimeFailureTestSuiteDidEvaluate = true; |
| ({}).x.x.x; |
| } |
| }); |
| |
| result = result.then(() => { |
| return asyncFunctionRuntimeFailureTestSuite.runTestCases(); |
| }).then(function resolve() { |
| ProtocolTest.fail("Promise from asyncFunctionRuntimeFailureTestSuite.runTestCases() should reject."); |
| return Promise.resolve(); // Continue this test. |
| }, function rejected(e) { |
| ProtocolTest.pass("Promise from asyncFunctionRuntimeFailureTestSuite.runTestCases() should reject."); |
| ProtocolTest.expectThat(asyncFunctionRuntimeFailureTestSuiteDidEvaluate, "Promise did evaluate the async test function."); |
| ProtocolTest.expectThat(e instanceof TypeError, "Rejected value should be a runtime exception."); |
| return Promise.resolve(); // Continue this test. |
| }); |
| |
| // Async setup() and teardown() success test cases. |
| const asyncSetupAndTeardownSymbol = Symbol("async-suite-async-setup-and-teardown-token"); |
| window[asyncSetupAndTeardownSymbol] = 0; |
| |
| let asyncSetupAndAsyncTeardownTestSuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.AsyncSetupAndAsyncTeardown"); |
| asyncSetupAndAsyncTeardownTestSuite.addTestCase({ |
| name: "TestWithSetupAndTeardown", |
| description: "Check execution order for setup and teardown actions.", |
| async setup() { |
| window[asyncSetupAndTeardownSymbol] = 1; |
| }, |
| async test() { |
| ProtocolTest.expectThat(window[asyncSetupAndTeardownSymbol] === 1, "Test should see side effects of running setup() action."); |
| window[asyncSetupAndTeardownSymbol] = 2; |
| }, |
| async teardown() { |
| ProtocolTest.expectThat(window[asyncSetupAndTeardownSymbol] === 2, "Teardown should see side effects of running setup() action."); |
| window[asyncSetupAndTeardownSymbol] = 3; |
| } |
| }); |
| asyncSetupAndAsyncTeardownTestSuite.addTestCase({ |
| name: "TestRunningAfterTeardown", |
| description: "Check execution order for test after a teardown action.", |
| test(resolve, reject) { |
| ProtocolTest.expectThat(window[asyncSetupAndTeardownSymbol] === 3, "Test should see side effects of previous test's teardown() action."); |
| resolve(); |
| }, |
| }); |
| |
| result = result.then(() => { |
| return asyncSetupAndAsyncTeardownTestSuite.runTestCases(); |
| }).then(function resolved() { |
| ProtocolTest.pass("Promise from asyncSetupAndAsyncTeardownTestSuite.runTestCases() should resolve."); |
| return Promise.resolve(); // Continue this test. |
| }, function rejected(e) { |
| ProtocolTest.fail("Promise from asyncSetupAndAsyncTeardownTestSuite.runTestCases() should resolve."); |
| return Promise.resolve(); // Continue this test. |
| }); |
| |
| // Async setup() failure test cases. |
| let asyncSetupExplicitFailureTestSuiteDidEvaluate = false; |
| let asyncSetupExplicitFailureTestSuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.AsyncSetupExplicitFailure"); |
| asyncSetupExplicitFailureTestSuite.addTestCase({ |
| name: "AsyncFunctionFailure", |
| description: "Check that an async suite with async test functions that throws will reject", |
| async test() { |
| asyncSetupExplicitFailureTestSuiteDidEvaluate = true; |
| throw "AsyncFunctionFailure Exception Message"; |
| } |
| }); |
| |
| result = result.then(() => { |
| return asyncSetupExplicitFailureTestSuite.runTestCases(); |
| }).then(function resolve() { |
| ProtocolTest.fail("Promise from asyncSetupExplicitFailureTestSuite.runTestCases() should reject."); |
| return Promise.resolve(); // Continue this test. |
| }, function rejected(e) { |
| ProtocolTest.pass("Promise from asyncSetupExplicitFailureTestSuite.runTestCases() should reject."); |
| ProtocolTest.expectThat(asyncSetupExplicitFailureTestSuiteDidEvaluate, "Promise did evaluate the async setup function."); |
| ProtocolTest.expectEqual(e, "AsyncFunctionFailure Exception Message", "Rejected value should be thrown exception."); |
| return Promise.resolve(); // Continue this test. |
| }); |
| |
| let asyncSetupRuntimeFailureTestSuiteDidEvaluate = false; |
| let asyncSetupRuntimeFailureTestSuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.AsyncSetupRuntimeFailure"); |
| asyncSetupRuntimeFailureTestSuite.addTestCase({ |
| name: "AsyncFunctionFailure", |
| description: "Check that an async suite with an async setup function that throws with a runtime error will reject", |
| async setup() { |
| asyncSetupRuntimeFailureTestSuiteDidEvaluate = true; |
| ({}).x.x.x; |
| }, |
| async test() { return true; }, |
| }); |
| |
| result = result.then(() => { |
| return asyncSetupRuntimeFailureTestSuite.runTestCases(); |
| }).then(function resolve() { |
| ProtocolTest.fail("Promise from asyncSetupRuntimeFailureTestSuite.runTestCases() should reject."); |
| return Promise.resolve(); // Continue this test. |
| }, function rejected(e) { |
| ProtocolTest.pass("Promise from asyncSetupRuntimeFailureTestSuite.runTestCases() should reject."); |
| ProtocolTest.expectThat(asyncSetupRuntimeFailureTestSuiteDidEvaluate, "Promise did evaluate the async setup function."); |
| ProtocolTest.expectThat(e instanceof TypeError, "Rejected value should be a runtime exception."); |
| return Promise.resolve(); // Continue this test. |
| }); |
| |
| // Async teardown() failure test cases. |
| let asyncTeardownExplicitFailureTestSuiteDidEvaluate = false; |
| let asyncTeardownExplicitFailureTestSuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.AsyncTeardownExplicitFailure"); |
| asyncTeardownExplicitFailureTestSuite.addTestCase({ |
| name: "AsyncFunctionFailure", |
| description: "Check that an async suite with async test functions that throws will reject", |
| async test() { return true; }, |
| async teardown() { |
| asyncTeardownExplicitFailureTestSuiteDidEvaluate = true; |
| throw "AsyncFunctionFailure Exception Message"; |
| }, |
| }); |
| |
| result = result.then(() => { |
| return asyncTeardownExplicitFailureTestSuite.runTestCases(); |
| }).then(function resolve() { |
| ProtocolTest.fail("Promise from asyncTeardownExplicitFailureTestSuite.runTestCases() should reject."); |
| return Promise.resolve(); // Continue this test. |
| }, function rejected(e) { |
| ProtocolTest.pass("Promise from asyncTeardownExplicitFailureTestSuite.runTestCases() should reject."); |
| ProtocolTest.expectThat(asyncTeardownExplicitFailureTestSuiteDidEvaluate, "Promise did evaluate the async teardown function."); |
| ProtocolTest.expectEqual(e, "AsyncFunctionFailure Exception Message", "Rejected value should be thrown exception."); |
| return Promise.resolve(); // Continue this test. |
| }); |
| |
| let asyncTeardownRuntimeFailureTestSuiteDidEvaluate = false; |
| let asyncTeardownRuntimeFailureTestSuite = ProtocolTest.createAsyncSuite("AsyncTestSuite.AsyncTeardownRuntimeFailure"); |
| asyncTeardownRuntimeFailureTestSuite.addTestCase({ |
| name: "AsyncFunctionFailure", |
| description: "Check that an async suite with an async teardown function that throws with a runtime error will reject", |
| async test() { return true; }, |
| async teardown() { |
| asyncTeardownRuntimeFailureTestSuiteDidEvaluate = true; |
| ({}).x.x.x; |
| }, |
| }); |
| |
| result = result.then(() => { |
| return asyncTeardownRuntimeFailureTestSuite.runTestCases(); |
| }).then(function resolve() { |
| ProtocolTest.fail("Promise from asyncTeardownRuntimeFailureTestSuite.runTestCases() should reject."); |
| return Promise.resolve(); // Continue this test. |
| }, function rejected(e) { |
| ProtocolTest.pass("Promise from asyncTeardownRuntimeFailureTestSuite.runTestCases() should reject."); |
| ProtocolTest.expectThat(asyncTeardownRuntimeFailureTestSuiteDidEvaluate, "Promise did evaluate the async teardown function."); |
| ProtocolTest.expectThat(e instanceof TypeError, "Rejected value should be a runtime exception."); |
| return Promise.resolve(); // Continue this test. |
| }); |
| |
| // This will finish the test whether the chain was resolved or rejected. |
| result = result.then(() => { ProtocolTest.completeTest(); }); |
| } |
| </script> |
| </head> |
| <body onLoad="runTest()"> |
| </body> |
| </html> |