CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-jetbrains-kotlin--kotlin-test-wasm-js

Kotlin Test library for experimental WebAssembly JS platform - provides test framework adapters and assertions for testing Kotlin/Wasm applications that target JavaScript environments

Pending
Overview
Eval results
Files

framework-integration.mddocs/

Framework Integration

Automatic integration with JavaScript testing frameworks, enabling seamless execution of Kotlin/WASM tests in various JavaScript environments without requiring manual configuration.

Capabilities

Automatic Framework Detection

The library automatically detects and integrates with popular JavaScript testing frameworks, requiring no manual configuration from developers.

Supported Frameworks:

  • Jasmine: Full integration with describe/it test structure and async Promise support
  • Mocha: Compatible with Mocha's testing patterns and reporting
  • Jest: Seamless integration with Jest test runner and assertion reporting
  • TeamCity: Automatic TeamCity service message format for CI/CD environments

Detection Logic:

  1. JavaScript Environment Detection: Checks for presence of describe and it functions in the global scope
  2. Jasmine-style Frameworks: If detected, uses Jasmine-compatible adapter with Promise support
  3. TeamCity Environment: Falls back to TeamCity reporting format for CI environments
  4. Error Handling: Converts Kotlin exceptions to JavaScript Error objects for proper framework reporting

Usage in Different Environments

Jasmine/Mocha/Jest Example:

<!DOCTYPE html>
<html>
<head>
    <title>Kotlin WASM Tests</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.8.0/jasmine.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.8.0/jasmine-html.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.8.0/boot.js"></script>
</head>
<body>
    <script src="your-kotlin-wasm-tests.js"></script>
    <!-- Tests run automatically - no additional setup needed -->
</body>
</html>

Node.js with Mocha:

# Install Mocha
npm install --save-dev mocha

# Run tests - framework detection happens automatically  
npx mocha your-kotlin-wasm-tests.js

TeamCity Integration:

# TeamCity build configuration
# No special setup needed - TeamCity format is detected automatically
script: |
  node your-kotlin-wasm-tests.js
  # Test results appear in TeamCity test tab automatically

Async Test Support

Full support for asynchronous testing with JavaScript Promises, including proper error handling and test completion detection.

Promise-Based Tests:

import kotlin.test.*
import kotlin.js.Promise

class AsyncIntegrationTests {
    @Test
    fun fetchDataTest(): Promise<*> {
        return fetchUserData("user123").then { userData ->
            assertNotNull(userData)
            assertEquals("user123", userData.id)
            assertTrue(userData.isActive)
        }
    }
    
    @Test
    fun errorHandlingTest(): Promise<*> {
        return fetchUserData("invalid-id")
            .then { 
                fail("Should have thrown an error for invalid ID")
            }
            .catch { error ->
                // Error is properly converted and reported by the framework
                assertTrue(error.toString().contains("User not found"))
            }
    }
    
    @Test
    fun chainedAsyncTest(): Promise<*> {
        return createUser("newuser@example.com")
            .then { user -> 
                assertEquals("newuser@example.com", user.email)
                return@then updateUserProfile(user.id, "John Doe")
            }
            .then { updatedUser ->
                assertEquals("John Doe", updatedUser.name)
            }
    }
}

Error Reporting Integration

Seamless error reporting that preserves Kotlin stack traces and exception details in JavaScript testing frameworks.

Error Conversion Features:

  • Stack Trace Preservation: Kotlin stack traces are converted to JavaScript-compatible format
  • Exception Message Preservation: Original Kotlin exception messages are maintained
  • Assertion Failure Details: Clear reporting of expected vs. actual values
  • Framework-Specific Formatting: Error format adapts to the detected testing framework

Example Error Output in Jasmine:

AssertionError: Expected <42> but was <43>
    at assertEquals (kotlin-test.js:123:45)
    at MyTests.calculateTest (my-tests.kt:15:8)
    at Object.it (jasmine-adapter.js:67:12)

Configuration Requirements

Zero Configuration: The library requires no manual setup or configuration files. Framework detection and integration happen automatically when tests are executed.

Environment Requirements:

  • WebAssembly support in the JavaScript runtime
  • One of the supported testing frameworks (Jasmine, Mocha, Jest, or TeamCity environment)
  • Standard JavaScript Promise support for async tests

Best Practices

Framework Compatibility:

  • Use standard @Test, @BeforeTest, @AfterTest annotations - they work across all supported frameworks
  • Return Promise<*> from test functions for async operations
  • Avoid framework-specific APIs in test code to maintain portability

Error Handling:

  • Let exceptions bubble up naturally - the integration layer handles conversion
  • Use kotlin.test assertion functions for consistent error reporting
  • Provide meaningful error messages in assertions for better debugging

Performance:

  • Framework detection happens only once per test run
  • Minimal overhead added to test execution
  • Efficient Promise handling for async test coordination

This automatic integration ensures that Kotlin/WASM tests run seamlessly in any JavaScript testing environment without requiring developers to learn framework-specific APIs or configuration details.

Install with Tessl CLI

npx tessl i tessl/maven-org-jetbrains-kotlin--kotlin-test-wasm-js

docs

annotations.md

asserter-system.md

assertions.md

framework-integration.md

index.md

tile.json