Fix another static version snapshot in tests (#141345)

* Fix another static version snapshot in tests

* switch import order

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Pierre Gayvallet 2022-09-23 09:19:27 +02:00 committed by GitHub
parent a9908dd7eb
commit f3a3243d00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 48 additions and 24 deletions

View file

@ -7,41 +7,37 @@
*/
import { firstValueFrom, Observable } from 'rxjs';
import { createTestEnv, createTestPackageInfo } from '@kbn/config-mocks';
import { mockCoreContext } from '@kbn/core-base-server-mocks';
import { analyticsClientMock } from './analytics_service.test.mocks';
import { AnalyticsService } from './analytics_service';
const packageInfo = createTestPackageInfo();
const createCoreContext = () => {
const env = createTestEnv({ packageInfo });
return mockCoreContext.create({ env });
};
describe('AnalyticsService', () => {
let analyticsService: AnalyticsService;
beforeEach(() => {
jest.clearAllMocks();
analyticsService = new AnalyticsService(mockCoreContext.create());
analyticsService = new AnalyticsService(createCoreContext());
});
test('should register the context provider `build info` on creation', async () => {
expect(analyticsClientMock.registerContextProvider).toHaveBeenCalledTimes(1);
await expect(
await firstValueFrom(analyticsClientMock.registerContextProvider.mock.calls[0][0].context$)
).toMatchInlineSnapshot(
{
branch: expect.any(String),
buildNum: 9007199254740991,
buildSha: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
isDev: true,
isDistributable: false,
version: expect.any(String),
},
`
Object {
"branch": Any<String>,
"buildNum": 9007199254740991,
"buildSha": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"isDev": true,
"isDistributable": false,
"version": Any<String>,
}
`
);
).toEqual({
branch: packageInfo.branch,
version: packageInfo.version,
buildNum: packageInfo.build.number,
buildSha: packageInfo.build.sha,
isDev: expect.any(Boolean),
isDistributable: packageInfo.build.distributable,
});
});
test('should register the `performance_metric` event type on creation', () => {

View file

@ -6,6 +6,8 @@
* Side Public License, v 1.
*/
import { getDeprecationsFor } from '@kbn/core-test-helpers-deprecations-getters';
import {
mockReadFileSync,
mockReadPkcs12Keystore,
@ -13,7 +15,6 @@ import {
} from './elasticsearch_config.test.mocks';
import { ElasticsearchConfig, config } from './elasticsearch_config';
import { getDeprecationsFor } from '@kbn/core-test-helpers-deprecations-getters';
const CONFIG_PATH = 'elasticsearch';

View file

@ -36,12 +36,14 @@ NPM_MODULE_EXTRA_FILES = [
RUNTIME_DEPS = [
"//packages/kbn-config",
"//packages/kbn-utils",
]
TYPES_DEPS = [
"@npm//rxjs",
"@npm//@types/node",
"@npm//@types/jest",
"//packages/kbn-utils:npm_module_types",
"//packages/kbn-config:npm_module_types",
"//packages/kbn-utility-types:npm_module_types",
]

View file

@ -18,4 +18,4 @@ export type { IConfigServiceMock } from './src/config_service.mock';
export { configDeprecationsMock } from './src/deprecations.mock';
export type { ConfigDeprecationContextMock } from './src/deprecations.mock';
export { getEnvOptions } from './src/env.mock';
export { createTestEnv, getEnvOptions, createTestPackageInfo } from './src/env.mock';

View file

@ -6,7 +6,8 @@
* Side Public License, v 1.
*/
import type { EnvOptions } from '@kbn/config';
import { REPO_ROOT } from '@kbn/utils';
import { Env, type RawPackageInfo, type EnvOptions } from '@kbn/config';
type DeepPartial<T> = {
[P in keyof T]?: T[P] extends Array<infer R> ? Array<DeepPartial<R>> : DeepPartial<T[P]>;
@ -29,3 +30,27 @@ export function getEnvOptions(options: DeepPartial<EnvOptions> = {}): EnvOptions
},
};
}
export const createTestPackageInfo = ({ dist = true }: { dist?: boolean } = {}): RawPackageInfo => {
return {
branch: 'test-branch',
version: '8.66-test',
build: {
distributable: dist,
number: 123456789,
sha: 'XXXXXX',
},
};
};
export const createTestEnv = ({
repoRoot = REPO_ROOT,
envOptions = getEnvOptions(),
packageInfo = createTestPackageInfo(),
}: {
repoRoot?: string;
envOptions?: EnvOptions;
packageInfo?: RawPackageInfo;
} = {}) => {
return Env.createDefault(repoRoot, envOptions, packageInfo);
};