Skip to content

Conversation

@sgrekhov
Copy link
Contributor

I also tried to test the case where constructorName contains a . but wasn’t successful. @srujzs, do you know how to import a JS class from a library into the tests? Any advice is appreciated. I tried the approach below, but it doesn’t work (module.js contains definitions for classes A and B).

// OtherResources=module.js
import 'dart:async';
import 'dart:js_interop';
import 'dart:js_interop_unsafe';
import '../../../Utils/expect.dart';
import '../js_utils.dart';

final completer = Completer<String>();

void complete(String value) {
  completer.complete(value);
}

main() async {
  globalContext["complete"] = complete.toJS;
  eval(r'''
    (async () => { 
      const lib1 = await import('./module.js');
      globalThis.objA = new lib1.A(42, "A form JS");
      globalThis.objB = new lib1.B();
    })().then(function(v) {
      globalThis.complete("");
    });
  ''');
  asyncStart();
  completer.future.then((_) {
    Expect.isTrue(globalContext["objA"].instanceOfString("lib1.A"));
    asyncEnd();
  });
}

@srujzs
Copy link

srujzs commented Jul 22, 2025

I'm not quite sure how OtherResources works but in the past I've checked in a JS file and used the /root_test/ prefix to reference other files: https://github.com/dart-lang/sdk/blob/db0c6461570c3e1696ded7095f9a2ab8d181403b/tests/lib/js/static_interop_test/import/import_test.dart#L17.

It's possible that the compiled file isn't in the same directory as the test files so a relative path may not work.

Copy link
Contributor Author

@sgrekhov sgrekhov left a comment

Choose a reason for hiding this comment

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

Updated. Added tests for constructorName with . (using /root_dart/...). Please take another look.

@sgrekhov sgrekhov requested a review from srujzs July 23, 2025 08:21
@sgrekhov
Copy link
Contributor Author

Updated. PTAL.

@sgrekhov sgrekhov requested a review from srujzs July 24, 2025 08:13
@srujzs srujzs merged commit 1fb5e20 into dart-lang:master Jul 24, 2025
2 checks passed
copybara-service bot pushed a commit to dart-lang/sdk that referenced this pull request Jul 28, 2025
2025-07-24 sgrekhov22@gmail.com dart-lang/co19#3180. Add `instanceof` and `instanceOfString` tests (dart-lang/co19#3260)
2025-07-22 sgrekhov22@gmail.com dart-lang/co19#3180. Add more tests for `@anonymous` annotation (dart-lang/co19#3259)
2025-07-22 sgrekhov22@gmail.com dart-lang/co19#3180. Add `@staticInterop` tests. Part 2. (dart-lang/co19#3257)
2025-07-22 sgrekhov22@gmail.com dart-lang/co19#3180. Add tests for `dartify()`. (dart-lang/co19#3258)

Cq-Include-Trybots: luci.dart.try:analyzer-linux-release-try,dart2js-minified-linux-d8-try
Change-Id: Ia8539002298999a01ce8999aeee4368201219ed5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/442180
Reviewed-by: Erik Ernst <eernst@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
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.

2 participants