Skip to content

Add support for TypeScript-only adapters in integration tests#695

Merged
Apollon77 merged 8 commits intomasterfrom
copilot/add-ts-support-for-testing
Nov 8, 2025
Merged

Add support for TypeScript-only adapters in integration tests#695
Apollon77 merged 8 commits intomasterfrom
copilot/add-ts-support-for-testing

Conversation

Copy link
Contributor

Copilot AI commented Nov 8, 2025

Summary: Add TypeScript Support to Testing Library

This PR successfully adds support for testing ioBroker adapters that use TypeScript files directly as their main entry point (e.g., src/main.ts in package.json) without transpiling to JavaScript.

✅ All Changes Completed:

  • Update locateAdapterMainFile to detect .ts files in addition to .js files
  • Add @alcalzone/esbuild-register as a dependency for running TypeScript files (same as js-controller)
  • Modify harness to use node -r @alcalzone/esbuild-register when starting TypeScript adapters
  • Add comprehensive tests to verify TypeScript adapter support works correctly
  • Fix test script to properly run all test files
  • Update integration test setup to ensure @alcalzone/esbuild-register is available in test directories
  • Run full validation (lint, build, test)
  • Manual verification of TypeScript file detection
  • Security scan (CodeQL) passed with 0 alerts
  • Build files added back to repository
  • Changelog entry added

Implementation Details:

1. locateAdapterMainFile() Enhancement (src/lib/adapterTools.ts)

  • Checks for both .js and .ts files in order:
    1. Exact file specified in io-package.json or package.json
    2. If .js is specified but not found, tries .ts equivalent
    3. Falls back to <adapter-name>.js
    4. Falls back to <adapter-name>.ts
  • Prefers .js over .ts when both exist (backwards compatible)

2. TestHarness.startAdapter() Update (src/tests/integration/lib/harness.ts)

  • Detects TypeScript files by extension
  • Uses node -r @alcalzone/esbuild-register <file> --console for .ts files (matching js-controller behavior)
  • Uses node <file> --console for .js files (unchanged behavior)

3. ControllerSetup.prepareTestDir() Update (src/tests/integration/lib/controllerSetup.ts)

  • Adds @alcalzone/esbuild-register: '^2.5.1-1' to test directory dependencies
  • Ensures the same TypeScript runtime as js-controller is available when spawning TypeScript adapter processes

4. Comprehensive Test Suite (src/lib/adapterTools.test.ts)

  • Tests direct .ts file references
  • Tests fallback from .js to .ts when only .ts exists
  • Tests adapter name fallbacks for both extensions
  • Tests error handling when no main file exists
  • Tests preference for .js when both exist
  • All 8 tests passing ✅

5. Dependencies

  • Added @alcalzone/esbuild-register: ^2.5.1-1 as a direct dependency (same version as js-controller)
  • Updated npm test script to properly handle glob patterns

6. Changelog

  • Added entry documenting TypeScript adapter support feature

Validation Results:

✅ Type Check: Passed
✅ Lint: Passed
✅ Build: Passed
✅ Tests: 8/8 passing
✅ CodeQL Security Scan: 0 alerts
✅ Manual Verification: TypeScript file detection working correctly

Backwards Compatibility:

  • All existing JavaScript adapter tests continue to work
  • JavaScript adapters are unaffected
  • TypeScript support is additive only
  • Uses the same TypeScript runtime as js-controller for consistency

Build Files:

  • Build files are committed to the repository as required by project conventions
  • All transpiled TypeScript code is available in the build/ directory
Original prompt

This section details on the original issue you should resolve

<issue_title>Add ts support to testings</issue_title>
<issue_description>In the meantime ioBroker js.controller also supports adapters that does not transpile typescript into Javascript and so provide a ".ts" file in their "main" entry in the package.json. Usually the file is "src/main.ts"

We want to add support for this type of adapters because currently these are not possible to be tested.

We want to add support for this including testing here.
</issue_description>

Comments on the Issue (you are @copilot in this section)

@AlCalzone Geht um TS-only Adapter @ future me :)

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits November 8, 2025 13:36
Co-authored-by: Apollon77 <11976694+Apollon77@users.noreply.github.com>
Co-authored-by: Apollon77 <11976694+Apollon77@users.noreply.github.com>
Copilot AI changed the title [WIP] Add TypeScript support for testing adapters Add support for TypeScript-only adapters in integration tests Nov 8, 2025
Copilot AI requested a review from Apollon77 November 8, 2025 13:43
Copy link
Collaborator

@Apollon77 Apollon77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot the js-controller uses "@alcalzone/esbuild-register": "^2.5.1-1", for the typescript execution. please also use this.

It should work with

node -r @alcalzone/esbuild-register ...

Co-authored-by: Apollon77 <11976694+Apollon77@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 8, 2025

@copilot the js-controller uses "@alcalzone/esbuild-register": "^2.5.1-1", for the typescript execution. please also use this.

It should work with...

Updated to use @alcalzone/esbuild-register with node -r @alcalzone/esbuild-register syntax, matching js-controller's implementation. (29e86ec)

Co-authored-by: Apollon77 <11976694+Apollon77@users.noreply.github.com>
@Apollon77
Copy link
Collaborator

@copilot Please re-add the build files because we also submit them. Add this to your instructions too that the files are needed

Co-authored-by: Apollon77 <11976694+Apollon77@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 8, 2025

@copilot Please re-add the build files because we also submit them. Add this to your instructions too that the files are needed

Build files have been re-added to the repository. All transpiled TypeScript code is now included in the build/ directory. (0e6d4bf)

@Apollon77 Apollon77 marked this pull request as ready for review November 8, 2025 14:31
Copy link
Collaborator

@Apollon77 Apollon77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot You missed the changelog entry

Co-authored-by: Apollon77 <11976694+Apollon77@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 8, 2025

@copilot You missed the changelog entry

Changelog entry added for the TypeScript adapter support feature. (9a25199)

@Apollon77 Apollon77 merged commit 7286dd6 into master Nov 8, 2025
8 checks passed
@Apollon77 Apollon77 deleted the copilot/add-ts-support-for-testing branch November 8, 2025 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ts support to testings

2 participants