Friday, January 4, 2013

Combined Tests in Dart

‹prev | My Chain | next›

Web components seem to be the rage in Dart-land of late, but I have almost no idea what they are. Sure, I could read excellent articles on the subject, but that's not how I learn best.

I start by updating my pubspec.yaml to include web_ui:
name: scripts
  hipster_mvc: any
  web_ui: any
  unittest: any
But when I run pub install, I am greeted with:
➜  app git:(web-components) ✗ pub install
Resolving dependencies...
Could not find package "hipster_mvc 0.2.4" at
I know that I published that, but it is not showing up in Dart Pub. Oh well, it's easy to re-publish:
➜  hipster-mvc git:(master) pub lish
Publishing "hipster_mvc" 0.2.4:
|-- .gitignore
|-- README.asciidoc
|-- lib
|   |-- hipster_collection.dart
|   |-- hipster_events.dart
|   |-- hipster_history.dart
|   |-- hipster_model.dart
|   |-- hipster_router.dart
|   |-- hipster_sync.dart
|   '-- hipster_view.dart
|-- pubspec.yaml
'-- test
    |-- hipster_events_test.dart
    '-- index.html

Looks great! Are you ready to upload your package (y/n)? y
hipster_mvc 0.2.4 uploaded successfully.
Done and done. Now to install web_ui:
➜  app git:(web-components) ✗ pub install
Resolving dependencies...
Could not find package "logging" at
Hrm... there are suspiciously fewer packages available in the pub tonight. It seems that something has gone wrong there. Hopefully this will not happen too often because I believe that I am completely blocked at this point.

So instead, I shift my attention to another question in need of answering: is it possible to have a whole book dashboard of my tests. I have been diligently extracting all code samples out into runnable tests. I can see the results of all tests within a chapter—either on the command line for non-browser chapters or in the browser for DOM-specific chapters. But what about putting them all together?

That turns out to be quite easy. The events chapter tests all have to run in the browser whereas I have been running the classes chapter tests from the command-line. To see both, I will need to run the tests in the least common denominator: the browser.

So I create a page to hold my tests:
  <title>Dart for Hipsters Tests</title>
  <script type="application/dart" src="test.dart"></script>

  <script type="text/javascript">
    // start dart


And, in the source'd test.dart, I import my two test.dart chapter files:
import 'package:unittest/html_enhanced_config.dart';
import 'package:unittest/unittest.dart';

import 'events/test.dart' as Events;
import 'classes/test.dart' as Classes;

main () {

I have to declare both as libraries (starting the files with the library directive), which is not a problem since it will have no effect on the current uses. The main() entry point in each of the chapter tests then becomes just another function in the imported libraries.

And, loading the combined tests up in my browser, I have two chapter's worth of tests passing at a glance:

It was a bummer not being able to mess about with web components tonight, but I am pretty happy to have a testing dashboard under way.

Day #620

No comments:

Post a Comment