|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | | -var adapters = ['local', 'http']; |
| 3 | +const adapters = ['local', 'http']; |
4 | 4 |
|
5 | | -adapters.forEach(function (adapter) { |
6 | | - describe('test.events.js-' + adapter, function () { |
| 5 | +adapters.forEach((adapter) => { |
| 6 | + describe(`test.events.js-${adapter}`, () => { |
7 | 7 |
|
8 | | - var dbs = {}; |
| 8 | + const dbs = {}; |
9 | 9 |
|
10 | | - beforeEach(function () { |
| 10 | + beforeEach(() => { |
11 | 11 | dbs.name = testUtils.adapterUrl(adapter, 'testdb'); |
12 | 12 | }); |
13 | 13 |
|
14 | | - afterEach(function (done) { |
15 | | - testUtils.cleanup([dbs.name], done); |
| 14 | + afterEach(async () => { |
| 15 | + await new Promise((resolve, reject) => testUtils.cleanup([dbs.name], (err) => { |
| 16 | + return err ? reject(err) : resolve(); |
| 17 | + })); |
16 | 18 | }); |
17 | 19 |
|
18 | | - it('PouchDB emits creation event', function (done) { |
19 | | - PouchDB.once('created', function (name) { |
20 | | - name.should.equal(dbs.name, 'should be same thing'); |
21 | | - done(); |
| 20 | + it('PouchDB emits creation event', async () => { |
| 21 | + const eventPromise = new Promise((resolve) => { |
| 22 | + PouchDB.once('created', (name) => { |
| 23 | + name.should.equal(dbs.name, 'should be same thing'); |
| 24 | + resolve(); |
| 25 | + }); |
22 | 26 | }); |
23 | 27 | new PouchDB(dbs.name); |
| 28 | + await eventPromise; |
24 | 29 | }); |
25 | 30 |
|
26 | | - it('PouchDB emits destruction event', function (done) { |
27 | | - var db = new PouchDB(dbs.name); |
28 | | - db.once('destroyed', done); |
| 31 | + it('PouchDB emits destruction event', async () => { |
| 32 | + const db = new PouchDB(dbs.name); |
| 33 | + const destroyedPromise = new Promise((resolve) => db.once('destroyed', resolve)); |
29 | 34 | db.destroy(); |
| 35 | + await destroyedPromise; |
30 | 36 | }); |
31 | 37 |
|
32 | | - it('PouchDB emits destruction event on PouchDB object', function (done) { |
33 | | - PouchDB.once('destroyed', function (name) { |
34 | | - name.should.equal(dbs.name, 'should have the same name'); |
35 | | - done(); |
| 38 | + it('PouchDB emits destruction event on PouchDB object', async () => { |
| 39 | + const eventPromise = new Promise((resolve) => { |
| 40 | + PouchDB.once('destroyed', (name) => { |
| 41 | + name.should.equal(dbs.name, 'should have the same name'); |
| 42 | + resolve(); |
| 43 | + }); |
36 | 44 | }); |
37 | 45 | new PouchDB(dbs.name).destroy(); |
| 46 | + await eventPromise; |
38 | 47 | }); |
39 | 48 |
|
40 | | - it('PouchDB emits destroyed when using {name: foo}', function () { |
41 | | - var db = new PouchDB({name: 'testdb'}); |
42 | | - return new Promise(function (resolve) { |
43 | | - PouchDB.once('destroyed', function (name) { |
| 49 | + it('PouchDB emits destroyed when using {name: foo}', async () => { |
| 50 | + const db = new PouchDB({name: 'testdb'}); |
| 51 | + await new Promise((resolve) => { |
| 52 | + PouchDB.once('destroyed', (name) => { |
44 | 53 | name.should.equal('testdb'); |
45 | 54 | resolve(); |
46 | 55 | }); |
47 | 56 | db.destroy(); |
48 | 57 | }); |
49 | 58 | }); |
50 | 59 |
|
51 | | - it('db emits destroyed on all DBs', function () { |
52 | | - var db1 = new PouchDB('testdb'); |
53 | | - var db2 = new PouchDB('testdb'); |
| 60 | + it('db emits destroyed on all DBs', async () => { |
| 61 | + const db1 = new PouchDB('testdb'); |
| 62 | + const db2 = new PouchDB('testdb'); |
54 | 63 |
|
55 | | - return new Promise(function (resolve) { |
56 | | - var called = 0; |
57 | | - function checkDone() { |
| 64 | + await new Promise((resolve) => { |
| 65 | + let called = 0; |
| 66 | + const checkDone = () => { |
58 | 67 | if (++called === 2) { |
59 | 68 | resolve(); |
60 | 69 | } |
61 | | - } |
| 70 | + }; |
62 | 71 | db1.once('destroyed', checkDone); |
63 | 72 | db2.once('destroyed', checkDone); |
64 | 73 | db1.destroy(); |
65 | 74 | }); |
66 | 75 | }); |
67 | 76 |
|
68 | | - it('3900 db emits destroyed event', function () { |
69 | | - var db = new PouchDB('testdb'); |
70 | | - return new Promise(function (resolve) { |
71 | | - db.once('destroyed', function () { |
72 | | - resolve(); |
73 | | - }); |
| 77 | + it('3900 db emits destroyed event', async () => { |
| 78 | + const db = new PouchDB('testdb'); |
| 79 | + await new Promise((resolve) => { |
| 80 | + db.once('destroyed', resolve); |
74 | 81 | db.destroy(); |
75 | 82 | }); |
76 | 83 | }); |
77 | 84 |
|
78 | | - it('3900 db emits destroyed event 2', function () { |
79 | | - var db = new PouchDB('testdb'); |
80 | | - return new Promise(function (resolve) { |
81 | | - db.once('destroyed', function () { |
82 | | - resolve(); |
83 | | - }); |
| 85 | + it('3900 db emits destroyed event 2', async () => { |
| 86 | + const db = new PouchDB('testdb'); |
| 87 | + await new Promise((resolve) => { |
| 88 | + db.once('destroyed', resolve); |
84 | 89 | db.destroy(); |
85 | 90 | }); |
86 | 91 | }); |
87 | 92 |
|
88 | | - it('emit creation event', function (done) { |
89 | | - var db = new PouchDB(dbs.name).on('created', function (newDB) { |
90 | | - db.should.equal(newDB, 'should be same thing'); |
91 | | - done(); |
| 93 | + it('emit creation event', async () => { |
| 94 | + await new Promise((resolve) => { |
| 95 | + const db = new PouchDB(dbs.name).on('created', (newDB) => { |
| 96 | + db.should.equal(newDB, 'should be same thing'); |
| 97 | + resolve(); |
| 98 | + }); |
92 | 99 | }); |
93 | 100 | }); |
94 | 101 |
|
95 | | - it('#4168 multiple constructor calls don\'t leak listeners', function () { |
96 | | - for (var i = 0; i < 50; i++) { |
| 102 | + it('#4168 multiple constructor calls don\'t leak listeners', () => { |
| 103 | + for (let i = 0; i < 50; i++) { |
97 | 104 | new PouchDB(dbs.name); |
98 | 105 | } |
99 | 106 | }); |
100 | 107 |
|
101 | | - it('4922 Destroyed is not called twice', function (done) { |
102 | | - var count = 0; |
103 | | - function destroyed() { |
104 | | - count++; |
105 | | - if (count === 1) { |
106 | | - setTimeout(function () { |
107 | | - count.should.equal(1); |
108 | | - PouchDB.removeListener('destroyed', destroyed); |
109 | | - done(); |
110 | | - }, 50); |
111 | | - } |
112 | | - } |
113 | | - PouchDB.on('destroyed', destroyed); |
114 | | - new PouchDB(dbs.name).destroy(); |
| 108 | + it('4922 Destroyed is not called twice', async () => { |
| 109 | + let count = 0; |
| 110 | + await new Promise((resolve) => { |
| 111 | + const destroyed = () => { |
| 112 | + count++; |
| 113 | + if (count === 1) { |
| 114 | + setTimeout(() => { |
| 115 | + count.should.equal(1); |
| 116 | + PouchDB.removeListener('destroyed', destroyed); |
| 117 | + resolve(); |
| 118 | + }, 50); |
| 119 | + } |
| 120 | + }; |
| 121 | + PouchDB.on('destroyed', destroyed); |
| 122 | + new PouchDB(dbs.name).destroy(); |
| 123 | + }); |
115 | 124 | }); |
116 | 125 |
|
117 | 126 | }); |
|
0 commit comments