@logux/server 0.12.3 → 0.12.5

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.
@@ -1,19 +1,16 @@
1
- import type { TestTime, TestLog } from '@logux/core'
2
- import type { TestClient, TestClientOptions } from '../test-client/index.js'
1
+ import type { TestLog, TestTime } from '@logux/core'
2
+
3
+ import { BaseServer } from '../base-server/index.js'
3
4
  import type {
4
5
  BaseServerOptions,
5
- ServerMeta,
6
- Logger
6
+ Logger,
7
+ ServerMeta
7
8
  } from '../base-server/index.js'
8
9
  import type { LoggerOptions } from '../server/index.js'
9
-
10
- import { BaseServer } from '../base-server/index.js'
10
+ import type { TestClient, TestClientOptions } from '../test-client/index.js'
11
11
 
12
12
  export interface TestServerOptions
13
13
  extends Omit<BaseServerOptions, 'subprotocol' | 'supports'> {
14
- subprotocol?: string
15
- supports?: string
16
-
17
14
  /**
18
15
  * Disable built-in auth.
19
16
  */
@@ -23,6 +20,10 @@ export interface TestServerOptions
23
20
  * Logger with custom settings.
24
21
  */
25
22
  logger?: Logger | LoggerOptions
23
+
24
+ subprotocol?: string
25
+
26
+ supports?: string
26
27
  }
27
28
 
28
29
  /**
@@ -48,9 +49,13 @@ export class TestServer<
48
49
  Headers extends object = {}
49
50
  > extends BaseServer<Headers> {
50
51
  /**
51
- * @param opts The limit subset of server options.
52
+ * Server actions log, with methods to check actions inside.
53
+ *
54
+ * ```js
55
+ * server.log.actions() //=> […]
56
+ * ```
52
57
  */
53
- constructor(opts?: TestServerOptions)
58
+ log: TestLog<ServerMeta>
54
59
 
55
60
  /**
56
61
  * Time replacement without variable parts like current timestamp.
@@ -58,13 +63,9 @@ export class TestServer<
58
63
  time: TestTime
59
64
 
60
65
  /**
61
- * Server actions log, with methods to check actions inside.
62
- *
63
- * ```js
64
- * server.log.actions() //=> […]
65
- * ```
66
+ * @param opts The limit subset of server options.
66
67
  */
67
- log: TestLog<ServerMeta>
68
+ constructor(opts?: TestServerOptions)
68
69
 
69
70
  /**
70
71
  * Create and connect client.
@@ -80,24 +81,6 @@ export class TestServer<
80
81
  */
81
82
  connect(userId: string, opts?: TestClientOptions): Promise<TestClient>
82
83
 
83
- /**
84
- * Try to connect client and throw an error is client didn’t received
85
- * `Wrong Cregentials` message from the server.
86
- *
87
- * ```js
88
- * server = new TestServer()
89
- * await server.expectWrongCredentials('10')
90
- * ```
91
- *
92
- * @param userId User ID.
93
- * @param opts Other options.
94
- * @returns Promise until check.
95
- */
96
- expectWrongCredentials(
97
- userId: string,
98
- opts?: TestClientOptions
99
- ): Promise<void>
100
-
101
84
  /**
102
85
  * Call callback and throw an error if there was no `Action was denied`
103
86
  * during callback.
@@ -112,6 +95,18 @@ export class TestServer<
112
95
  */
113
96
  expectDenied(test: () => any | Promise<any>): Promise<void>
114
97
 
98
+ /**
99
+ * Call callback and throw an error if there was no error during
100
+ * server processing.
101
+ *
102
+ * @param text RegExp or string of error message.
103
+ * @param test Callback with subscripting or action sending.
104
+ */
105
+ expectError(
106
+ text: RegExp | string,
107
+ test: () => any | Promise<any>
108
+ ): Promise<void>
109
+
115
110
  /**
116
111
  * Call callback and throw an error if there was no `logux/undo` in return
117
112
  * with specific reason.
@@ -128,14 +123,20 @@ export class TestServer<
128
123
  expectUndo(reason: string, test: () => any | Promise<any>): Promise<void>
129
124
 
130
125
  /**
131
- * Call callback and throw an error if there was no error during
132
- * server processing.
126
+ * Try to connect client and throw an error is client didn’t received
127
+ * `Wrong Cregentials` message from the server.
133
128
  *
134
- * @param text RegExp or string of error message.
135
- * @param test Callback with subscripting or action sending.
129
+ * ```js
130
+ * server = new TestServer()
131
+ * await server.expectWrongCredentials('10')
132
+ * ```
133
+ *
134
+ * @param userId User ID.
135
+ * @param opts Other options.
136
+ * @returns Promise until check.
136
137
  */
137
- expectError(
138
- text: string | RegExp,
139
- test: () => any | Promise<any>
138
+ expectWrongCredentials(
139
+ userId: string,
140
+ opts?: TestClientOptions
140
141
  ): Promise<void>
141
142
  }
@@ -1,7 +1,7 @@
1
1
  import { TestTime } from '@logux/core'
2
2
 
3
- import { createReporter } from '../create-reporter/index.js'
4
3
  import { BaseServer } from '../base-server/index.js'
4
+ import { createReporter } from '../create-reporter/index.js'
5
5
  import { TestClient } from '../test-client/index.js'
6
6
 
7
7
  export class TestServer extends BaseServer {
@@ -12,20 +12,20 @@ export class TestServer extends BaseServer {
12
12
 
13
13
  opts.time.lastId += 1
14
14
  super({
15
+ id: `${opts.time.lastId}`,
15
16
  subprotocol: '0.0.0',
16
17
  supports: '0.0.0',
17
- id: `${opts.time.lastId}`,
18
18
  ...opts
19
19
  })
20
20
  if (opts.logger) {
21
21
  this.on('report', createReporter(opts))
22
22
  } else {
23
23
  this.logger = {
24
- fatal: () => {},
24
+ debug: () => {},
25
25
  error: () => {},
26
- warn: () => {},
26
+ fatal: () => {},
27
27
  info: () => {},
28
- debug: () => {}
28
+ warn: () => {}
29
29
  }
30
30
  }
31
31
  if (opts.auth !== false) this.auth(() => true)
@@ -42,21 +42,24 @@ export class TestServer extends BaseServer {
42
42
  return client
43
43
  }
44
44
 
45
- async expectWrongCredentials(userId, opts = {}) {
45
+ async expectDenied(test) {
46
+ await this.expectUndo('denied', test)
47
+ }
48
+
49
+ async expectError(text, test) {
46
50
  try {
47
- await this.connect(userId, opts)
48
- throw new Error('Credentials passed')
51
+ await test()
52
+ throw new Error('Actions passed without error')
49
53
  } catch (e) {
50
- if (e.message !== 'Wrong credentials') {
54
+ if (
55
+ (typeof text === 'string' && e.message !== text) ||
56
+ (text instanceof RegExp && !text.test(e.message))
57
+ ) {
51
58
  throw e
52
59
  }
53
60
  }
54
61
  }
55
62
 
56
- async expectDenied(test) {
57
- await this.expectUndo('denied', test)
58
- }
59
-
60
63
  async expectUndo(reason, test) {
61
64
  try {
62
65
  await test()
@@ -75,15 +78,12 @@ export class TestServer extends BaseServer {
75
78
  }
76
79
  }
77
80
 
78
- async expectError(text, test) {
81
+ async expectWrongCredentials(userId, opts = {}) {
79
82
  try {
80
- await test()
81
- throw new Error('Actions passed without error')
83
+ await this.connect(userId, opts)
84
+ throw new Error('Credentials passed')
82
85
  } catch (e) {
83
- if (
84
- (typeof text === 'string' && e.message !== text) ||
85
- (text instanceof RegExp && !text.test(e.message))
86
- ) {
86
+ if (e.message !== 'Wrong credentials') {
87
87
  throw e
88
88
  }
89
89
  }
package/vite.config.ts CHANGED
@@ -2,12 +2,12 @@ import { defineConfig } from 'vitest/config'
2
2
 
3
3
  export default defineConfig({
4
4
  test: {
5
- environment: 'node',
6
- exclude: ['node_modules', 'test/servers'],
7
5
  coverage: {
8
- provider: 'c8',
6
+ exclude: ['node_modules', 'server/index.js', '*/*.test.*'],
9
7
  lines: 100,
10
- exclude: ['node_modules', 'server/index.js', '*/*.test.*']
11
- }
8
+ provider: 'v8'
9
+ },
10
+ environment: 'node',
11
+ exclude: ['node_modules', 'test/servers']
12
12
  }
13
13
  })