Skip to content

Commit

Permalink
adapt plugin service mock
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Sep 15, 2020
1 parent fe0fcc5 commit c80dd02
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/core/server/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export async function bootstrap({
// and as `REPO_ROOT` is initialized on the fly when importing `dev-utils` and requires
// the `fs` package, it causes failures. This is why we use a dynamic `require` here.
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { REPO_ROOT } = require('@kbn/dev-utils');
const { REPO_ROOT } = require('@kbn/utils');

const env = Env.createDefault(REPO_ROOT, {
configs,
Expand Down
16 changes: 14 additions & 2 deletions src/core/server/plugins/plugins_service.test.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,24 @@
* under the License.
*/

import { REPO_ROOT } from '@kbn/utils';
import { resolve } from 'path';

const loadJsonFile = jest.requireActual('load-json-file');
const kibanaPackagePath = resolve(REPO_ROOT, 'package.json');

export const mockPackage = {
raw: { __dirname: '/tmp' } as any,
raw: { __dirname: '/tmp', name: 'kibana' } as any,
};

jest.doMock('load-json-file', () => ({
sync: () => mockPackage.raw,
...loadJsonFile,
sync: (path: string) => {
if (path === kibanaPackagePath) {
return mockPackage.raw;
}
return loadJsonFile.sync(path);
},
}));

export const mockDiscover = jest.fn();
Expand Down
3 changes: 1 addition & 2 deletions src/core/server/plugins/plugins_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
* under the License.
*/

// must be before mocks imports to avoid conflicting with `REPO_ROOT` accessor.
import { createAbsolutePathSerializer, REPO_ROOT } from '@kbn/dev-utils';
import { mockDiscover, mockPackage } from './plugins_service.test.mocks';

import { resolve, join } from 'path';
import { BehaviorSubject, from } from 'rxjs';
import { schema } from '@kbn/config-schema';
import { createAbsolutePathSerializer, REPO_ROOT } from '@kbn/dev-utils';

import { ConfigPath, ConfigService, Env } from '../config';
import { rawConfigServiceMock, getEnvOptions } from '../config/mocks';
Expand Down

0 comments on commit c80dd02

Please sign in to comment.