@backstage/backend-test-utils 0.3.9-next.0 → 0.4.0-next.2
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 +30 -0
- package/dist/index.cjs.js +608 -207
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +63 -11
- package/package.json +13 -8
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,67 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="jest" />
|
|
3
|
+
import Keyv from 'keyv';
|
|
3
4
|
import { Knex } from 'knex';
|
|
4
5
|
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
5
|
-
import { ServiceFactory, ServiceRef, ExtensionPoint, BackendFeature, RootConfigService, LoggerService, TokenManagerService, IdentityService, AuthService, DiscoveryService, BackstageCredentials, HttpAuthService, BackstageUserInfo, UserInfoService, BackstageNonePrincipal, BackstageUserPrincipal, BackstageServicePrincipal } from '@backstage/backend-plugin-api';
|
|
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';
|
|
6
7
|
import * as _backstage_backend_app_api from '@backstage/backend-app-api';
|
|
7
8
|
import { Backend, ExtendedHttpServer } from '@backstage/backend-app-api';
|
|
8
9
|
import * as _backstage_plugin_events_node from '@backstage/plugin-events-node';
|
|
9
10
|
import { JsonObject } from '@backstage/types';
|
|
10
11
|
|
|
11
|
-
/**
|
|
12
|
-
|
|
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
|
+
}
|
|
13
65
|
|
|
14
66
|
/**
|
|
15
67
|
* The possible databases to test against.
|
|
@@ -25,7 +77,8 @@ type TestDatabaseId = 'POSTGRES_16' | 'POSTGRES_15' | 'POSTGRES_14' | 'POSTGRES_
|
|
|
25
77
|
* @public
|
|
26
78
|
*/
|
|
27
79
|
declare class TestDatabases {
|
|
28
|
-
private readonly
|
|
80
|
+
private readonly engineFactoryByDriver;
|
|
81
|
+
private readonly engineByTestDatabaseId;
|
|
29
82
|
private readonly supportedIds;
|
|
30
83
|
private static defaultIds?;
|
|
31
84
|
/**
|
|
@@ -57,10 +110,6 @@ declare class TestDatabases {
|
|
|
57
110
|
* @returns A `Knex` connection object
|
|
58
111
|
*/
|
|
59
112
|
init(id: TestDatabaseId): Promise<Knex>;
|
|
60
|
-
private initAny;
|
|
61
|
-
private initPostgres;
|
|
62
|
-
private initMysql;
|
|
63
|
-
private initSqlite;
|
|
64
113
|
private shutdown;
|
|
65
114
|
}
|
|
66
115
|
|
|
@@ -559,9 +608,9 @@ declare namespace mockCredentials {
|
|
|
559
608
|
/**
|
|
560
609
|
* Creates a mocked credentials object for a service principal.
|
|
561
610
|
*
|
|
562
|
-
* The default subject is 'external:test-service'.
|
|
611
|
+
* The default subject is 'external:test-service', and no access restrictions.
|
|
563
612
|
*/
|
|
564
|
-
function service(subject?: string): BackstageCredentials<BackstageServicePrincipal>;
|
|
613
|
+
function service(subject?: string, accessRestrictions?: BackstagePrincipalAccessRestrictions): BackstageCredentials<BackstageServicePrincipal>;
|
|
565
614
|
/**
|
|
566
615
|
* Utilities related to service credentials.
|
|
567
616
|
*/
|
|
@@ -590,4 +639,7 @@ declare namespace mockCredentials {
|
|
|
590
639
|
}
|
|
591
640
|
}
|
|
592
641
|
|
|
593
|
-
|
|
642
|
+
/** @public */
|
|
643
|
+
declare function isDockerDisabledForTests(): boolean;
|
|
644
|
+
|
|
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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/backend-test-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0-next.2",
|
|
4
4
|
"description": "Test helpers library for Backstage backends",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "node-library"
|
|
@@ -42,28 +42,33 @@
|
|
|
42
42
|
"test": "backstage-cli package test"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@backstage/backend-app-api": "^0.7.6-next.
|
|
46
|
-
"@backstage/backend-
|
|
47
|
-
"@backstage/backend-plugin-api": "^0.6.19-next.0",
|
|
45
|
+
"@backstage/backend-app-api": "^0.7.6-next.2",
|
|
46
|
+
"@backstage/backend-plugin-api": "^0.6.19-next.2",
|
|
48
47
|
"@backstage/config": "^1.2.0",
|
|
49
48
|
"@backstage/errors": "^1.2.4",
|
|
50
|
-
"@backstage/plugin-auth-node": "^0.4.14-next.
|
|
51
|
-
"@backstage/plugin-events-node": "^0.3.5-next.
|
|
49
|
+
"@backstage/plugin-auth-node": "^0.4.14-next.2",
|
|
50
|
+
"@backstage/plugin-events-node": "^0.3.5-next.1",
|
|
52
51
|
"@backstage/types": "^1.1.1",
|
|
52
|
+
"@keyv/memcache": "^1.3.5",
|
|
53
|
+
"@keyv/redis": "^2.5.3",
|
|
54
|
+
"@types/keyv": "^4.2.0",
|
|
53
55
|
"better-sqlite3": "^9.0.0",
|
|
54
56
|
"cookie": "^0.6.0",
|
|
55
57
|
"express": "^4.17.1",
|
|
56
58
|
"fs-extra": "^11.0.0",
|
|
59
|
+
"keyv": "^4.5.2",
|
|
57
60
|
"knex": "^3.0.0",
|
|
58
61
|
"msw": "^1.0.0",
|
|
59
62
|
"mysql2": "^3.0.0",
|
|
60
63
|
"pg": "^8.11.3",
|
|
64
|
+
"pg-connection-string": "^2.3.0",
|
|
61
65
|
"testcontainers": "^10.0.0",
|
|
62
66
|
"textextensions": "^5.16.0",
|
|
63
|
-
"uuid": "^9.0.0"
|
|
67
|
+
"uuid": "^9.0.0",
|
|
68
|
+
"yn": "^4.0.0"
|
|
64
69
|
},
|
|
65
70
|
"devDependencies": {
|
|
66
|
-
"@backstage/cli": "^0.26.
|
|
71
|
+
"@backstage/cli": "^0.26.7-next.2",
|
|
67
72
|
"@types/supertest": "^2.0.8",
|
|
68
73
|
"supertest": "^6.1.3"
|
|
69
74
|
},
|