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