dart-archive / polymer-dart

Polymer support for Dart
https://pub.dartlang.org/packages/polymer
BSD 3-Clause "New" or "Revised" License
181 stars 33 forks source link

Error while initPolymer when using with test-package #649

Closed flash1293 closed 8 years ago

flash1293 commented 8 years ago

I try to test a polymer-dart-component using the test-package, but I get a strange error when using initPolymer:

  Failed to load "test/my_component_test.dart": receiver is undefined
  my_component_test.dart.browser_test.dart.js 21261:1   J.$index$asx
  my_component_test.dart.browser_test.dart.js 21858:12  <fn>
  my_component_test.dart.browser_test.dart.js 21975:42  init.<fn>.<fn>
  my_component_test.dart.browser_test.dart.js 16370:22  dart<._setUpPropertyChanged
  my_component_test.dart.browser_test.dart.js 16342:15  dart<.initPolymer.<fn>
  my_component_test.dart.browser_test.dart.js 5617:13   dart<._wrapJsFunctionForAsync.<fn>
  my_component_test.dart.browser_test.dart.js 6109:9    dart<._wrapJsFunctionForAsync_closure.call$2<
  my_component_test.dart.browser_test.dart.js 6097:16   dart<._awaitOnObject_closure.call$1<
  my_component_test.dart.browser_test.dart.js 5940:1    dart<._rootRunUnary<
  my_component_test.dart.browser_test.dart.js 8619:16   dart<._CustomZone.runUnary$2<
  my_component_test.dart.browser_test.dart.js 6909:58   dart<._Future__propagateToListeners_handleValueCallback.call$0
  my_component_test.dart.browser_test.dart.js 6816:53   dart<._Future.static._Future__propagateToListeners
//....

I did everything as stated in the tutorial. This is the project: https://github.com/flash1293/polymer_dart_example/tree/darttest

zoechi commented 8 years ago

The test files are missing in the transformers entry point configuration

transformers:
- web_components:
    entry_points:
      - web/foo.html
      - test/my_component_test.html
- reflectable:
    entry_points:
      - web/foo.dart
      - test/my_component_test.dart

Imports that reach out of top-level directories are not supported with pub and prone to cause troubles. If you want to import code into several top-level directories (like web and test) move it into the lib folder (or a subfolder) and import it like

import 'package:polymer_dart_example/my_component.dart';
zoechi commented 8 years ago

The first line in your test should look like

test("my-component should be initialized correctly", () {
  Element heading = new PolymerDom(componentUnderTest.root).querySelector('h1');
  ...
}

to work properly in Polymer 1.0 (when shady DOM is used - default)

Related SO question http://stackoverflow.com/questions/33864930
flash1293 commented 8 years ago

Thanks a lot for your help. I updated my code, but it still doesn't work: Failed to load "test/my_component_test.dart": Unsupported operation: Couldn't find document._registerDartTypeUpgrader. Please make sure that packages/web_components/interop_support.html is loaded and available before calling this function.

I already added <link rel="import" href="packages/web_components/interop_support.html"> to the test.html-file, but it doesn't change anything.

I updated the repo under https://github.com/flash1293/polymer_dart_example/tree/darttest.

zoechi commented 8 years ago

It worked for me. Your error message doesn't look familiar. Can you please provide the full stack-trace? Can you please also try <script src="packages/web_components/webcomponents.min.js"></script> instead of <link rel="import" href="packages/web_components/interop_support.html"> in your my_component_test.html? What Dart version are you using?

flash1293 commented 8 years ago

If I use webcomponents.min.js instead of interop_support.html, it doesn't do anything (the test is never completed).

The complete stacktrace:

Failed to load "test/my_component_test.dart": Unsupported operation: Couldn't find `document._registerDartTypeUpgrader`. Please make sure that `packages/web_components/interop_support.html` is loaded and available before calling this function.
  my_component_test.bootstrap.initialize.dart.browser_test.dart.js 2903:17   dart<.wrapException
  my_component_test.bootstrap.initialize.dart.browser_test.dart.js 22445:1   dart<.registerDartType
  my_component_test.bootstrap.initialize.dart.browser_test.dart.js 22428:9   dart<.CustomElementProxy.initialize$1<
  my_component_test.bootstrap.initialize.dart.browser_test.dart.js 15451:16  dart<.loadInitializers__closure.call$0<
  my_component_test.bootstrap.initialize.dart.browser_test.dart.js 15396:13  dart<._runInitQueue
  my_component_test.bootstrap.initialize.dart.browser_test.dart.js 22489:14  dart<.initWebComponents
  my_component_test.bootstrap.initialize.dart.browser_test.dart.js 16580:37  dart<.initPolymer.<fn>
  my_component_test.bootstrap.initialize.dart.browser_test.dart.js 5660:13   dart<._wrapJsFunctionForAsync.<fn>
  my_component_test.bootstrap.initialize.dart.browser_test.dart.js 6152:9    dart<._wrapJsFunctionForAsync_closure.call$2<
  my_component_test.bootstrap.initialize.dart.browser_test.dart.js 6140:16   dart<._awaitOnObject_closure.call$1<
  my_component_test.bootstrap.initialize.dart.browser_test.dart.js 5983:1    dart<._rootRunUnary<
  my_component_test.bootstrap.initialize.dart.browser_test.dart.js 8662:16   dart<._CustomZone.runUnary$2<
  my_component_test.bootstrap.initialize.dart.browser_test.dart.js 6952:58   dart<._Future__propagateToListeners_handleValueCallback.call$0
  my_component_test.bootstrap.initialize.dart.browser_test.dart.js 6859:53   dart<._Future.static._Future__propagateToListeners
  my_component_test.bootstrap.initialize.dart.browser_test.dart.js 6746:9    dart<._Future._completeWithValue$1
  my_component_test.bootstrap.initialize.dart.browser_test.dart.js 6938:9    dart<._Future__asyncComplete_closure0.call$0<
  my_component_test.bootstrap.initialize.dart.browser_test.dart.js 5974:14   dart<._rootRun<
  my_component_test.bootstrap.initialize.dart.browser_test.dart.js 8655:16   dart<._CustomZone.run$1<
  my_component_test.bootstrap.initialize.dart.browser_test.dart.js 8739:16   dart<._CustomZone_bindCallback_closure0.call$0<
  my_component_test.bootstrap.initialize.dart.browser_test.dart.js 7119:16   dart<._AsyncCallbackEntry.callback$0
  my_component_test.bootstrap.initialize.dart.browser_test.dart.js 5778:9    dart<._microtaskLoop
  my_component_test.bootstrap.initialize.dart.browser_test.dart.js 5784:9    dart<._microtaskLoopEntry<
  my_component_test.bootstrap.initialize.dart.browser_test.dart.js 6109:9    dart<._AsyncRun__initializeScheduleImmediate_internalCallback.call$1<
  my_component_test.bootstrap.initialize.dart.browser_test.dart.js 4076:16   dart<.invokeClosure_closure0.call$0
  my_component_test.bootstrap.initialize.dart.browser_test.dart.js 1881:20   dart<._IsolateContext.eval$1
  my_component_test.bootstrap.initialize.dart.browser_test.dart.js 1525:20   dart<._callInIsolate
  my_component_test.bootstrap.initialize.dart.browser_test.dart.js 3053:16   dart<.invokeClosure<
  my_component_test.bootstrap.initialize.dart.browser_test.dart.js 3072:18   dart<.convertDartClosureToJS.<fn>.<fn>

Dart VM version: 1.13.0-dev.7.12 (Fri Nov 13 15:34:05 2015) on "macos_x64"

jakemac53 commented 8 years ago

The project works for me as well...

flash1293 commented 8 years ago

Firefox is the problem in my configuration - the test runs fine in chrome but crashes with the above stacktrace in firefox. Where should I file this bug?

jakemac53 commented 8 years ago

You must include <script src="packages/web_components/webcomponents-lite.min.js"></script> before your dart script, and before any html imports. You don't need to manually put <link rel="import" href="packages/web_components/interop_support.html"> (it will get automatically added). I verified with your project that doing this resolves the FF issue.

jakemac53 commented 8 years ago

fwiw if you don't include the polyfill script it causes the script in interop_support.html to have errors, which is why it was giving that warning about it not being loaded.