Daniel Robinson
Daniel Robinson

Reputation: 14868

drone.io headless dartium testing

Can you run browser based unit tests for Dart on drone.io? my last failed build is here. I tried sudo start xvfb but I'm not sure how to point that to my index.html file that launches my unit tests, anyone know how to do this? I should say that I am in no way interested in any actual DOM testing but my library imports 'dart:html' so I can't run it in the basic dart vm only configuration.

Upvotes: 3

Views: 689

Answers (2)

scribeGriff
scribeGriff

Reputation: 637

Update: Modified the build script to download content_shell. Also updated the path to content_shell in the hop task createUnitTestTask().


I use the hop pub package to do headless testing for drone. You can refer to the simplot library for a relatively simple example. But the steps are basically to add the following to your pubspec.yaml as developer dependencies:

hop: '>=0.27.0'
unittest: '>=0.9.0 <0.10.0'

Create a tool directory in your project root and add a file hop_runner.dart. Mine looks something like this:

library dumprendertree;

import 'package:hop/hop.dart';
import 'dart:io';
import 'dart:async';

main(List<String> args) {
  addTask('test', createUnitTestTask());
  runHop(args);
}

Task createUnitTestTask() {
  return new Task((TaskContext tcontext) {
    tcontext.info("Running Unit Tests....");
    var result = Process.run('./content_shell',
        ['--dump-render-tree','test/simplot_tests.html'])
        .then((ProcessResult process) {
          tcontext.info(process.stdout);
        });
    return result;
  });
}

You can see where it is calling my simplot_tests.html file in the test directory.

Then my drone script is:

$DART_SDK/../chromium/download_contentshell.sh
unzip content_shell-linux-x64-release.zip
mv drt*/* .
pub get
sudo start xvfb
dart --checked tool/hop_runner.dart test

The simplot_tests.html file looks like the following:

<!DOCTYPE html>

<html>
  <head>
    <title>Unit Tests for Simplot Library</title>
  </head>
  <body>
    <script type="text/javascript" src="packages/unittest/test_controller.js"></script>
    <script type="text/javascript" src="packages/browser/dart.js"></script>
    <script type="application/dart" src="simplot_tests.dart"></script>
  </body>
</html>

And finally, the dart file looks something like this:

import 'package:simplot/simplot.dart';
import 'package:unittest/unittest.dart';
import 'package:unittest/html_enhanced_config.dart';
import 'dart:html';
import 'dart:math';

part 'tests/logarithmic_tests.dart';
part 'tests/time_stamp_tests.dart';
part 'tests/axis_configure_tests.dart';
part 'tests/create_single_plot.dart';
part 'tests/create_multiple_plots.dart';
part '../lib/src/axis_config.dart';

void main() {
  print('Running unit tests for simplot library.');
  useHtmlEnhancedConfiguration();
  group('All Tests:', (){
    test('test of logarithmic functions', () => logarithmicTests());
    test('test of time stamp', () => timeStampTests());
    test('test of axis configuration', () => axisConfigTests());
    test('test of creating a single plot', () => createSinglePlot());
    test('test of creating multiple plots', () => createMultiplePlots());
  });
}

Hopefully, that should get you started.

Upvotes: 3

user2685314
user2685314

Reputation: 1069

This is my Drone script for the xml2json library

pub install
sudo start xvfb
content_shell --args --dump-render-tree test/xml2json.html | sed -n 2p | grep PASS

It uses standard HTML based unit testing, ie includes htmlconfiguration().

The grep is just to check for pass/fail, you may not need this.

Upvotes: 2

Related Questions