test-utils/js/src/TestBase.kt [34:76]: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - actual constructor(): this(errorCatching = ErrorCatching.Impl()) actual fun println(message: Any?) { kotlin.io.println(message) } actual fun runTest( expected: ((Throwable) -> Boolean)?, unhandled: List<(Throwable) -> Boolean>, block: suspend CoroutineScope.() -> Unit ): TestResult { var exCount = 0 var ex: Throwable? = null /* * This is an additional sanity check against `runTest` mis-usage on JS. * The only way to write an async test on JS is to return Promise from the test function. * _Just_ launching promise and returning `Unit` won't suffice as the underlying test framework * won't be able to detect an asynchronous failure in a timely manner. * We cannot detect such situations, but we can detect the most common erroneous pattern * in our code base, an attempt to use multiple `runTest` in the same `@Test` method, * which typically is a premise to the same error: * ``` * @Test * fun incorrectTestForJs() { // <- promise is not returned * for (parameter in parameters) { * runTest { * runTestForParameter(parameter) * } * } * } * ``` */ if (lastTestPromise != null) { error("Attempt to run multiple asynchronous test within one @Test method") } val result = GlobalScope.promise(block = block, context = CoroutineExceptionHandler { _, e -> if (e is CancellationException) return@CoroutineExceptionHandler // are ignored exCount++ when { exCount > unhandled.size -> error("Too many unhandled exceptions $exCount, expected ${unhandled.size}, got: $e", e) !unhandled[exCount - 1](e) -> error("Unhandled exception was unexpected: $e", e) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - test-utils/wasmJs/src/TestBase.kt [33:75]: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - actual constructor(): this(errorCatching = ErrorCatching.Impl()) actual fun println(message: Any?) { kotlin.io.println(message) } actual fun runTest( expected: ((Throwable) -> Boolean)?, unhandled: List<(Throwable) -> Boolean>, block: suspend CoroutineScope.() -> Unit ): TestResult { var exCount = 0 var ex: Throwable? = null /* * This is an additional sanity check against `runTest` mis-usage on JS. * The only way to write an async test on JS is to return Promise from the test function. * _Just_ launching promise and returning `Unit` won't suffice as the underlying test framework * won't be able to detect an asynchronous failure in a timely manner. * We cannot detect such situations, but we can detect the most common erroneous pattern * in our code base, an attempt to use multiple `runTest` in the same `@Test` method, * which typically is a premise to the same error: * ``` * @Test * fun incorrectTestForJs() { // <- promise is not returned * for (parameter in parameters) { * runTest { * runTestForParameter(parameter) * } * } * } * ``` */ if (lastTestPromise != null) { error("Attempt to run multiple asynchronous test within one @Test method") } val result = GlobalScope.promise(block = block, context = CoroutineExceptionHandler { _, e -> if (e is CancellationException) return@CoroutineExceptionHandler // are ignored exCount++ when { exCount > unhandled.size -> error("Too many unhandled exceptions $exCount, expected ${unhandled.size}, got: $e", e) !unhandled[exCount - 1](e) -> error("Unhandled exception was unexpected: $e", e) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -