Friday, November 8, 2013

Auto-Install content_shell from CI (like drone.io)


This is one of things that I could probably wait on but...

In preparation the 1.0 release of Dart (which is going to happen any day NOW!), the language and tool maintainers have begun to pare down the size of the downloads. One of the first things to go was the content_shell which can create a browser context from the command-line, making it very handy for testing. And without it, I am getting errors like:
test/run.sh: line 11: content_shell: command not found
Bummer, right?

Well, the Dart folks didn't just delete it. In its place they left a handy download script. I ought to be able to add some download code just above that line 11 failure to check for content_shell and, if not present, to download it into the current path:
# ...
which content_shell
if [[ $? -ne 0 ]]; then
  $DART_SDK/../chromium/download_contentshell.sh
  unzip content_shell-linux-x64-release.zip

  cs_path=$(ls -d drt-*)
  PATH=$cs_path:$PATH
fi

results=$(content_shell --dump-render-tree test/index.html 2>&1)
echo -e "$results"
# ...
That still does not quite work. The tests are passing in Dartium, but not in content_shell. Actually, they are passing in content_shell as well, but my hacked together post-message-to-test-controller-on-completion thing is no longer working:
main(){
  // tests here...
  pollForDone(testCases);
}

pollForDone(List tests) {
  if (tests.every((t)=> t.isComplete)) {
    window.postMessage('done', '*');
    return;
  }

  var wait = new Duration(milliseconds: 100);
  new Timer(wait, ()=> pollForDone(tests));
}
I knew at the time that I started using that hack that I ought to look into the real Dart way of doing that. Since then, nothing has kicked me in the butt enough to actually make that happen. Until now.

The solution turns out to be simple enough—to use the HTML configuration built into unittest:
import 'package:unittest/unittest.dart';
import 'package:unittest/html_config.dart';
// ...
main(){
  useHtmlConfiguration();
  // tests here...
}
With that, my test suite passes both in the browser and from the downloaded content_shell. I really wish I has spent a couple of minutes digging for that solution back when I hacked that mess together. I feel quite silly now.

Anyhow, with that, I am ready to commit and to see if the build passes on drone.io. A quick git commit locally, a git push to GitHub and a brief wait for drone.io to automatically build my test suite, and...

It passes. Yay!

No doubt the drone.io folks will make content_shell part of the normal build process. I doubt they want every Dart package downloading content_shell on each build any more than Dart developers want to add crazy Bash like that to their test runners. But it is nice to know that it is possible to do in a pinch.


Day #929

No comments:

Post a Comment