[deps] Replace faker with @faker-js (#201105)

## Summary

The `faker` library is[ not maintained
anymore](https://fakerjs.dev/about/announcements/2022-01-14.html#i-heard-something-happened-what-s-the-tldr)
and is replaced by a community fork `@faker-js`.
This PR migrates all the usages of faker to the new library, trying to
use the same methods (even if they have slight differences in results
like `faker.random.number()` has a max of 99999 where instead
`faker.number.int()` have a MAX_SAFE_INTEGER as max).
This commit is contained in:
Marco Vettorello 2024-12-03 18:17:49 +01:00 committed by GitHub
parent 230d6617ab
commit b61ad41284
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
31 changed files with 122 additions and 130 deletions

View file

@ -1572,7 +1572,6 @@
"@types/eslint": "^8.44.2",
"@types/express": "^4.17.21",
"@types/extract-zip": "^1.6.2",
"@types/faker": "^5.1.5",
"@types/fetch-mock": "^7.3.1",
"@types/file-saver": "^2.0.0",
"@types/flot": "^0.0.31",
@ -1741,7 +1740,6 @@
"expect": "^29.7.0",
"expose-loader": "^0.7.5",
"express": "^4.21.1",
"faker": "^5.1.0",
"fetch-mock": "^7.3.9",
"file-loader": "^4.2.0",
"find-cypress-specs": "^1.41.4",

View file

@ -9,24 +9,22 @@
import { calculateWidthFromEntries } from './calculate_width_from_entries';
import { MAX_WIDTH } from './calculate_width_from_char_count';
import faker from 'faker';
const generateLabel = (length: number) => faker.random.alpha({ count: length });
import { faker } from '@faker-js/faker';
const generateObjectWithLabelOfLength = (length: number, propOverrides?: Record<string, any>) => ({
label: generateLabel(length),
label: faker.string.alpha(length),
...propOverrides,
});
describe('calculateWidthFromEntries', () => {
it('calculates width for array of strings', () => {
const shortLabels = [10, 20].map(generateLabel);
const shortLabels = [10, 20].map(faker.string.alpha);
expect(calculateWidthFromEntries(shortLabels)).toBe(256);
const mediumLabels = [50, 55, 10, 20].map(generateLabel);
const mediumLabels = [50, 55, 10, 20].map(faker.string.alpha);
expect(calculateWidthFromEntries(mediumLabels)).toBe(501);
const longLabels = [80, 90, 10].map(generateLabel);
const longLabels = [80, 90, 10].map(faker.string.alpha);
expect(calculateWidthFromEntries(longLabels)).toBe(MAX_WIDTH);
});
@ -42,12 +40,12 @@ describe('calculateWidthFromEntries', () => {
});
it('calculates width for array of objects for fallback keys', () => {
const shortLabels = [10, 20].map((v) =>
generateObjectWithLabelOfLength(v, { label: undefined, name: generateLabel(v) })
generateObjectWithLabelOfLength(v, { label: undefined, name: faker.string.alpha(v) })
);
expect(calculateWidthFromEntries(shortLabels, ['id', 'label', 'name'])).toBe(256);
const mediumLabels = [50, 55, 10, 20].map((v) =>
generateObjectWithLabelOfLength(v, { label: undefined, name: generateLabel(v) })
generateObjectWithLabelOfLength(v, { label: undefined, name: faker.string.alpha(v) })
);
expect(calculateWidthFromEntries(mediumLabels, ['id', 'label', 'name'])).toBe(501);
});

View file

@ -8,7 +8,7 @@
*/
import React, { ReactElement } from 'react';
import faker from 'faker';
import { faker } from '@faker-js/faker';
import { RenderOptions, render } from '@testing-library/react';
import { DragContextState, RootDragDropProvider } from './providers';
@ -22,7 +22,7 @@ export const dataTransfer = {
};
export const generateDragDropValue = (label = faker.lorem.word()) => ({
id: faker.random.uuid(),
id: faker.string.uuid(),
humanData: {
label,
groupLabel: faker.lorem.word(),

View file

@ -10,15 +10,15 @@
import React from 'react';
import { FieldPicker, FieldPickerProps } from './field_picker';
import { render, screen } from '@testing-library/react';
import faker from 'faker';
import { faker } from '@faker-js/faker';
import userEvent from '@testing-library/user-event';
import { DataType, FieldOptionValue } from './types';
const generateFieldWithLabelOfLength = (length: number) => ({
label: faker.random.alpha({ count: length }),
label: faker.string.alpha(length),
value: {
type: 'field' as const,
field: faker.random.alpha({ count: length }),
field: faker.string.alpha(length),
dataType: 'date' as DataType,
operationType: 'count',
},

View file

@ -27,7 +27,7 @@ import { CustomPaletteState } from '@kbn/charts-plugin/common/expressions/palett
import { DimensionsVisParam, MetricVisParam } from '../../common';
import { euiThemeVars } from '@kbn/ui-theme';
import { DEFAULT_TRENDLINE_NAME } from '../../common/constants';
import faker from 'faker';
import { faker } from '@faker-js/faker';
const mockDeserialize = jest.fn(({ id }: { id: string }) => {
const convertFn = (v: unknown) => `${id}-${v}`;
@ -825,47 +825,47 @@ describe('MetricVisComponent', function () {
// Raw values here, not formatted
const trends: Record<string, MetricWTrend['trend']> = {
Friday: [
{ x: faker.random.number(), y: faker.random.number() },
{ x: faker.random.number(), y: faker.random.number() },
{ x: faker.random.number(), y: faker.random.number() },
{ x: faker.random.number(), y: faker.random.number() },
{ x: faker.number.int(), y: faker.number.int() },
{ x: faker.number.int(), y: faker.number.int() },
{ x: faker.number.int(), y: faker.number.int() },
{ x: faker.number.int(), y: faker.number.int() },
],
Wednesday: [
{ x: faker.random.number(), y: faker.random.number() },
{ x: faker.random.number(), y: faker.random.number() },
{ x: faker.random.number(), y: faker.random.number() },
{ x: faker.random.number(), y: faker.random.number() },
{ x: faker.number.int(), y: faker.number.int() },
{ x: faker.number.int(), y: faker.number.int() },
{ x: faker.number.int(), y: faker.number.int() },
{ x: faker.number.int(), y: faker.number.int() },
],
Saturday: [
{ x: faker.random.number(), y: faker.random.number() },
{ x: faker.random.number(), y: faker.random.number() },
{ x: faker.random.number(), y: faker.random.number() },
{ x: faker.random.number(), y: faker.random.number() },
{ x: faker.number.int(), y: faker.number.int() },
{ x: faker.number.int(), y: faker.number.int() },
{ x: faker.number.int(), y: faker.number.int() },
{ x: faker.number.int(), y: faker.number.int() },
],
Sunday: [
{ x: faker.random.number(), y: faker.random.number() },
{ x: faker.random.number(), y: faker.random.number() },
{ x: faker.random.number(), y: faker.random.number() },
{ x: faker.random.number(), y: faker.random.number() },
{ x: faker.number.int(), y: faker.number.int() },
{ x: faker.number.int(), y: faker.number.int() },
{ x: faker.number.int(), y: faker.number.int() },
{ x: faker.number.int(), y: faker.number.int() },
],
Thursday: [
{ x: faker.random.number(), y: faker.random.number() },
{ x: faker.random.number(), y: faker.random.number() },
{ x: faker.random.number(), y: faker.random.number() },
{ x: faker.random.number(), y: faker.random.number() },
{ x: faker.number.int(), y: faker.number.int() },
{ x: faker.number.int(), y: faker.number.int() },
{ x: faker.number.int(), y: faker.number.int() },
{ x: faker.number.int(), y: faker.number.int() },
],
__other__: [
{ x: faker.random.number(), y: faker.random.number() },
{ x: faker.random.number(), y: faker.random.number() },
{ x: faker.random.number(), y: faker.random.number() },
{ x: faker.random.number(), y: faker.random.number() },
{ x: faker.number.int(), y: faker.number.int() },
{ x: faker.number.int(), y: faker.number.int() },
{ x: faker.number.int(), y: faker.number.int() },
{ x: faker.number.int(), y: faker.number.int() },
],
// this one shouldn't show up!
[DEFAULT_TRENDLINE_NAME]: [
{ x: faker.random.number(), y: faker.random.number() },
{ x: faker.random.number(), y: faker.random.number() },
{ x: faker.random.number(), y: faker.random.number() },
{ x: faker.random.number(), y: faker.random.number() },
{ x: faker.number.int(), y: faker.number.int() },
{ x: faker.number.int(), y: faker.number.int() },
{ x: faker.number.int(), y: faker.number.int() },
{ x: faker.number.int(), y: faker.number.int() },
],
};
@ -1004,7 +1004,7 @@ describe('MetricVisComponent', function () {
});
it('should convert null values to NaN', () => {
const metricId = faker.random.word();
const metricId = faker.lorem.word();
const tableWNull: Datatable = {
type: 'datatable',

View file

@ -18,7 +18,7 @@ import {
import { createMockBucketColumns, createMockVisData, createMockPieParams } from '../mocks';
import { consolidateMetricColumns } from '../../common/utils';
import { LayerValue } from '@elastic/charts';
import faker from 'faker';
import { faker } from '@faker-js/faker';
const bucketColumns = createMockBucketColumns();
const visData = createMockVisData();
@ -186,26 +186,26 @@ describe('getFilterClickData', () => {
const clickedLayers: LayerValue[] = [
{
groupByRollup: 'circle',
value: faker.random.number(),
depth: faker.random.number(),
value: faker.number.int(),
depth: faker.number.int(),
path: [],
sortIndex: faker.random.number(),
sortIndex: faker.number.int(),
smAccessorValue: '',
},
{
groupByRollup: 'green',
value: faker.random.number(),
depth: faker.random.number(),
value: faker.number.int(),
depth: faker.number.int(),
path: [],
sortIndex: faker.random.number(),
sortIndex: faker.number.int(),
smAccessorValue: '',
},
{
groupByRollup: 'metric2',
value: faker.random.number(),
depth: faker.random.number(),
value: faker.number.int(),
depth: faker.number.int(),
path: [],
sortIndex: faker.random.number(),
sortIndex: faker.number.int(),
smAccessorValue: '',
},
];

View file

@ -34,7 +34,7 @@ import { setState, LensAppState } from '../state_management';
import { coreMock } from '@kbn/core/public/mocks';
import { LensSerializedState } from '..';
import { createMockedField, createMockedIndexPattern } from '../datasources/form_based/mocks';
import faker from 'faker';
import { faker } from '@faker-js/faker';
import { screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { VisualizeEditorContext } from '../types';
@ -48,7 +48,7 @@ jest.mock('lodash', () => ({
debounce: (fn: unknown) => fn,
}));
const defaultSavedObjectId: string = faker.random.uuid();
const defaultSavedObjectId: string = faker.string.uuid();
const waitToLoad = async () =>
await act(async () => new Promise((resolve) => setTimeout(resolve, 0)));
@ -233,7 +233,7 @@ describe('Lens App', () => {
});
describe('breadcrumbs', () => {
const breadcrumbDocSavedObjectId = faker.random.uuid();
const breadcrumbDocSavedObjectId = faker.string.uuid();
const breadcrumbDoc = getLensDocumentMock({
savedObjectId: breadcrumbDocSavedObjectId,
title: 'Daaaaaaadaumching!',
@ -601,7 +601,7 @@ describe('Lens App', () => {
expect(lensStore.getState().lens.applyChangesCounter).toBe(1);
});
it('adds to the recently accessed list on save', async () => {
const savedObjectId = faker.random.uuid();
const savedObjectId = faker.string.uuid();
await save({ savedObjectId, prevSavedObjectId: 'prevId', comesFromDashboard: false });
expect(services.chrome.recentlyAccessed.add).toHaveBeenCalledWith(
`/app/lens#/edit/${savedObjectId}`,

View file

@ -6,7 +6,7 @@
*/
import { renderHook, act } from '@testing-library/react-hooks';
import faker from 'faker';
import { faker } from '@faker-js/faker';
import { UseNavigateBackToAppProps, useNavigateBackToApp } from './app_helpers';
import { defaultDoc, makeDefaultServices } from '../mocks/services_mock';
import { cloneDeep } from 'lodash';

View file

@ -8,7 +8,7 @@
import { SaveProps } from './app';
import { type SaveVisualizationProps, runSaveLensVisualization } from './save_modal_container';
import { defaultDoc, makeDefaultServices } from '../mocks';
import faker from 'faker';
import { faker } from '@faker-js/faker';
import { makeAttributeService } from '../mocks/services_mock';
jest.mock('../persistence/saved_objects_utils/check_for_duplicate_title', () => ({
@ -241,7 +241,7 @@ describe('runSaveLensVisualization', () => {
});
// save the current document as a new by-value copy and add it to a dashboard
it('should save as a new by-value copy and redirect to the dashboard', async () => {
const dashboardId = faker.random.uuid();
const dashboardId = faker.string.uuid();
const { props, saveProps, options, redirectToDashboardFn, saveToLibraryFn, toasts } =
getDefaultArgs(
{
@ -271,7 +271,7 @@ describe('runSaveLensVisualization', () => {
// save the current document as a new by-ref copy and add it to a dashboard
it('should save as a new by-ref copy and redirect to the dashboard', async () => {
const dashboardId = faker.random.uuid();
const dashboardId = faker.string.uuid();
const { props, saveProps, options, redirectToDashboardFn, saveToLibraryFn, toasts } =
getDefaultArgs(
{
@ -376,7 +376,7 @@ describe('runSaveLensVisualization', () => {
// simulate a new save
const attributeServiceMock = makeAttributeService({
...defaultDoc,
savedObjectId: faker.random.uuid(),
savedObjectId: faker.string.uuid(),
});
const { props, saveProps, options, saveToLibraryFn, cleanupEditor } = getDefaultArgs(

View file

@ -12,7 +12,7 @@ import { unifiedSearchPluginMock } from '@kbn/unified-search-plugin/public/mocks
import { IStorageWrapper } from '@kbn/kibana-utils-plugin/public';
import { dataPluginMock } from '@kbn/data-plugin/public/mocks';
import { dataViewPluginMocks } from '@kbn/data-views-plugin/public/mocks';
import faker from 'faker';
import { faker } from '@faker-js/faker';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { createMockedIndexPattern } from '../../mocks';
@ -402,7 +402,7 @@ describe('percentile', () => {
it('should update order-by references for any terms columns', () => {
const field1 = 'foo';
const field2 = 'bar';
const percentile = faker.random.number(100);
const percentile = faker.number.int(100);
const aggs = [
makeEsAggBuilder('aggTerms', {

View file

@ -21,7 +21,7 @@ import { DatasourcePublicAPI, SuggestionRequest, DatasourceSuggestion } from '..
import { ChartSwitchProps } from './chart_switch';
import { ChartSwitchPopover } from './chart_switch_popover';
import { LensAppState, applyChanges } from '../../../../state_management';
import faker from 'faker';
import { faker } from '@faker-js/faker';
const mockFrame = (layers: string[]) => ({
...createMockFramePublicAPI(),

View file

@ -7,7 +7,7 @@
import React from 'react';
import { screen } from '@testing-library/react';
import faker from 'faker';
import { faker } from '@faker-js/faker';
import {
createMockDatasource,
createMockFramePublicAPI,

View file

@ -12,7 +12,7 @@ import { ChildDragDropProvider, Droppable, Draggable } from '@kbn/dom-drag-drop'
import { FramePublicAPI, Visualization, VisualizationConfigProps } from '../../../types';
import { LayerPanel } from './layer_panel';
import { coreMock } from '@kbn/core/public/mocks';
import faker from 'faker';
import { faker } from '@faker-js/faker';
import { generateId } from '../../../id_generator';
import {
createMockVisualization,
@ -144,7 +144,7 @@ describe('LayerPanel', () => {
};
beforeEach(() => {
mockVisualization = createMockVisualization(faker.random.alphaNumeric());
mockVisualization = createMockVisualization(faker.string.alphanumeric());
mockVisualization.getLayerIds.mockReturnValue(['first']);
mockDatasource = createMockDatasource();
});

View file

@ -39,7 +39,7 @@ import { getLensInspectorService } from '../../../lens_inspector_service';
import { inspectorPluginMock } from '@kbn/inspector-plugin/public/mocks';
import { disableAutoApply, enableAutoApply } from '../../../state_management/lens_slice';
import { Ast, toExpression } from '@kbn/interpreter';
import faker from 'faker';
import { faker } from '@faker-js/faker';
const defaultPermissions: Record<string, Record<string, boolean | Record<string, boolean>>> = {
navLinks: { management: true },

View file

@ -18,7 +18,7 @@ import { updateVisualizationState, LensAppState } from '../../../state_managemen
import { setChangesApplied } from '../../../state_management/lens_slice';
import { LensInspector } from '../../../lens_inspector_service';
import { screen } from '@testing-library/react';
import faker from 'faker';
import { faker } from '@faker-js/faker';
import { SettingsMenu } from '../../../app_plugin/settings_menu';
describe('workspace_panel_wrapper', () => {
@ -98,7 +98,7 @@ describe('workspace_panel_wrapper', () => {
});
it('should render its children', async () => {
const customElementText = faker.random.word();
const customElementText = faker.word.words();
renderWorkspacePanelWrapper({ children: <span>{customElementText}</span> });
expect(screen.getByText(customElementText)).toBeInTheDocument();
});

View file

@ -13,7 +13,7 @@ import {
DEFAULT_COLOR_MAPPING_CONFIG,
DEFAULT_OTHER_ASSIGNMENT_INDEX,
} from '@kbn/coloring';
import faker from 'faker';
import { faker } from '@faker-js/faker';
const exampleAssignment = (
valuesCount = 1,
@ -35,7 +35,7 @@ const exampleAssignment = (
return {
rule: {
type: 'matchExactly',
values: Array.from({ length: valuesCount }, () => faker.random.alpha()),
values: Array.from({ length: valuesCount }, () => faker.string.alpha()),
},
color,
touched: false,

View file

@ -7,7 +7,7 @@
import React from 'react';
import { LayerTypes } from '@kbn/expression-xy-plugin/public';
import { toExpression } from '@kbn/interpreter';
import faker from 'faker';
import { faker } from '@faker-js/faker';
import { Visualization, VisualizationMap } from '../types';
export function createMockVisualization(

View file

@ -9,7 +9,7 @@ import { ExpressionRendererEvent } from '@kbn/expressions-plugin/public';
import { getLensApiMock, getLensRuntimeStateMock, makeEmbeddableServices } from '../mocks';
import { LensApi, LensEmbeddableStartServices, LensPublicCallbacks } from '../types';
import { prepareEventHandler } from './on_event';
import faker from 'faker';
import { faker } from '@faker-js/faker';
import {
LENS_EDIT_PAGESIZE_ACTION,
LENS_EDIT_RESIZE_ACTION,
@ -109,7 +109,7 @@ describe('Embeddable interaction event handlers', () => {
const event = {
name: 'filter',
data: {
data: [{ value: faker.random.number(), row: 1, column: 'test', table: getTable() }],
data: [{ value: faker.number.int(), row: 1, column: 'test', table: getTable() }],
},
};
const { callbacks } = await submitEvent(event);
@ -119,7 +119,7 @@ describe('Embeddable interaction event handlers', () => {
const event = {
name: 'filter',
data: {
data: [{ value: faker.random.number(), row: 1, column: 'test', table: getTable() }],
data: [{ value: faker.number.int(), row: 1, column: 'test', table: getTable() }],
},
};
const { getTrigger } = await submitEvent(event, true);
@ -171,7 +171,7 @@ describe('Embeddable interaction event handlers', () => {
await reSubmit({
name: 'filter',
data: {
data: [{ value: faker.random.number(), row: 1, column: 'test', table: getTable() }],
data: [{ value: faker.number.int(), row: 1, column: 'test', table: getTable() }],
},
});

View file

@ -6,7 +6,7 @@
*/
import { pick } from 'lodash';
import faker from 'faker';
import { faker } from '@faker-js/faker';
import type { LensRuntimeState, VisualizationContext } from '../types';
import { initializeActionApi } from './initialize_actions';
import {
@ -42,7 +42,7 @@ function setupActionsApi(
visOverrides: { id: 'lnsXY' },
dataOverrides: { id: 'form_based' },
});
const uuid = faker.random.uuid();
const uuid = faker.string.uuid();
const runtimeState = getLensRuntimeStateMock(stateOverrides);
const apiMock = getLensApiMock();

View file

@ -9,7 +9,7 @@ import type { LensRuntimeState } from '../types';
import { getLensRuntimeStateMock, getLensInternalApiMock, makeEmbeddableServices } from '../mocks';
import { initializeStateManagement } from './initialize_state_management';
import { initializeDashboardServices } from './initialize_dashboard_services';
import faker from 'faker';
import { faker } from '@faker-js/faker';
import { createEmptyLensState } from '../helper';
function setupDashboardServicesApi(runtimeOverrides?: Partial<LensRuntimeState>) {
@ -30,7 +30,7 @@ function setupDashboardServicesApi(runtimeOverrides?: Partial<LensRuntimeState>)
describe('Transformation API', () => {
it("should not save to library if there's already a saveObjectId", async () => {
const api = setupDashboardServicesApi({ savedObjectId: faker.random.uuid() });
const api = setupDashboardServicesApi({ savedObjectId: faker.string.uuid() });
expect(await api.canLinkToLibrary()).toBe(false);
});

View file

@ -8,7 +8,7 @@
import { BehaviorSubject, Subject } from 'rxjs';
import deepMerge from 'deepmerge';
import React from 'react';
import faker from 'faker';
import { faker } from '@faker-js/faker';
import { Query, Filter, AggregateQuery, TimeRange } from '@kbn/es-query';
import { PhaseEvent, ViewMode } from '@kbn/presentation-publishing';
import { DataView } from '@kbn/data-views-plugin/common';
@ -49,7 +49,7 @@ import {
const LensApiMock: LensApi = {
// Static props
type: DOC_TYPE,
uuid: faker.random.uuid(),
uuid: faker.string.uuid(),
// Shared Embeddable Observables
panelTitle: new BehaviorSubject<string | undefined>(faker.lorem.words()),
hidePanelTitle: new BehaviorSubject<boolean | undefined>(false),
@ -94,7 +94,7 @@ const LensApiMock: LensApi = {
setPanelTitle: jest.fn(),
setHidePanelTitle: jest.fn(),
phase$: new BehaviorSubject<PhaseEvent | undefined>({
id: faker.random.uuid(),
id: faker.string.uuid(),
status: 'rendered',
timeToEvent: 1000,
}),
@ -138,7 +138,7 @@ export function getLensApiMock(overrides: Partial<LensApi> = {}) {
export function getLensSerializedStateMock(overrides: Partial<LensSerializedState> = {}) {
return {
savedObjectId: faker.random.uuid(),
savedObjectId: faker.string.uuid(),
...LensSerializedStateMock,
...overrides,
};

View file

@ -17,7 +17,7 @@ import { Location, History } from 'history';
import { act } from 'react-dom/test-utils';
import { InitialAppState, loadInitial } from './lens_slice';
import { Filter } from '@kbn/es-query';
import faker from 'faker';
import { faker } from '@faker-js/faker';
import { DOC_TYPE } from '../../common/constants';
const history = {

View file

@ -9,7 +9,7 @@ import React from 'react';
import { fireEvent, render, screen, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { I18nProvider } from '@kbn/i18n-react';
import faker from 'faker';
import { faker } from '@faker-js/faker';
import { act } from 'react-dom/test-utils';
import { IFieldFormat } from '@kbn/field-formats-plugin/common';
import { coreMock } from '@kbn/core/public/mocks';
@ -504,7 +504,7 @@ describe('DatatableComponent', () => {
data.rows = new Array(rowNumbers).fill({
a: 'shoes',
b: 1588024800000,
c: faker.random.number(),
c: faker.number.int(),
});
args.pageSize = pageSize;
@ -537,7 +537,7 @@ describe('DatatableComponent', () => {
data.rows = new Array(rowNumbers).fill({
a: 'shoes',
b: 1588024800000,
c: faker.random.number(),
c: faker.number.int(),
});
args.pageSize = pageSize;
@ -558,7 +558,7 @@ describe('DatatableComponent', () => {
data.rows = new Array(20).fill({
a: 'shoes',
b: 1588024800000,
c: faker.random.number(),
c: faker.number.int(),
});
renderDatatableComponent({
args,
@ -584,7 +584,7 @@ describe('DatatableComponent', () => {
data.rows = new Array(rowNumbers).fill({
a: 'shoes',
b: 1588024800000,
c: faker.random.number(),
c: faker.number.int(),
});
args.pageSize = pageSize;
@ -624,7 +624,7 @@ describe('DatatableComponent', () => {
data.rows = new Array(rowNumbers).fill({
a: 'shoes',
b: 1588024800000,
c: faker.random.number(),
c: faker.number.int(),
});
args.pageSize = pageSize;

View file

@ -7,7 +7,7 @@
import React from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import faker from 'faker';
import { faker } from '@faker-js/faker';
import userEvent from '@testing-library/user-event';
import { chartPluginMock } from '@kbn/charts-plugin/public/mocks';
import { euiLightVars } from '@kbn/ui-theme';
@ -77,7 +77,7 @@ describe('dimension editor', () => {
id: 'first',
rows: Array(3).fill({
'metric-col-id': faker.lorem.word(3),
'max-col-id': faker.random.number(),
'max-col-id': faker.number.int(),
}),
},
]),
@ -106,8 +106,8 @@ describe('dimension editor', () => {
{
id: 'first',
rows: Array(3).fill({
'metric-col-id': faker.random.number(),
'secondary-metric-col-id': faker.random.number(),
'metric-col-id': faker.number.int(),
'secondary-metric-col-id': faker.number.int(),
}),
},
]),

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import faker from 'faker';
import { faker } from '@faker-js/faker';
import { LogEntry, LogViewColumnConfiguration } from '@kbn/logs-shared-plugin/common';
export function generateFakeEntries(
@ -51,15 +51,15 @@ export function generateFakeEntries(
function fakeColumnValue(field: string): string {
switch (field) {
case 'message':
return faker.fake(
'{{internet.ip}} - [{{date.past}}] "GET {{internet.url}} HTTP/1.1" 200 {{random.number}} "-" "{{internet.userAgent}}"'
return faker.helpers.fake(
'{{internet.ip}} - [{{date.past}}] "GET {{internet.url}} HTTP/1.1" 200 {{number.int}} "-" "{{internet.userAgent}}"'
);
case 'event.dataset':
return faker.fake('{{hacker.noun}}.{{hacker.noun}}');
return faker.helpers.fake('{{hacker.noun}}.{{hacker.noun}}');
case 'log.file.path':
return faker.system.filePath();
case 'log.level':
return faker.random.arrayElement(['debug', 'info', 'warn', 'error']);
return faker.helpers.arrayElement(['debug', 'info', 'warn', 'error']);
case 'host.name':
return faker.hacker.noun();
default:

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import faker from 'faker';
import { faker } from '@faker-js/faker';
import { LogEntry } from '../../common/log_entry';
import { LogViewColumnConfiguration } from '../../common/log_views';
@ -60,15 +60,15 @@ export function generateFakeEntries(
function fakeColumnValue(field: string): string {
switch (field) {
case 'message':
return faker.fake(
'{{internet.ip}} - [{{date.past}}] "GET {{internet.url}} HTTP/1.1" 200 {{random.number}} "-" "{{internet.userAgent}}"'
return faker.helpers.fake(
'{{internet.ip}} - [{{date.past}}] "GET {{internet.url}} HTTP/1.1" 200 {{number.int}} "-" "{{internet.userAgent}}"'
);
case 'event.dataset':
return faker.fake('{{hacker.noun}}.{{hacker.noun}}');
return faker.helpers.fake('{{hacker.noun}}.{{hacker.noun}}');
case 'log.file.path':
return faker.system.filePath();
case 'log.level':
return faker.random.arrayElement(['debug', 'info', 'warn', 'error']);
return faker.helpers.arrayElement(['debug', 'info', 'warn', 'error']);
case 'host.name':
return faker.hacker.noun();
default:

View file

@ -25,13 +25,19 @@ jest.mock('@kbn/triggers-actions-ui-plugin/public/common/lib/kibana', () => ({
})),
}));
jest.mock('@faker-js/faker', () => ({
faker: {
string: {
alpha: jest.fn().mockReturnValue('123'),
jest.mock('@faker-js/faker', () => {
const originalModule = jest.requireActual('@faker-js/faker');
return {
...originalModule,
faker: {
...originalModule.faker,
string: {
...originalModule.faker.string,
alpha: jest.fn().mockReturnValue('123'),
},
},
},
}));
};
});
const mockProviders = useProviders as jest.Mock;

View file

@ -6,7 +6,7 @@
*/
const { Client } = require('@elastic/elasticsearch');
const faker = require('faker');
const { faker } = require('@faker-js/faker');
const THREAT_INDEX = 'logs-ti';

View file

@ -1250,7 +1250,7 @@ export default ({ getService }: FtrProviderContext) => {
await indexGeneratedSourceDocuments({
docsCount: 60000,
interval: [firstTimestamp, '2020-10-28T05:35:50.000Z'],
interval: [firstTimestamp, '2020-10-28T05:45:50.000Z'],
seed: (index, _, timestamp) => ({
id,
'@timestamp': timestamp,

View file

@ -4,12 +4,12 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import faker from 'faker';
import { faker } from '@faker-js/faker';
import type { IndexingInterval } from './types';
export const getTimestamp = (interval?: IndexingInterval) => {
if (interval) {
return faker.date.between(...interval).toISOString();
return faker.date.between({ from: interval[0], to: interval[1] }).toISOString();
}
return new Date().toISOString();

View file

@ -11493,11 +11493,6 @@
resolved "https://registry.yarnpkg.com/@types/extract-zip/-/extract-zip-1.6.2.tgz#5c7eb441c41136167a42b88b64051e6260c29e86"
integrity sha1-XH60QcQRNhZ6QriLZAUeYmDCnoY=
"@types/faker@^5.1.5":
version "5.1.5"
resolved "https://registry.yarnpkg.com/@types/faker/-/faker-5.1.5.tgz#f14b015e0100232bb00c6dd7611505efb08709a0"
integrity sha512-2uEQFb7bsx68rqD4F8q95wZq6LTLOyexjv6BnvJogCO4jStkyc6IDEkODPQcWfovI6g6M3uPQ2/uD/oedJKkNw==
"@types/fetch-mock@^7.3.1":
version "7.3.1"
resolved "https://registry.yarnpkg.com/@types/fetch-mock/-/fetch-mock-7.3.1.tgz#df7421e8bcb351b430bfbfa5c52bb353826ac94f"
@ -18764,11 +18759,6 @@ extsprintf@1.3.0, extsprintf@^1.2.0:
resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.3.0.tgz#96918440e3041a7a414f8c52e3c574eb3c3e1e05"
integrity sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=
faker@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/faker/-/faker-5.1.0.tgz#e10fa1dec4502551aee0eb771617a7e7b94692e8"
integrity sha512-RrWKFSSA/aNLP0g3o2WW1Zez7/MnMr7xkiZmoCfAGZmdkDQZ6l2KtuXHN5XjdvpRjDl8+3vf+Rrtl06Z352+Mw==
fancy-log@^1.3.3:
version "1.3.3"
resolved "https://registry.yarnpkg.com/fancy-log/-/fancy-log-1.3.3.tgz#dbc19154f558690150a23953a0adbd035be45fc7"