aboutsummaryrefslogtreecommitdiff
path: root/catapult/docs/dev-server-tests.md
blob: 6a97d0b3a1b9fd88cc58f3175326c3a7b363c47f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# Overview of dev_server testing

## Introduction

Catapult has a simple, optionally asynchronous, JavaScript testing framework.
The framework is located in `/tracing/base/unittest/`.

Test files exist in `<filename>_test.html` files where, typically, filename
will match the name of the file being tested. The tests sit in the same
folder as their respective files.

## Test Creation

The general structure of tests is (assuming a file of ui/foo_test.html):

```
<link rel="import" href="/ui/foo.html">
<script>
'use strict';

tr.b.unittest.testSuite(function() {
  test('instantiate', function() {
    var myFoo = ui.Foo();
    this.addHTMLOutput(myFoo);
  });

  test('somethingElse', function() {
  });
});
```

Generally, there is one test suite per file (there is an assumption inside the
code that this is true).

If you add something to the DOM with `appendChild` you should remove it. The
exception is if you use `this.addHTMLOutput(element)`. If you use that, then
you should be good, the content will get shown if there is an error,
otherwise it's hidden.

The current tests follow the convention that if the test is there just to draw
things, to name them with a prefix of instantiate. So, `instantiate`,
`instantiate_multiRow`, etc.

## Chai

Catapult uses [Chai](http://chaijs.com) for assertions. We are using Chai's
[TDD `assert` style](http://chaijs.com/api/assert/).

## Execution

You'll need to start a dev_server to run the tests
```
$ bin/run_dev_server
```

After you start the dev_server, it'll be available at http://localhost:8003.
You'll see links to run unit tests for all projects. We'll use the `tracing/`
project as an example below.

### Running all tests

```
http://localhost:8003/tracing/tests.html
```

### Running an individual test suite (such as `ui/foo_test.js`)

```
http://localhost:8003/tracing/tests.html?testSuiteName=ui.foo
```

### Running tests named blah

```
http://localhost:8003/tracing/tests.html?testFilterString=blah
```

## Options

If you select the `small format` option on the main test page and reload then
the test output will be condensed to a lot smaller, making it easier to see
errors without having to scroll the screen.