@dxos/async 0.6.13 → 0.6.14-main.1366248

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,9 +2,7 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { expect } from 'chai';
6
-
7
- import { afterTest, describe, test } from '@dxos/test';
5
+ import { describe, expect, onTestFinished, test } from 'vitest';
8
6
 
9
7
  import { Event } from './events';
10
8
  import { MulticastObservable, Observable, PushStream } from './observable';
@@ -23,7 +21,7 @@ describe('multicast observable', () => {
23
21
  expect(value).to.equal(1);
24
22
  trigger.wake();
25
23
  });
26
- afterTest(() => subscription.unsubscribe());
24
+ onTestFinished(() => subscription.unsubscribe());
27
25
  await trigger.wait();
28
26
  });
29
27
 
@@ -46,8 +44,8 @@ describe('multicast observable', () => {
46
44
  }
47
45
  });
48
46
 
49
- afterTest(() => subscription1.unsubscribe());
50
- afterTest(() => subscription2.unsubscribe());
47
+ onTestFinished(() => subscription1.unsubscribe());
48
+ onTestFinished(() => subscription2.unsubscribe());
51
49
 
52
50
  const next = { new: 'value' };
53
51
  event.emit(next);
@@ -100,7 +98,7 @@ describe('multicast observable', () => {
100
98
  const subscription = mapped.subscribe((value) => {
101
99
  result.wake(value);
102
100
  });
103
- afterTest(() => subscription.unsubscribe());
101
+ onTestFinished(() => subscription.unsubscribe());
104
102
  expect(await result.wait()).to.deep.equal(6);
105
103
  });
106
104
 
@@ -121,7 +119,7 @@ describe('multicast observable', () => {
121
119
  const subscription = reduced.subscribe((value) => {
122
120
  result.wake(value);
123
121
  });
124
- afterTest(() => subscription.unsubscribe());
122
+ onTestFinished(() => subscription.unsubscribe());
125
123
  expect(await result.wait()).to.deep.equal(6);
126
124
  });
127
125
 
@@ -2,11 +2,9 @@
2
2
  // Copyright 2022 DXOS.org
3
3
  //
4
4
 
5
- import { expect } from 'chai';
6
- import waitForExpect from 'wait-for-expect';
5
+ import { describe, expect, test } from 'vitest';
7
6
 
8
7
  import { Context } from '@dxos/context';
9
- import { describe, test } from '@dxos/test';
10
8
 
11
9
  import { DeferredTask, scheduleTask } from './task-scheduling';
12
10
  import { sleep } from './timeout';
@@ -25,9 +23,7 @@ describe('task-scheduling', () => {
25
23
  throw new Error('test');
26
24
  });
27
25
 
28
- await waitForExpect(() => {
29
- expect(error.message).to.eq('test');
30
- });
26
+ await expect.poll(() => error.message).toBe('test');
31
27
  });
32
28
 
33
29
  test('cancelation', async () => {
@@ -61,6 +61,7 @@ export class DeferredTask {
61
61
  if (this._ctx.disposed) {
62
62
  throw new ContextDisposedError();
63
63
  }
64
+
64
65
  this.schedule();
65
66
  await this._nextTask.wait();
66
67
  }
@@ -2,7 +2,7 @@
2
2
  // Copyright 2022 DXOS.org
3
3
  //
4
4
 
5
- import { test } from '@dxos/test';
5
+ import { test } from 'vitest';
6
6
 
7
7
  import { TestStream } from './test-stream';
8
8
 
@@ -2,10 +2,9 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import { expect } from 'chai';
5
+ import { describe, expect, test } from 'vitest';
6
6
 
7
7
  import { expectToThrow } from '@dxos/debug';
8
- import { describe, test } from '@dxos/test';
9
8
 
10
9
  import { waitForCondition } from './testing';
11
10
 
@@ -2,10 +2,7 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import { expect } from 'chai';
6
-
7
- import { expectToThrow } from '@dxos/debug';
8
- import { describe, test } from '@dxos/test';
5
+ import { describe, expect, test } from 'vitest';
9
6
 
10
7
  import { asyncTimeout, sleep } from './timeout';
11
8
 
@@ -18,7 +15,7 @@ describe('timeout', () => {
18
15
 
19
16
  test('fails', async () => {
20
17
  const promise = sleep(200).then(() => 'test');
21
- await expectToThrow(() => asyncTimeout(promise, 100, new Error('timeout')));
18
+ await expect(() => asyncTimeout(promise, 100, new Error('timeout'))).rejects.toThrowError();
22
19
  });
23
20
 
24
21
  test('sleep', async () => {
@@ -2,16 +2,11 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import chai, { expect } from 'chai';
6
- import chaiAsPromised from 'chai-as-promised';
7
-
8
- import { describe, test } from '@dxos/test';
5
+ import { describe, expect, test } from 'vitest';
9
6
 
10
7
  import { sleep } from './timeout';
11
8
  import { Trigger, TriggerState, trigger } from './trigger';
12
9
 
13
- chai.use(chaiAsPromised);
14
-
15
10
  describe('trigger', () => {
16
11
  test('trigger', async () => {
17
12
  const [value, setValue] = trigger<any>();
@@ -52,7 +47,7 @@ describe('trigger', () => {
52
47
  const error = new Error('Test error');
53
48
  const promise = trigger.wait();
54
49
  trigger.throw(error);
55
- await expect(promise).to.be.rejectedWith(error);
50
+ await expect(promise).rejects.toThrowError(error);
56
51
  expect(trigger.state).to.equal(TriggerState.REJECTED);
57
52
  trigger.reset();
58
53
  expect(trigger.state).to.equal(TriggerState.WAITING);
package/src/trigger.ts CHANGED
@@ -78,6 +78,9 @@ export class Trigger<T = void> {
78
78
  * NOOP if the trigger is already resolved.
79
79
  */
80
80
  wake(value: T) {
81
+ if (this._state !== TriggerState.WAITING) {
82
+ return this;
83
+ }
81
84
  this._state = TriggerState.RESOLVED;
82
85
  this._resolve(value);
83
86
  if (this._options.autoReset) {
@@ -106,6 +109,9 @@ export class Trigger<T = void> {
106
109
  * NOOP if the trigger is already resolved.
107
110
  */
108
111
  throw(error: Error) {
112
+ if (this._state !== TriggerState.WAITING) {
113
+ return this;
114
+ }
109
115
  this._state = TriggerState.REJECTED;
110
116
  this._reject(error);
111
117
  if (this._options.autoReset) {
package/src/until.test.ts CHANGED
@@ -2,10 +2,7 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- import { expect } from 'chai';
6
-
7
- import { expectToThrow } from '@dxos/debug';
8
- import { describe, test } from '@dxos/test';
5
+ import { describe, expect, test } from 'vitest';
9
6
 
10
7
  import { sleep } from './timeout';
11
8
  import { until } from './until';
@@ -22,29 +19,29 @@ describe('until', () => {
22
19
  });
23
20
 
24
21
  test('error', async () => {
25
- await expectToThrow(async () => {
22
+ await expect(async () => {
26
23
  await until(async (resolve, reject) => {
27
24
  await sleep(100);
28
25
  reject(new Error());
29
26
  });
30
- });
27
+ }).rejects.toThrowError();
31
28
  });
32
29
 
33
30
  test('catch', async () => {
34
- await expectToThrow(async () => {
31
+ await expect(async () => {
35
32
  await until(async () => {
36
33
  await sleep(100);
37
34
  throw new Error();
38
35
  });
39
- });
36
+ }).rejects.toThrowError();
40
37
  });
41
38
 
42
39
  test('timeout', async () => {
43
- await expectToThrow(async () => {
40
+ await expect(async () => {
44
41
  await until(async (resolve) => {
45
42
  await sleep(500);
46
43
  resolve();
47
44
  }, 100); // Timeout before complete.
48
- });
45
+ }).rejects.toThrowError();
49
46
  });
50
47
  });
@@ -2,10 +2,9 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { expect } from 'chai';
5
+ import { describe, expect, test } from 'vitest';
6
6
 
7
7
  import { Context } from '@dxos/context';
8
- import { describe, test } from '@dxos/test';
9
8
 
10
9
  import { sleep } from './timeout';
11
10
  import { UpdateScheduler } from './update-scheduler';