@backstage/backend-test-utils 0.4.5-next.3 → 0.5.1
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 +40 -0
- package/dist/index.cjs.js +14 -31
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +119 -144
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -4,11 +4,127 @@ import Keyv from 'keyv';
|
|
|
4
4
|
import { Knex } from 'knex';
|
|
5
5
|
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
6
6
|
import { ServiceFactory, ServiceRef, ExtensionPoint, BackendFeature, RootConfigService, LoggerService, TokenManagerService, IdentityService, AuthService, DiscoveryService, BackstageCredentials, HttpAuthService, BackstageUserInfo, UserInfoService, BackstageNonePrincipal, BackstageUserPrincipal, BackstagePrincipalAccessRestrictions, BackstageServicePrincipal } from '@backstage/backend-plugin-api';
|
|
7
|
-
import { Backend
|
|
8
|
-
import * as _backstage_plugin_events_node from '@backstage/plugin-events-node';
|
|
7
|
+
import { Backend } from '@backstage/backend-app-api';
|
|
9
8
|
import * as _backstage_backend_defaults_rootHttpRouter from '@backstage/backend-defaults/rootHttpRouter';
|
|
9
|
+
import { ExtendedHttpServer } from '@backstage/backend-defaults/rootHttpRouter';
|
|
10
|
+
import * as _backstage_plugin_events_node from '@backstage/plugin-events-node';
|
|
10
11
|
import { JsonObject } from '@backstage/types';
|
|
11
12
|
|
|
13
|
+
/**
|
|
14
|
+
* The possible caches to test against.
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
type TestCacheId = 'MEMORY' | 'REDIS_7' | 'MEMCACHED_1';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Encapsulates the creation of ephemeral test cache instances for use inside
|
|
22
|
+
* unit or integration tests.
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
declare class TestCaches {
|
|
27
|
+
private readonly instanceById;
|
|
28
|
+
private readonly supportedIds;
|
|
29
|
+
private static defaultIds?;
|
|
30
|
+
/**
|
|
31
|
+
* Creates an empty `TestCaches` instance, and sets up Jest to clean up all of
|
|
32
|
+
* its acquired resources after all tests finish.
|
|
33
|
+
*
|
|
34
|
+
* You typically want to create just a single instance like this at the top of
|
|
35
|
+
* your test file or `describe` block, and then call `init` many times on that
|
|
36
|
+
* instance inside the individual tests. Spinning up a "physical" cache
|
|
37
|
+
* instance takes a considerable amount of time, slowing down tests. But
|
|
38
|
+
* wiping the contents of an instance using `init` is very fast.
|
|
39
|
+
*/
|
|
40
|
+
static create(options?: {
|
|
41
|
+
ids?: TestCacheId[];
|
|
42
|
+
disableDocker?: boolean;
|
|
43
|
+
}): TestCaches;
|
|
44
|
+
static setDefaults(options: {
|
|
45
|
+
ids?: TestCacheId[];
|
|
46
|
+
}): void;
|
|
47
|
+
private constructor();
|
|
48
|
+
supports(id: TestCacheId): boolean;
|
|
49
|
+
eachSupportedId(): [TestCacheId][];
|
|
50
|
+
/**
|
|
51
|
+
* Returns a fresh, empty cache for the given driver.
|
|
52
|
+
*
|
|
53
|
+
* @param id - The ID of the cache to use, e.g. 'REDIS_7'
|
|
54
|
+
* @returns Cache connection properties
|
|
55
|
+
*/
|
|
56
|
+
init(id: TestCacheId): Promise<{
|
|
57
|
+
store: string;
|
|
58
|
+
connection: string;
|
|
59
|
+
keyv: Keyv;
|
|
60
|
+
}>;
|
|
61
|
+
private initAny;
|
|
62
|
+
private initMemcached;
|
|
63
|
+
private initRedis;
|
|
64
|
+
private shutdown;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The possible databases to test against.
|
|
69
|
+
*
|
|
70
|
+
* @public
|
|
71
|
+
*/
|
|
72
|
+
type TestDatabaseId = 'POSTGRES_16' | 'POSTGRES_15' | 'POSTGRES_14' | 'POSTGRES_13' | 'POSTGRES_12' | 'POSTGRES_11' | 'POSTGRES_9' | 'MYSQL_8' | 'SQLITE_3';
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Encapsulates the creation of ephemeral test database instances for use
|
|
76
|
+
* inside unit or integration tests.
|
|
77
|
+
*
|
|
78
|
+
* @public
|
|
79
|
+
*/
|
|
80
|
+
declare class TestDatabases {
|
|
81
|
+
private readonly engineFactoryByDriver;
|
|
82
|
+
private readonly engineByTestDatabaseId;
|
|
83
|
+
private readonly supportedIds;
|
|
84
|
+
private static defaultIds?;
|
|
85
|
+
/**
|
|
86
|
+
* Creates an empty `TestDatabases` instance, and sets up Jest to clean up
|
|
87
|
+
* all of its acquired resources after all tests finish.
|
|
88
|
+
*
|
|
89
|
+
* You typically want to create just a single instance like this at the top
|
|
90
|
+
* of your test file or `describe` block, and then call `init` many times on
|
|
91
|
+
* that instance inside the individual tests. Spinning up a "physical"
|
|
92
|
+
* database instance takes a considerable amount of time, slowing down tests.
|
|
93
|
+
* But initializing a new logical database inside that instance using `init`
|
|
94
|
+
* is very fast.
|
|
95
|
+
*/
|
|
96
|
+
static create(options?: {
|
|
97
|
+
ids?: TestDatabaseId[];
|
|
98
|
+
disableDocker?: boolean;
|
|
99
|
+
}): TestDatabases;
|
|
100
|
+
static setDefaults(options: {
|
|
101
|
+
ids?: TestDatabaseId[];
|
|
102
|
+
}): void;
|
|
103
|
+
private constructor();
|
|
104
|
+
supports(id: TestDatabaseId): boolean;
|
|
105
|
+
eachSupportedId(): [TestDatabaseId][];
|
|
106
|
+
/**
|
|
107
|
+
* Returns a fresh, unique, empty logical database on an instance of the
|
|
108
|
+
* given database ID platform.
|
|
109
|
+
*
|
|
110
|
+
* @param id - The ID of the database platform to use, e.g. 'POSTGRES_13'
|
|
111
|
+
* @returns A `Knex` connection object
|
|
112
|
+
*/
|
|
113
|
+
init(id: TestDatabaseId): Promise<Knex>;
|
|
114
|
+
private shutdown;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Sets up handlers for request mocking
|
|
119
|
+
* @public
|
|
120
|
+
* @param worker - service worker
|
|
121
|
+
*/
|
|
122
|
+
declare function registerMswTestHooks(worker: {
|
|
123
|
+
listen: (t: any) => void;
|
|
124
|
+
close: () => void;
|
|
125
|
+
resetHandlers: () => void;
|
|
126
|
+
}): void;
|
|
127
|
+
|
|
12
128
|
/**
|
|
13
129
|
* A context that allows for more advanced file system operations when writing mock directory content.
|
|
14
130
|
*
|
|
@@ -195,141 +311,6 @@ interface CreateMockDirectoryOptions {
|
|
|
195
311
|
*/
|
|
196
312
|
declare function createMockDirectory(options?: CreateMockDirectoryOptions): MockDirectory;
|
|
197
313
|
|
|
198
|
-
/**
|
|
199
|
-
* @public
|
|
200
|
-
* @deprecated Use `CreateMockDirectoryOptions` from `@backstage/backend-test-utils` instead.
|
|
201
|
-
*/
|
|
202
|
-
type MockDirectoryOptions = CreateMockDirectoryOptions;
|
|
203
|
-
/**
|
|
204
|
-
* @public
|
|
205
|
-
* @deprecated Use `registerMswTestHooks` from `@backstage/backend-test-utils` instead.
|
|
206
|
-
*/
|
|
207
|
-
declare function setupRequestMockHandlers(worker: {
|
|
208
|
-
listen: (t: any) => void;
|
|
209
|
-
close: () => void;
|
|
210
|
-
resetHandlers: () => void;
|
|
211
|
-
}): void;
|
|
212
|
-
/**
|
|
213
|
-
* @public
|
|
214
|
-
* @deprecated This is an internal function and will no longer be exported from this package.
|
|
215
|
-
*/
|
|
216
|
-
declare function isDockerDisabledForTests(): boolean;
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* The possible caches to test against.
|
|
220
|
-
*
|
|
221
|
-
* @public
|
|
222
|
-
*/
|
|
223
|
-
type TestCacheId = 'MEMORY' | 'REDIS_7' | 'MEMCACHED_1';
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Encapsulates the creation of ephemeral test cache instances for use inside
|
|
227
|
-
* unit or integration tests.
|
|
228
|
-
*
|
|
229
|
-
* @public
|
|
230
|
-
*/
|
|
231
|
-
declare class TestCaches {
|
|
232
|
-
private readonly instanceById;
|
|
233
|
-
private readonly supportedIds;
|
|
234
|
-
private static defaultIds?;
|
|
235
|
-
/**
|
|
236
|
-
* Creates an empty `TestCaches` instance, and sets up Jest to clean up all of
|
|
237
|
-
* its acquired resources after all tests finish.
|
|
238
|
-
*
|
|
239
|
-
* You typically want to create just a single instance like this at the top of
|
|
240
|
-
* your test file or `describe` block, and then call `init` many times on that
|
|
241
|
-
* instance inside the individual tests. Spinning up a "physical" cache
|
|
242
|
-
* instance takes a considerable amount of time, slowing down tests. But
|
|
243
|
-
* wiping the contents of an instance using `init` is very fast.
|
|
244
|
-
*/
|
|
245
|
-
static create(options?: {
|
|
246
|
-
ids?: TestCacheId[];
|
|
247
|
-
disableDocker?: boolean;
|
|
248
|
-
}): TestCaches;
|
|
249
|
-
static setDefaults(options: {
|
|
250
|
-
ids?: TestCacheId[];
|
|
251
|
-
}): void;
|
|
252
|
-
private constructor();
|
|
253
|
-
supports(id: TestCacheId): boolean;
|
|
254
|
-
eachSupportedId(): [TestCacheId][];
|
|
255
|
-
/**
|
|
256
|
-
* Returns a fresh, empty cache for the given driver.
|
|
257
|
-
*
|
|
258
|
-
* @param id - The ID of the cache to use, e.g. 'REDIS_7'
|
|
259
|
-
* @returns Cache connection properties
|
|
260
|
-
*/
|
|
261
|
-
init(id: TestCacheId): Promise<{
|
|
262
|
-
store: string;
|
|
263
|
-
connection: string;
|
|
264
|
-
keyv: Keyv;
|
|
265
|
-
}>;
|
|
266
|
-
private initAny;
|
|
267
|
-
private initMemcached;
|
|
268
|
-
private initRedis;
|
|
269
|
-
private shutdown;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* The possible databases to test against.
|
|
274
|
-
*
|
|
275
|
-
* @public
|
|
276
|
-
*/
|
|
277
|
-
type TestDatabaseId = 'POSTGRES_16' | 'POSTGRES_15' | 'POSTGRES_14' | 'POSTGRES_13' | 'POSTGRES_12' | 'POSTGRES_11' | 'POSTGRES_9' | 'MYSQL_8' | 'SQLITE_3';
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* Encapsulates the creation of ephemeral test database instances for use
|
|
281
|
-
* inside unit or integration tests.
|
|
282
|
-
*
|
|
283
|
-
* @public
|
|
284
|
-
*/
|
|
285
|
-
declare class TestDatabases {
|
|
286
|
-
private readonly engineFactoryByDriver;
|
|
287
|
-
private readonly engineByTestDatabaseId;
|
|
288
|
-
private readonly supportedIds;
|
|
289
|
-
private static defaultIds?;
|
|
290
|
-
/**
|
|
291
|
-
* Creates an empty `TestDatabases` instance, and sets up Jest to clean up
|
|
292
|
-
* all of its acquired resources after all tests finish.
|
|
293
|
-
*
|
|
294
|
-
* You typically want to create just a single instance like this at the top
|
|
295
|
-
* of your test file or `describe` block, and then call `init` many times on
|
|
296
|
-
* that instance inside the individual tests. Spinning up a "physical"
|
|
297
|
-
* database instance takes a considerable amount of time, slowing down tests.
|
|
298
|
-
* But initializing a new logical database inside that instance using `init`
|
|
299
|
-
* is very fast.
|
|
300
|
-
*/
|
|
301
|
-
static create(options?: {
|
|
302
|
-
ids?: TestDatabaseId[];
|
|
303
|
-
disableDocker?: boolean;
|
|
304
|
-
}): TestDatabases;
|
|
305
|
-
static setDefaults(options: {
|
|
306
|
-
ids?: TestDatabaseId[];
|
|
307
|
-
}): void;
|
|
308
|
-
private constructor();
|
|
309
|
-
supports(id: TestDatabaseId): boolean;
|
|
310
|
-
eachSupportedId(): [TestDatabaseId][];
|
|
311
|
-
/**
|
|
312
|
-
* Returns a fresh, unique, empty logical database on an instance of the
|
|
313
|
-
* given database ID platform.
|
|
314
|
-
*
|
|
315
|
-
* @param id - The ID of the database platform to use, e.g. 'POSTGRES_13'
|
|
316
|
-
* @returns A `Knex` connection object
|
|
317
|
-
*/
|
|
318
|
-
init(id: TestDatabaseId): Promise<Knex>;
|
|
319
|
-
private shutdown;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* Sets up handlers for request mocking
|
|
324
|
-
* @public
|
|
325
|
-
* @param worker - service worker
|
|
326
|
-
*/
|
|
327
|
-
declare function registerMswTestHooks(worker: {
|
|
328
|
-
listen: (t: any) => void;
|
|
329
|
-
close: () => void;
|
|
330
|
-
resetHandlers: () => void;
|
|
331
|
-
}): void;
|
|
332
|
-
|
|
333
314
|
/**
|
|
334
315
|
* Options for {@link ServiceFactoryTester}.
|
|
335
316
|
* @public
|
|
@@ -361,12 +342,6 @@ declare class ServiceFactoryTester<TService, TScope extends 'root' | 'plugin', T
|
|
|
361
342
|
*/
|
|
362
343
|
static from<TService, TScope extends 'root' | 'plugin', TInstances extends 'singleton' | 'multiton' = 'singleton'>(subject: ServiceFactory<TService, TScope, TInstances>, options?: ServiceFactoryTesterOptions): ServiceFactoryTester<TService, TScope, TInstances>;
|
|
363
344
|
private constructor();
|
|
364
|
-
/**
|
|
365
|
-
* Returns the service instance for the subject.
|
|
366
|
-
*
|
|
367
|
-
* @deprecated Use `getSubject` instead.
|
|
368
|
-
*/
|
|
369
|
-
get(...args: 'root' extends TScope ? [] : [pluginId?: string]): Promise<TInstances extends 'multiton' ? TService[] : TService>;
|
|
370
345
|
/**
|
|
371
346
|
* Returns the service instance for the subject.
|
|
372
347
|
*
|
|
@@ -669,4 +644,4 @@ declare namespace mockCredentials {
|
|
|
669
644
|
}
|
|
670
645
|
}
|
|
671
646
|
|
|
672
|
-
export { type CreateMockDirectoryOptions, type MockDirectory, type MockDirectoryContent, type MockDirectoryContentCallback, type MockDirectoryContentCallbackContext, type MockDirectoryContentOptions,
|
|
647
|
+
export { type CreateMockDirectoryOptions, type MockDirectory, type MockDirectoryContent, type MockDirectoryContentCallback, type MockDirectoryContentCallbackContext, type MockDirectoryContentOptions, ServiceFactoryTester, type ServiceFactoryTesterOptions, type ServiceMock, type TestBackend, type TestBackendOptions, type TestCacheId, TestCaches, type TestDatabaseId, TestDatabases, createMockDirectory, mockCredentials, mockServices, registerMswTestHooks, startTestBackend };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/backend-test-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Test helpers library for Backstage backends",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "node-library"
|
|
@@ -42,13 +42,13 @@
|
|
|
42
42
|
"test": "backstage-cli package test"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@backstage/backend-app-api": "^0.
|
|
46
|
-
"@backstage/backend-defaults": "^0.4.
|
|
47
|
-
"@backstage/backend-plugin-api": "^0.8.
|
|
45
|
+
"@backstage/backend-app-api": "^0.9.3",
|
|
46
|
+
"@backstage/backend-defaults": "^0.4.4",
|
|
47
|
+
"@backstage/backend-plugin-api": "^0.8.1",
|
|
48
48
|
"@backstage/config": "^1.2.0",
|
|
49
49
|
"@backstage/errors": "^1.2.4",
|
|
50
|
-
"@backstage/plugin-auth-node": "^0.5.
|
|
51
|
-
"@backstage/plugin-events-node": "^0.3.
|
|
50
|
+
"@backstage/plugin-auth-node": "^0.5.1",
|
|
51
|
+
"@backstage/plugin-events-node": "^0.3.10",
|
|
52
52
|
"@backstage/types": "^1.1.1",
|
|
53
53
|
"@keyv/memcache": "^1.3.5",
|
|
54
54
|
"@keyv/redis": "^2.5.3",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"yn": "^4.0.0"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
|
-
"@backstage/cli": "^0.27.0
|
|
72
|
+
"@backstage/cli": "^0.27.0",
|
|
73
73
|
"@types/supertest": "^2.0.8",
|
|
74
74
|
"supertest": "^6.1.3"
|
|
75
75
|
},
|