You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> This is necessary for both `npm test` and `npm run dev`.
18
+
19
+
## Table of Contents <!-- omit from toc -->
20
+
21
+
-[Running the integration tests](#running-the-integration-tests)
22
+
-[Test options](#test-options)
23
+
-[Other sets of tests](#other-sets-of-tests)
24
+
-[`find` and `mapreduce`](#find-and-mapreduce)
25
+
-["Fuzzy" tests](#fuzzy-tests)
26
+
-[Performance tests](#performance-tests)
27
+
-[Running tests in the browser](#running-tests-in-the-browser)
28
+
-[Other test tasks](#other-test-tasks)
29
+
-[Troubleshooting and useful info when working on tests](#troubleshooting-and-useful-info-when-working-on-tests)
30
+
-[Where do I get a CouchDB from?](#where-do-i-get-a-couchdb-from)
31
+
-[Utils won’t update](#utils-wont-update)
32
+
-[Flaky tests and random timeouts](#flaky-tests-and-random-timeouts)
10
33
11
34
The PouchDB test suite expects an instance of CouchDB (version 1.6.1 and above)
12
35
running in [Admin Party](http://guide.couchdb.org/draft/security.html#party) on
@@ -38,6 +61,9 @@ The main test suite can be run using the following command:
38
61
39
62
$ npm test
40
63
64
+
> [!NOTE]
65
+
> If the tests don‘t pass on `main`, try building once before running the tests: `$npm run build`.
66
+
41
67
PouchDB runs in the browser and on Node.js, and has multiple different storage
42
68
backends known as _adapters_. In the browser these are `idb`, `indexeddb` and
43
69
`memory` and on Node.js they're `leveldb` and `memory`.
@@ -59,7 +85,7 @@ replication to a remote server, and by default we start an instance of
59
85
The integration tests support the following options, configured via environment
60
86
variables.
61
87
62
-
#### `ADAPTERS` (default: depends on `CLIENT`)
88
+
#### `ADAPTERS` (default: depends on `CLIENT`)<!-- omit from toc -->
63
89
64
90
Comma-separated list of preferred adapter backends that PouchDB will use for local
65
91
databases. These are selected automatically based on the execution environment,
@@ -74,21 +100,21 @@ a remote server, identified by `COUCH_HOST`. This is not necessary for
74
100
integration tests since they use a mixture of local and remote databases to
75
101
check compatibility, but it's useful for the `find` and `mapreduce` suites.
76
102
77
-
#### `AUTO_COMPACTION` (default: `0`)
103
+
#### `AUTO_COMPACTION` (default: `0`)<!-- omit from toc -->
78
104
79
105
Set this to `1` to enable automatic compaction of PouchDB databases by default.
80
106
81
-
#### `BAIL` (default: `1`)
107
+
#### `BAIL` (default: `1`)<!-- omit from toc -->
82
108
83
109
Normally the test runner will halt as soon as it discovers a failing test. Set
84
110
this to `0` to prevent this behaviour.
85
111
86
-
#### `CLIENT` (default: `node`)
112
+
#### `CLIENT` (default: `node`)<!-- omit from toc -->
87
113
88
114
Sets the target platform the tests will execute on. Set this to
89
115
`firefox`, `chromium` or `webkit` to execute the tests in the browser.
90
116
91
-
#### `COUCH_HOST`
117
+
#### `COUCH_HOST`<!-- omit from toc -->
92
118
93
119
Some tests perform replication between local and remote databases. When we
94
120
create a remote database, we get the URL of the remote server from `COUCH_HOST`.
@@ -98,45 +124,45 @@ CORS enabled.
98
124
If not set explicitly, this variable is set automatically based on the other
99
125
configuration values.
100
126
101
-
#### `FETCH` (default: `0`)
127
+
#### `FETCH` (default: `0`)<!-- omit from toc -->
102
128
103
129
Set this to `1` to stop PouchDB falling back to `XMLHttpRequest` if `fetch()` is
104
130
not available.
105
131
106
-
#### `GREP`
132
+
#### `GREP`<!-- omit from toc -->
107
133
108
134
Use this to request that a specific test is run; if you set `GREP='name of
109
135
test'` then only those tests whose names include the string `name of test` will
110
136
run. Regular expressions are also supported.
111
137
112
-
#### `PLUGINS` (default: empty)
138
+
#### `PLUGINS` (default: empty)<!-- omit from toc -->
113
139
114
140
Comma-separated list of additional plugins that should be loaded into the test
115
141
environment. For example:
116
142
117
143
$ PLUGINS=pouchdb-find npm test
118
144
119
-
#### `POUCHDB_SRC`
145
+
#### `POUCHDB_SRC`<!-- omit from toc -->
120
146
121
147
This overrides the path used to load PouchDB in the browser. We use this in CI
122
148
to select different builds of the PouchDB library, for example to test the
123
149
Webpack version, etc.
124
150
125
151
This is an alternative to `SRC_ROOT` and `USE_MINIFIED`.
126
152
127
-
#### `SRC_ROOT`
153
+
#### `SRC_ROOT`<!-- omit from toc -->
128
154
129
155
This overrides the path used to load all PouchDB files in the browser. We use
130
156
this in performance tests to allow easily comparing two different versions of
131
157
PouchDB, including plugin and adapter implementations.
132
158
133
-
#### `USE_MINIFIED`
159
+
#### `USE_MINIFIED`<!-- omit from toc -->
134
160
135
161
This changes the file extension used for loading PouchDB files in the browser.
136
162
This can be used in CI and performance testing to select the minified version of
137
163
PouchDB and its adapters, plugins, etc.
138
164
139
-
#### `SERVER` (default: `pouchdb-express-router`)
165
+
#### `SERVER` (default: `pouchdb-express-router`)<!-- omit from toc -->
140
166
141
167
To support remote replication tests, we start a server in the background that
142
168
speaks the CouchDB replication protocol. This variable controls how that is
@@ -151,11 +177,11 @@ following values:
151
177
-`couchdb-master`: use this value if you already have CouchDB running; it
152
178
causes `COUCH_HOST` to be set to the correct value.
153
179
154
-
#### `SKIP_MIGRATION` (default: `0`)
180
+
#### `SKIP_MIGRATION` (default: `0`)<!-- omit from toc -->
155
181
156
182
Set this to `1` to skip the migration tests.
157
183
158
-
#### `VIEW_ADAPTERS` (default: `memory`)
184
+
#### `VIEW_ADAPTERS` (default: `memory`)<!-- omit from toc -->
159
185
160
186
Comma-separated list of preferred view adapter backends that PouchDB will use.
161
187
This variable overrides the default choice and causes additional adapters to
@@ -226,7 +252,7 @@ This supports most of the same options as the integration suite, particularly
226
252
the `CLIENT`, `ADAPTERS` and `GREP` options. It has some additional options of
227
253
its own:
228
254
229
-
#### `ITERATIONS`
255
+
#### `ITERATIONS`<!-- omit from toc -->
230
256
231
257
Sets the number of iterations each test uses by default.
232
258
@@ -252,15 +278,20 @@ server and opening a browser window yourself. To run the server:
252
278
253
279
$ npm run dev
254
280
281
+
You will almost always want to include the `find` plugin though, without it, all the `find` tests will fail:
282
+
283
+
$ PLUGINS=pouchdb-find npm run dev
284
+
255
285
Then you can open the page for any of the test suites via the following URLs:
256
286
257
287
-`http://127.0.0.1:8000/tests/integration/`
258
288
-`http://127.0.0.1:8000/tests/find/`
259
289
-`http://127.0.0.1:8000/tests/mapreduce/`
260
290
-`http://127.0.0.1:8000/tests/performance/`
261
291
262
-
The test options are controlled by editing the query string; some of the common
263
-
command-line options and their query string equivalents are:
292
+
You can re-run tests by reloading, and only run specific suites by clicking on the suite names, this sets the `grep` query string mentioned below. This works well in conjunction with setting `.only` on individual tests in that suite.
293
+
294
+
The test options are controlled by editing the query string; some of the common command-line options and their query string equivalents are:
264
295
265
296
| Environment variable | Query-string param |
266
297
| -------------------- | ------------------ |
@@ -281,29 +312,61 @@ command-line options and their query string equivalents are:
281
312
There are a few other tasks we run during CI and which you will find useful to
282
313
run during development.
283
314
284
-
### `npm run eslint`
315
+
### `npm run eslint`<!-- omit from toc -->
285
316
286
317
Checks that all code in the project follows our formatting and style guide. This
287
318
runs before any other tasks are run during our CI build.
288
319
289
-
### `npm run test-unit`
320
+
### `npm run test-unit`<!-- omit from toc -->
290
321
291
322
Runs the unit tests; running these can give more precise feedback about key
292
323
building blocks that are not working.
293
324
294
-
### `npm run test-component`
325
+
### `npm run test-component`<!-- omit from toc -->
295
326
296
327
Tests some additional components besides the core database functionality, for
297
328
example authentication and read-only replication.
298
329
299
-
### `npm run test-coverage`
330
+
### `npm run test-coverage`<!-- omit from toc -->
300
331
301
332
Runs the test suite with coverage analysis turned on.
302
333
303
-
### `npm run test-webpack`
334
+
### `npm run test-webpack`<!-- omit from toc -->
304
335
305
336
Checks that the Webpack build of PouchDB works correctly.
306
337
307
-
### `npm run verify-build`
338
+
### `npm run verify-build`<!-- omit from toc -->
308
339
309
340
Checks that the build is correct.
341
+
342
+
## Troubleshooting and useful info when working on tests
343
+
344
+
### Where do I get a CouchDB from?
345
+
346
+
See the [official CouchDB documentation](https://docs.couchdb.org/en/stable/install/index.html) for a guide on how to install CouchDB.
347
+
348
+
Your CouchDB will most likely then run at `http://127.0.0.1:5984`. All you need to do now is enable CORS so CouchDB will accept requests from PouchDB in the tests. Add `http://127.0.0.1:8000`, the test server’s domain. There are several ways to do this, easiest first:
349
+
350
+
1. In the [CouchDB admin UI](http://127.0.0.1:5984/_utils), click on `Configuration` -> `CORS`.
351
+
2. Via cURL (`_local` is the node name in single-node databases, which your local dev CouchDB probably is):
352
+
```sh
353
+
curl 'http://admin:password@127.0.0.1:5984/_node/_local/_config/cors/origins' -X PUT -d '"http://127.0.0.1:8000"'
354
+
```
355
+
3. There’s also an older [npm package](https://github.com/pouchdb/add-cors-to-couchdb) to help you do this porgrammatically.
356
+
357
+
### Utils won’t update
358
+
359
+
If you’re modifying the test utils (`/tests/integration/utils.js` etc.) or adding logs to them, you need to rebuild these before running your tests again, eg.:
360
+
361
+
```sh
362
+
$ npm run build && CLIENT=firefox npm test
363
+
```
364
+
365
+
### Flaky tests and random timeouts
366
+
367
+
If you regularly run into random timeouts, please re-read the top of this file and set the `COUCH_HOST` env var when running tests or the dev server, eg.:
368
+
369
+
```sh
370
+
$ CLIENT=firefox COUCH_HOST=http://admin:admin@127.0.0.1:5984 npm test
0 commit comments