# testharness.js Tests ```eval_rst .. toctree:: :maxdepth: 1 idlharness testharness-api testdriver-extension-tutorial testdriver ``` testharness.js tests are the correct type of test to write in any situation where you are not specifically interested in the rendering of a page, and where human interaction isn't required; these tests are written in JavaScript using a framework called `testharness.js`. It is documented in two sections: * [testharness.js Documentation](testharness-api.md) — An introduction to the library and a detailed API reference. * [idlharness.js Documentation](idlharness.md) — A library for testing IDL interfaces using `testharness.js`. See [server features](server-features.md) for advanced testing features that are commonly used with testharness.js. See also the [general guidelines](general-guidelines.md) for all test types. This page describes testharness.js exhaustively; [the tutorial on writing a testharness.js test](testharness-tutorial) provides a concise guide to writing a test--a good place to start for newcomers to the project. ## Variants A test file can have multiple variants by including `meta` elements, for example: ```html ``` The test can then do different things based on the URL. There are two utility scripts in that work well together with variants, `/common/subset-tests.js` and `/common/subset-tests-by-key.js`, where a test that would otherwise have too many tests to be useful can be split up in ranges of subtests. For example: ```html
x.any.js
, the available scope keywords
are:
* `window` (default): to be run at x.any.html
* `dedicatedworker` (default): to be run at x.any.worker.html
* `serviceworker`: to be run at x.any.serviceworker.html
(`.https` is implied)
* `sharedworker`: to be run at x.any.sharedworker.html
* `jsshell`: to be run in a JavaScript shell, without access to the DOM
(currently only supported in SpiderMonkey, and skipped in wptrunner)
* `default`: shorthand for the default scopes
* `worker`: shorthand for the dedicated, shared and service worker scopes
To check if your test is run from a window or worker you can use the following two methods that will
be made available by the framework:
self.GLOBAL.isWindow()
self.GLOBAL.isWorker()
Although [the global `done` function must be explicitly invoked for most
dedicated worker tests and shared worker
tests](testharness-api.html#determining-when-all-tests-are-complete), it is
automatically invoked for tests defined using the "multi-global" pattern.
### Specifying a test title in auto-generated boilerplate tests
Use `// META: title=This is the title of the test` at the beginning of the resource.
### Including other JavaScript resources in auto-generated boilerplate tests
Use `// META: script=link/to/resource.js` at the beginning of the resource. For example,
```
// META: script=/common/utils.js
// META: script=resources/utils.js
```
can be used to include both the global and a local `utils.js` in a test.
### Specifying a timeout of long in auto-generated boilerplate tests
Use `// META: timeout=long` at the beginning of the resource.
### Specifying test [variants](#variants) in auto-generated boilerplate tests
Use `// META: variant=url-suffix` at the beginning of the resource. For example,
```
// META: variant=
// META: variant=?wss
```