@powersync/service-core-tests 0.0.0-dev-20251030082344 → 0.0.0-dev-20251110113516

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.
package/CHANGELOG.md CHANGED
@@ -1,17 +1,26 @@
1
1
  # @powersync/service-core-tests
2
2
 
3
- ## 0.0.0-dev-20251030082344
3
+ ## 0.0.0-dev-20251110113516
4
+
5
+ ### Patch Changes
6
+
7
+ - 422ae99: General client connections analytics added
8
+ - Updated dependencies [422ae99]
9
+ - @powersync/service-core@0.0.0-dev-20251110113516
10
+
11
+ ## 0.12.9
4
12
 
5
13
  ### Patch Changes
6
14
 
7
15
  - 88982d9: Migrate to trusted publishing
8
16
  - Updated dependencies [b4fa979]
17
+ - Updated dependencies [80fd68b]
9
18
  - Updated dependencies [c2bd0b0]
10
19
  - Updated dependencies [0268858]
11
20
  - Updated dependencies [88982d9]
12
- - @powersync/service-sync-rules@0.0.0-dev-20251030082344
13
- - @powersync/service-jsonbig@0.0.0-dev-20251030082344
14
- - @powersync/service-core@0.0.0-dev-20251030082344
21
+ - @powersync/service-sync-rules@0.29.6
22
+ - @powersync/service-core@1.16.0
23
+ - @powersync/service-jsonbig@0.17.12
15
24
 
16
25
  ## 0.12.8
17
26
 
@@ -0,0 +1,78 @@
1
+ import { storage } from '@powersync/service-core';
2
+ export declare const REPORT_TEST_DATES: {
3
+ now: Date;
4
+ nowAdd5minutes: Date;
5
+ nowLess5minutes: Date;
6
+ dayAgo: Date;
7
+ yesterday: Date;
8
+ weekAgo: Date;
9
+ monthAgo: Date;
10
+ };
11
+ export declare const REPORT_TEST_USERS: {
12
+ user_one: {
13
+ user_id: string;
14
+ client_id: string;
15
+ connected_at: Date;
16
+ sdk: string;
17
+ user_agent: string;
18
+ jwt_exp: Date;
19
+ };
20
+ user_two: {
21
+ user_id: string;
22
+ client_id: string;
23
+ connected_at: Date;
24
+ sdk: string;
25
+ user_agent: string;
26
+ jwt_exp: Date;
27
+ };
28
+ user_three: {
29
+ user_id: string;
30
+ client_id: string;
31
+ connected_at: Date;
32
+ sdk: string;
33
+ user_agent: string;
34
+ disconnected_at: Date;
35
+ };
36
+ user_four: {
37
+ user_id: string;
38
+ client_id: string;
39
+ connected_at: Date;
40
+ sdk: string;
41
+ user_agent: string;
42
+ jwt_exp: Date;
43
+ };
44
+ user_old: {
45
+ user_id: string;
46
+ client_id: string;
47
+ connected_at: Date;
48
+ sdk: string;
49
+ user_agent: string;
50
+ jwt_exp: Date;
51
+ };
52
+ user_week: {
53
+ user_id: string;
54
+ client_id: string;
55
+ connected_at: Date;
56
+ sdk: string;
57
+ user_agent: string;
58
+ disconnected_at: Date;
59
+ };
60
+ user_month: {
61
+ user_id: string;
62
+ client_id: string;
63
+ connected_at: Date;
64
+ sdk: string;
65
+ user_agent: string;
66
+ disconnected_at: Date;
67
+ };
68
+ user_expired: {
69
+ user_id: string;
70
+ client_id: string;
71
+ connected_at: Date;
72
+ sdk: string;
73
+ user_agent: string;
74
+ jwt_exp: Date;
75
+ };
76
+ };
77
+ export type ReportUserData = typeof REPORT_TEST_USERS;
78
+ export declare function registerReportTests(factory: storage.ReportStorage): Promise<void>;
@@ -0,0 +1,181 @@
1
+ import { expect, it } from 'vitest';
2
+ const now = new Date();
3
+ const nowAdd5minutes = new Date(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours(), now.getMinutes() + 5);
4
+ const nowLess5minutes = new Date(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours(), now.getMinutes() - 5);
5
+ const dayAgo = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1, now.getHours());
6
+ const yesterday = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1);
7
+ const weekAgo = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 7);
8
+ const monthAgo = new Date(now.getFullYear(), now.getMonth() - 1, now.getDate());
9
+ export const REPORT_TEST_DATES = {
10
+ now,
11
+ nowAdd5minutes,
12
+ nowLess5minutes,
13
+ dayAgo,
14
+ yesterday,
15
+ weekAgo,
16
+ monthAgo
17
+ };
18
+ const user_one = {
19
+ user_id: 'user_one',
20
+ client_id: 'client_one',
21
+ connected_at: now,
22
+ sdk: 'powersync-dart/1.6.4',
23
+ user_agent: 'powersync-dart/1.6.4 Dart (flutter-web) Chrome/128 android',
24
+ jwt_exp: nowAdd5minutes
25
+ };
26
+ const user_two = {
27
+ user_id: 'user_two',
28
+ client_id: 'client_two',
29
+ connected_at: nowLess5minutes,
30
+ sdk: 'powersync-js/1.21.1',
31
+ user_agent: 'powersync-js/1.21.0 powersync-web Chromium/138 linux',
32
+ jwt_exp: nowAdd5minutes
33
+ };
34
+ const user_three = {
35
+ user_id: 'user_three',
36
+ client_id: 'client_three',
37
+ connected_at: yesterday,
38
+ sdk: 'powersync-js/1.21.2',
39
+ user_agent: 'powersync-js/1.21.0 powersync-web Firefox/141 linux',
40
+ disconnected_at: yesterday
41
+ };
42
+ const user_four = {
43
+ user_id: 'user_four',
44
+ client_id: 'client_four',
45
+ connected_at: now,
46
+ sdk: 'powersync-js/1.21.4',
47
+ user_agent: 'powersync-js/1.21.0 powersync-web Firefox/141 linux',
48
+ jwt_exp: nowLess5minutes
49
+ };
50
+ const user_old = {
51
+ user_id: 'user_one',
52
+ client_id: '',
53
+ connected_at: nowLess5minutes,
54
+ sdk: 'unknown',
55
+ user_agent: 'Dart (flutter-web) Chrome/128 android',
56
+ jwt_exp: nowAdd5minutes
57
+ };
58
+ const user_week = {
59
+ user_id: 'user_week',
60
+ client_id: 'client_one',
61
+ connected_at: weekAgo,
62
+ sdk: 'powersync-js/1.24.5',
63
+ user_agent: 'powersync-js/1.21.0 powersync-web Firefox/141 linux',
64
+ disconnected_at: weekAgo
65
+ };
66
+ const user_month = {
67
+ user_id: 'user_month',
68
+ client_id: 'client_month',
69
+ connected_at: monthAgo,
70
+ sdk: 'powersync-js/1.23.6',
71
+ user_agent: 'powersync-js/1.23.0 powersync-web Firefox/141 linux',
72
+ disconnected_at: monthAgo
73
+ };
74
+ const user_expired = {
75
+ user_id: 'user_expired',
76
+ client_id: 'client_expired',
77
+ connected_at: monthAgo,
78
+ sdk: 'powersync-js/1.23.7',
79
+ user_agent: 'powersync-js/1.23.0 powersync-web Firefox/141 linux',
80
+ jwt_exp: monthAgo
81
+ };
82
+ export const REPORT_TEST_USERS = {
83
+ user_one,
84
+ user_two,
85
+ user_three,
86
+ user_four,
87
+ user_old,
88
+ user_week,
89
+ user_month,
90
+ user_expired
91
+ };
92
+ const removeVolatileFields = (connections) => {
93
+ return connections.map((sdk) => {
94
+ const { _id, disconnected_at, connected_at, jwt_exp, ...rest } = sdk;
95
+ return {
96
+ ...rest
97
+ };
98
+ });
99
+ };
100
+ export async function registerReportTests(factory) {
101
+ it('Should show currently connected users', async () => {
102
+ const current = await factory.getConnectedClients();
103
+ expect(current).toMatchSnapshot();
104
+ });
105
+ it('Should show connection report data for user over the past month', async () => {
106
+ const sdk = await factory.getClientConnectionReports({
107
+ start: monthAgo,
108
+ end: now
109
+ });
110
+ expect(sdk).toMatchSnapshot();
111
+ });
112
+ it('Should show connection report data for user over the past week', async () => {
113
+ const sdk = await factory.getClientConnectionReports({
114
+ start: weekAgo,
115
+ end: now
116
+ });
117
+ expect(sdk).toMatchSnapshot();
118
+ });
119
+ it('Should show connection report data for user over the past day', async () => {
120
+ const sdk = await factory.getClientConnectionReports({
121
+ start: dayAgo,
122
+ end: now
123
+ });
124
+ expect(sdk).toMatchSnapshot();
125
+ });
126
+ it('Should show paginated response of all connections of specified client_id', async () => {
127
+ const connections = await factory.getClientConnections({
128
+ client_id: user_two.client_id
129
+ });
130
+ const cleaned = {
131
+ ...connections,
132
+ items: removeVolatileFields(connections.items)
133
+ };
134
+ expect(cleaned).toMatchSnapshot();
135
+ });
136
+ it('Should show paginated response of connections of specified user_id', async () => {
137
+ const connections = await factory.getClientConnections({
138
+ user_id: user_one.user_id
139
+ });
140
+ const cleaned = {
141
+ ...connections,
142
+ items: removeVolatileFields(connections.items)
143
+ };
144
+ expect(cleaned).toMatchSnapshot();
145
+ });
146
+ it('Should show paginated response of connections over a date range', async () => {
147
+ const connections = await factory.getClientConnections({
148
+ date_range: {
149
+ start: weekAgo,
150
+ end: now
151
+ }
152
+ });
153
+ const cleaned = {
154
+ ...connections,
155
+ items: removeVolatileFields(connections.items)
156
+ };
157
+ expect(cleaned).toMatchSnapshot();
158
+ });
159
+ it('Should show paginated response of all connections with a limit', async () => {
160
+ const initial = await factory.getClientConnections({
161
+ limit: 4
162
+ });
163
+ const cursor = initial.cursor;
164
+ expect(cursor).toBeDefined();
165
+ const cleanedInitial = {
166
+ ...initial,
167
+ cursor: '<removed-for-snapshot>',
168
+ items: removeVolatileFields(initial.items)
169
+ };
170
+ expect(cleanedInitial).toMatchSnapshot();
171
+ const connections = await factory.getClientConnections({
172
+ cursor
173
+ });
174
+ const cleaned = {
175
+ ...connections,
176
+ items: removeVolatileFields(initial.items)
177
+ };
178
+ expect(cleaned).toMatchSnapshot();
179
+ });
180
+ }
181
+ //# sourceMappingURL=register-report-tests.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register-report-tests.js","sourceRoot":"","sources":["../../src/tests/register-report-tests.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAEpC,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;AACvB,MAAM,cAAc,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,GAAG,CAAC,QAAQ,EAAE,EAAE,GAAG,CAAC,OAAO,EAAE,EAAE,GAAG,CAAC,QAAQ,EAAE,EAAE,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,CAAC;AACxH,MAAM,eAAe,GAAG,IAAI,IAAI,CAC9B,GAAG,CAAC,WAAW,EAAE,EACjB,GAAG,CAAC,QAAQ,EAAE,EACd,GAAG,CAAC,OAAO,EAAE,EACb,GAAG,CAAC,QAAQ,EAAE,EACd,GAA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ACjD,KAAK,EAAE,CAAC;SACT,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC9B,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;QAE7B,MAAM,cAAc,GAAG;YACrB,GAAG,OAAO;YACV,MAAM,EAAE,wBAAwB;YAChC,KAAK,EAAE,oBAAoB,CAAC,OAAO,CAAC,KAAK,CAAC;SAC3C,CAAC;QACF,MAAM,CAAC,cAAc,CAAC,CAAC,eAAe,EAAE,CAAC;QACzC,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,oBAAoB,CAAC;YACrD,MAAM;SACP,CAAC,CAAC;QAEH,MAAM,OAAO,GAAG;YACd,GAAG,WAAW;YACd,KAAK,EAAE,oBAAoB,CAAC,OAAO,CAAC,KAAK,CAAC;SAC3C,CAAC;QACF,MAAM,CAAC,OAAO,CAAC,CAAC,eAAe,EAAE,CAAC;IACpC,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -6,4 +6,5 @@ export * from './register-data-storage-data-tests.js';
6
6
  export * from './register-data-storage-checkpoint-tests.js';
7
7
  export * from './register-migration-tests.js';
8
8
  export * from './register-sync-tests.js';
9
+ export * from './register-report-tests.js';
9
10
  export * from './util.js';
@@ -6,5 +6,6 @@ export * from './register-data-storage-data-tests.js';
6
6
  export * from './register-data-storage-checkpoint-tests.js';
7
7
  export * from './register-migration-tests.js';
8
8
  export * from './register-sync-tests.js';
9
+ export * from './register-report-tests.js';
9
10
  export * from './util.js';
10
11
  //# sourceMappingURL=tests-index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tests-index.js","sourceRoot":"","sources":["../../src/tests/tests-index.ts"],"names":[],"mappings":"AAAA,cAAc,uCAAuC,CAAC;AACtD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0CAA0C,CAAC;AACzD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,uCAAuC,CAAC;AACtD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0BAA0B,CAAC;AACzC,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"tests-index.js","sourceRoot":"","sources":["../../src/tests/tests-index.ts"],"names":[],"mappings":"AAAA,cAAc,uCAAuC,CAAC;AACtD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0CAA0C,CAAC;AACzD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,uCAAuC,CAAC;AACtD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,+BAA+B,CAAC;AAC9C,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,WAAW,CAAC"}
package/package.json CHANGED
@@ -5,14 +5,14 @@
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
- "version": "0.0.0-dev-20251030082344",
8
+ "version": "0.0.0-dev-20251110113516",
9
9
  "main": "dist/index.js",
10
10
  "license": "FSL-1.1-ALv2",
11
11
  "type": "module",
12
12
  "dependencies": {
13
- "@powersync/service-core": "^0.0.0-dev-20251030082344",
14
- "@powersync/service-jsonbig": "^0.0.0-dev-20251030082344",
15
- "@powersync/service-sync-rules": "^0.0.0-dev-20251030082344"
13
+ "@powersync/service-core": "^0.0.0-dev-20251110113516",
14
+ "@powersync/service-jsonbig": "^0.17.12",
15
+ "@powersync/service-sync-rules": "^0.29.6"
16
16
  },
17
17
  "peerDependencies": {
18
18
  "vite-tsconfig-paths": "^5.1.4",
@@ -0,0 +1,209 @@
1
+ import { storage } from '@powersync/service-core';
2
+ import { expect, it } from 'vitest';
3
+
4
+ const now = new Date();
5
+ const nowAdd5minutes = new Date(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours(), now.getMinutes() + 5);
6
+ const nowLess5minutes = new Date(
7
+ now.getFullYear(),
8
+ now.getMonth(),
9
+ now.getDate(),
10
+ now.getHours(),
11
+ now.getMinutes() - 5
12
+ );
13
+ const dayAgo = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1, now.getHours());
14
+ const yesterday = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1);
15
+ const weekAgo = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 7);
16
+ const monthAgo = new Date(now.getFullYear(), now.getMonth() - 1, now.getDate());
17
+
18
+ export const REPORT_TEST_DATES = {
19
+ now,
20
+ nowAdd5minutes,
21
+ nowLess5minutes,
22
+ dayAgo,
23
+ yesterday,
24
+ weekAgo,
25
+ monthAgo
26
+ };
27
+
28
+ const user_one = {
29
+ user_id: 'user_one',
30
+ client_id: 'client_one',
31
+ connected_at: now,
32
+ sdk: 'powersync-dart/1.6.4',
33
+ user_agent: 'powersync-dart/1.6.4 Dart (flutter-web) Chrome/128 android',
34
+ jwt_exp: nowAdd5minutes
35
+ };
36
+ const user_two = {
37
+ user_id: 'user_two',
38
+ client_id: 'client_two',
39
+ connected_at: nowLess5minutes,
40
+ sdk: 'powersync-js/1.21.1',
41
+ user_agent: 'powersync-js/1.21.0 powersync-web Chromium/138 linux',
42
+ jwt_exp: nowAdd5minutes
43
+ };
44
+ const user_three = {
45
+ user_id: 'user_three',
46
+ client_id: 'client_three',
47
+ connected_at: yesterday,
48
+ sdk: 'powersync-js/1.21.2',
49
+ user_agent: 'powersync-js/1.21.0 powersync-web Firefox/141 linux',
50
+ disconnected_at: yesterday
51
+ };
52
+
53
+ const user_four = {
54
+ user_id: 'user_four',
55
+ client_id: 'client_four',
56
+ connected_at: now,
57
+ sdk: 'powersync-js/1.21.4',
58
+ user_agent: 'powersync-js/1.21.0 powersync-web Firefox/141 linux',
59
+ jwt_exp: nowLess5minutes
60
+ };
61
+
62
+ const user_old = {
63
+ user_id: 'user_one',
64
+ client_id: '',
65
+ connected_at: nowLess5minutes,
66
+ sdk: 'unknown',
67
+ user_agent: 'Dart (flutter-web) Chrome/128 android',
68
+ jwt_exp: nowAdd5minutes
69
+ };
70
+
71
+ const user_week = {
72
+ user_id: 'user_week',
73
+ client_id: 'client_one',
74
+ connected_at: weekAgo,
75
+ sdk: 'powersync-js/1.24.5',
76
+ user_agent: 'powersync-js/1.21.0 powersync-web Firefox/141 linux',
77
+ disconnected_at: weekAgo
78
+ };
79
+
80
+ const user_month = {
81
+ user_id: 'user_month',
82
+ client_id: 'client_month',
83
+ connected_at: monthAgo,
84
+ sdk: 'powersync-js/1.23.6',
85
+ user_agent: 'powersync-js/1.23.0 powersync-web Firefox/141 linux',
86
+ disconnected_at: monthAgo
87
+ };
88
+
89
+ const user_expired = {
90
+ user_id: 'user_expired',
91
+ client_id: 'client_expired',
92
+ connected_at: monthAgo,
93
+ sdk: 'powersync-js/1.23.7',
94
+ user_agent: 'powersync-js/1.23.0 powersync-web Firefox/141 linux',
95
+ jwt_exp: monthAgo
96
+ };
97
+ export const REPORT_TEST_USERS = {
98
+ user_one,
99
+ user_two,
100
+ user_three,
101
+ user_four,
102
+ user_old,
103
+ user_week,
104
+ user_month,
105
+ user_expired
106
+ };
107
+ export type ReportUserData = typeof REPORT_TEST_USERS;
108
+
109
+ type LocalConnection = Partial<typeof user_expired>;
110
+ const removeVolatileFields = <T>(connections: LocalConnection[]) => {
111
+ return connections.map((sdk: Partial<LocalConnection & { _id: string; disconnected_at?: Date }>) => {
112
+ const { _id, disconnected_at, connected_at, jwt_exp, ...rest } = sdk;
113
+ return {
114
+ ...rest
115
+ };
116
+ });
117
+ };
118
+
119
+ export async function registerReportTests(factory: storage.ReportStorage) {
120
+ it('Should show currently connected users', async () => {
121
+ const current = await factory.getConnectedClients();
122
+ expect(current).toMatchSnapshot();
123
+ });
124
+
125
+ it('Should show connection report data for user over the past month', async () => {
126
+ const sdk = await factory.getClientConnectionReports({
127
+ start: monthAgo,
128
+ end: now
129
+ });
130
+ expect(sdk).toMatchSnapshot();
131
+ });
132
+ it('Should show connection report data for user over the past week', async () => {
133
+ const sdk = await factory.getClientConnectionReports({
134
+ start: weekAgo,
135
+ end: now
136
+ });
137
+ expect(sdk).toMatchSnapshot();
138
+ });
139
+ it('Should show connection report data for user over the past day', async () => {
140
+ const sdk = await factory.getClientConnectionReports({
141
+ start: dayAgo,
142
+ end: now
143
+ });
144
+ expect(sdk).toMatchSnapshot();
145
+ });
146
+
147
+ it('Should show paginated response of all connections of specified client_id', async () => {
148
+ const connections = await factory.getClientConnections({
149
+ client_id: user_two.client_id
150
+ });
151
+ const cleaned = {
152
+ ...connections,
153
+ items: removeVolatileFields(connections.items)
154
+ };
155
+ expect(cleaned).toMatchSnapshot();
156
+ });
157
+
158
+ it('Should show paginated response of connections of specified user_id', async () => {
159
+ const connections = await factory.getClientConnections({
160
+ user_id: user_one.user_id
161
+ });
162
+
163
+ const cleaned = {
164
+ ...connections,
165
+ items: removeVolatileFields(connections.items)
166
+ };
167
+ expect(cleaned).toMatchSnapshot();
168
+ });
169
+
170
+ it('Should show paginated response of connections over a date range', async () => {
171
+ const connections = await factory.getClientConnections({
172
+ date_range: {
173
+ start: weekAgo,
174
+ end: now
175
+ }
176
+ });
177
+
178
+ const cleaned = {
179
+ ...connections,
180
+ items: removeVolatileFields(connections.items)
181
+ };
182
+ expect(cleaned).toMatchSnapshot();
183
+ });
184
+
185
+ it('Should show paginated response of all connections with a limit', async () => {
186
+ const initial = await factory.getClientConnections({
187
+ limit: 4
188
+ });
189
+
190
+ const cursor = initial.cursor;
191
+ expect(cursor).toBeDefined();
192
+
193
+ const cleanedInitial = {
194
+ ...initial,
195
+ cursor: '<removed-for-snapshot>',
196
+ items: removeVolatileFields(initial.items)
197
+ };
198
+ expect(cleanedInitial).toMatchSnapshot();
199
+ const connections = await factory.getClientConnections({
200
+ cursor
201
+ });
202
+
203
+ const cleaned = {
204
+ ...connections,
205
+ items: removeVolatileFields(initial.items)
206
+ };
207
+ expect(cleaned).toMatchSnapshot();
208
+ });
209
+ }
@@ -6,4 +6,5 @@ export * from './register-data-storage-data-tests.js';
6
6
  export * from './register-data-storage-checkpoint-tests.js';
7
7
  export * from './register-migration-tests.js';
8
8
  export * from './register-sync-tests.js';
9
+ export * from './register-report-tests.js';
9
10
  export * from './util.js';