Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"env": {
"commonjs": true,
"es6": true,
"jest": true,
"vitest": true,
"node": true,
"browser": true
},
Expand Down
24 changes: 0 additions & 24 deletions alertmanager/jest.config.ts

This file was deleted.

2 changes: 1 addition & 1 deletion alertmanager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"build:esm": "swc ./src -d dist/lib --strip-leading-paths --config-file ../.swcrc",
"build:types": "tsc --project tsconfig.build.json",
"lint": "oxlint src",
"test": "cross-env LC_ALL=C TZ=UTC jest",
"test": "cross-env LC_ALL=C TZ=UTC vitest run",
"type-check": "tsc --noEmit"
},
"main": "lib/cjs/index.js",
Expand Down
6 changes: 3 additions & 3 deletions alertmanager/src/model/alertmanager-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ type FetchResponse = {
json: () => Promise<unknown>;
};

const fetchMock = jest.fn();
jest.mock('@perses-dev/client', () => ({
...jest.requireActual('@perses-dev/client'),
const fetchMock = vi.hoisted(() => vi.fn());
vi.mock('@perses-dev/client', async (importOriginal) => ({
...(await importOriginal<typeof import('@perses-dev/client')>()),
fetch: (...args: unknown[]): Promise<FetchResponse> => fetchMock(...args),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,23 @@ const mockAlerts: GettableAlert[] = [

const makeClient = (): AlertManagerClient => {
const client = AlertManagerDatasource.createClient(datasource, {});
client.getAlerts = jest.fn(async () => mockAlerts);
client.getAlerts = vi.fn(async () => mockAlerts);
return client;
};

function createContext(client: AlertManagerClient): AlertsQueryContext {
return {
variableState: {},
datasourceStore: {
getDatasource: jest.fn(),
getDatasourceClient: jest.fn(() =>
getDatasource: vi.fn(),
getDatasourceClient: vi.fn(() =>
Promise.resolve(client),
) as AlertsQueryContext['datasourceStore']['getDatasourceClient'],
listDatasourceSelectItems: jest.fn(async () => []),
getLocalDatasources: jest.fn(),
setLocalDatasources: jest.fn(),
getSavedDatasources: jest.fn(),
setSavedDatasources: jest.fn(),
listDatasourceSelectItems: vi.fn(async () => []),
getLocalDatasources: vi.fn(),
setLocalDatasources: vi.fn(),
getSavedDatasources: vi.fn(),
setSavedDatasources: vi.fn(),
},
};
}
Expand Down Expand Up @@ -127,7 +127,7 @@ describe('getAlertsData', () => {

it('returns empty alerts array when API returns empty', async () => {
const client = makeClient();
client.getAlerts = jest.fn(async () => []);
client.getAlerts = vi.fn(async () => []);
const spec: AlertManagerAlertsQuerySpec = {};
const context = createContext(client);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,23 @@ const mockSilences = [

const makeClient = (): AlertManagerClient => {
const client = AlertManagerDatasource.createClient(datasource, {});
client.getSilences = jest.fn(async () => mockSilences);
client.getSilences = vi.fn(async () => mockSilences);
return client;
};

function createContext(client: AlertManagerClient): SilencesQueryContext {
return {
variableState: {},
datasourceStore: {
getDatasource: jest.fn(),
getDatasourceClient: jest.fn(() =>
getDatasource: vi.fn(),
getDatasourceClient: vi.fn(() =>
Promise.resolve(client),
) as SilencesQueryContext['datasourceStore']['getDatasourceClient'],
listDatasourceSelectItems: jest.fn(async () => []),
getLocalDatasources: jest.fn(),
setLocalDatasources: jest.fn(),
getSavedDatasources: jest.fn(),
setSavedDatasources: jest.fn(),
listDatasourceSelectItems: vi.fn(async () => []),
getLocalDatasources: vi.fn(),
setLocalDatasources: vi.fn(),
getSavedDatasources: vi.fn(),
setSavedDatasources: vi.fn(),
},
};
}
Expand Down Expand Up @@ -118,7 +118,7 @@ describe('getSilencesData', () => {

it('returns empty silences array when API returns empty', async () => {
const client = makeClient();
client.getSilences = jest.fn(async () => []);
client.getSilences = vi.fn(async () => []);
const spec: AlertManagerSilencesQuerySpec = {};
const context = createContext(client);

Expand Down
4 changes: 2 additions & 2 deletions alertmanager/src/setup-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import '@testing-library/jest-dom';
import '@testing-library/jest-dom/vitest';

jest.mock('echarts/core');
vi.mock('echarts/core');
14 changes: 6 additions & 8 deletions jaeger/jest.config.ts → alertmanager/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import type { Config } from '@jest/types';
import { resolve } from 'node:path';

import shared from '../jest.shared';
import { definePackageVitestConfig } from '../vitest.shared';

const jestConfig: Config.InitialOptions = {
...shared,
setupFilesAfterEnv: [...(shared.setupFilesAfterEnv ?? []), '<rootDir>/src/setup-tests.ts'],
};

export default jestConfig;
export default definePackageVitestConfig({
packageDir: resolve(__dirname),
setupFiles: ['src/setup-tests.ts'],
});
24 changes: 0 additions & 24 deletions barchart/jest.config.ts

This file was deleted.

2 changes: 1 addition & 1 deletion barchart/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"build:esm": "swc ./src -d dist/lib --strip-leading-paths --config-file ../.swcrc",
"build:types": "tsc --project tsconfig.build.json",
"lint": "oxlint src",
"test": "cross-env LC_ALL=C TZ=UTC jest",
"test": "cross-env LC_ALL=C TZ=UTC vitest run",
"type-check": "tsc --noEmit"
},
"main": "lib/cjs/index.js",
Expand Down
16 changes: 8 additions & 8 deletions barchart/src/BarChartOptionsEditorSettings.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { BarChartOptions } from './bar-chart-model';
import { BarChartOptionsEditorSettings } from './BarChartOptionsEditorSettings';

describe('BarChartOptionsEditorSettings', () => {
const renderBarChartOptionsEditorSettings = (value?: BarChartOptions, onChange = jest.fn()): void => {
const renderBarChartOptionsEditorSettings = (value?: BarChartOptions, onChange = vi.fn()): void => {
render(
<ChartsProvider chartsTheme={testChartsTheme}>
<BarChartOptionsEditorSettings
Expand All @@ -40,7 +40,7 @@ describe('BarChartOptionsEditorSettings', () => {
};

it('can modify unit', () => {
const onChange = jest.fn();
const onChange = vi.fn();
renderBarChartOptionsEditorSettings(undefined, onChange);
const unitSelector = screen.getByRole('combobox', { name: 'Unit' });
userEvent.click(unitSelector);
Expand All @@ -58,7 +58,7 @@ describe('BarChartOptionsEditorSettings', () => {
});

it('can modify calculation', () => {
const onChange = jest.fn();
const onChange = vi.fn();
renderBarChartOptionsEditorSettings(undefined, onChange);
const calcSelector = screen.getByRole('combobox', { name: 'Calculation' });
userEvent.click(calcSelector);
Expand All @@ -74,7 +74,7 @@ describe('BarChartOptionsEditorSettings', () => {
});

it('can modify sort order', () => {
const onChange = jest.fn();
const onChange = vi.fn();
renderBarChartOptionsEditorSettings(undefined, onChange);
const sortSelector = screen.getByRole('combobox', { name: 'Sort' });
userEvent.click(sortSelector);
Expand All @@ -90,7 +90,7 @@ describe('BarChartOptionsEditorSettings', () => {
});

it('can modify mode', () => {
const onChange = jest.fn();
const onChange = vi.fn();
renderBarChartOptionsEditorSettings(undefined, onChange);
const modeSelector = screen.getByRole('combobox', { name: 'Mode' });
userEvent.click(modeSelector);
Expand Down Expand Up @@ -136,7 +136,7 @@ describe('BarChartOptionsEditorSettings', () => {
});

it('should reset settings to defaults', () => {
const onChange = jest.fn();
const onChange = vi.fn();
renderBarChartOptionsEditorSettings(
{
format: {
Expand Down Expand Up @@ -164,7 +164,7 @@ describe('BarChartOptionsEditorSettings', () => {
});

it('can add a color override', () => {
const onChange = jest.fn();
const onChange = vi.fn();
renderBarChartOptionsEditorSettings(undefined, onChange);
const addButton = screen.getByRole('button', { name: 'Add Color Override' });
userEvent.click(addButton);
Expand All @@ -176,7 +176,7 @@ describe('BarChartOptionsEditorSettings', () => {
});

it('can remove a color override', () => {
const onChange = jest.fn();
const onChange = vi.fn();
renderBarChartOptionsEditorSettings(
{
format: {
Expand Down
4 changes: 2 additions & 2 deletions barchart/src/setup-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import '@testing-library/jest-dom';
import '@testing-library/jest-dom/vitest';

// Always mock e-charts during tests since we don't have a proper canvas in jsdom
jest.mock('echarts/core');
vi.mock('echarts/core');
15 changes: 6 additions & 9 deletions clickhouse/jest.config.ts → barchart/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import type { Config } from '@jest/types';
import { resolve } from 'node:path';

import shared from '../jest.shared';
import { definePackageVitestConfig } from '../vitest.shared';

const jestConfig: Config.InitialOptions = {
...shared,

setupFilesAfterEnv: [...(shared.setupFilesAfterEnv ?? []), '<rootDir>/src/setup-tests.ts'],
};

export default jestConfig;
export default definePackageVitestConfig({
packageDir: resolve(__dirname),
setupFiles: ['src/setup-tests.ts'],
});
2 changes: 1 addition & 1 deletion clickhouse/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"build:esm": "swc ./src -d dist/lib --strip-leading-paths --config-file ../.swcrc",
"build:types": "tsc --project tsconfig.build.json",
"lint": "oxlint src",
"test": "cross-env LC_ALL=C TZ=UTC jest",
"test": "cross-env LC_ALL=C TZ=UTC vitest run",
"type-check": "tsc --noEmit"
},
"main": "lib/cjs/index.js",
Expand Down
6 changes: 3 additions & 3 deletions clickhouse/src/model/click-house-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { formatClickHouseDateTime, query, replaceTimeRangePlaceholders } from '.

describe('ClickHouse client', () => {
afterEach(() => {
jest.restoreAllMocks();
vi.restoreAllMocks();
});

it('should replace time range placeholders', () => {
Expand All @@ -33,9 +33,9 @@ describe('ClickHouse client', () => {
});

it('should send interpolated query to ClickHouse', async () => {
const fetchMock = jest.fn<Promise<Pick<Response, 'ok' | 'json'>>, [string, RequestInit?]>(async () => ({
const fetchMock = vi.fn<(url: string, init?: RequestInit) => Promise<Pick<Response, 'ok' | 'json'>>>(async () => ({
ok: true,
json: jest.fn(async () => ({ data: [] })),
json: vi.fn(async () => ({ data: [] })),
}));
global.fetch = fetchMock as unknown as typeof fetch;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// limitations under the License.

import { LogQueryContext } from '@perses-dev/plugin-system';
import type { Mock } from 'vitest';

import { ClickHouseDatasource, ClickHouseDatasourceSpec } from '../../datasources/click-house-datasource';
import { ClickHouseQueryResponse } from '../../model/click-house-client';
Expand All @@ -24,28 +25,28 @@ const datasource: ClickHouseDatasourceSpec = {
const clickhouseStubClient = ClickHouseDatasource.createClient(datasource, {});

// Mock query
clickhouseStubClient.query = jest.fn(async () => {
clickhouseStubClient.query = vi.fn(async () => {
const stubResponse: ClickHouseQueryResponse = {
status: 'success',
data: [],
};
return stubResponse as ClickHouseQueryResponse;
});

const getDatasourceClient: jest.Mock = jest.fn(() => {
const getDatasourceClient: Mock = vi.fn(() => {
return clickhouseStubClient;
});

const createStubContext = (): LogQueryContext => {
const stubLogContext: LogQueryContext = {
datasourceStore: {
getDatasource: jest.fn(),
getDatasource: vi.fn(),
getDatasourceClient: getDatasourceClient,
listDatasourceSelectItems: jest.fn(),
getLocalDatasources: jest.fn(),
setLocalDatasources: jest.fn(),
getSavedDatasources: jest.fn(),
setSavedDatasources: jest.fn(),
listDatasourceSelectItems: vi.fn(),
getLocalDatasources: vi.fn(),
setLocalDatasources: vi.fn(),
getSavedDatasources: vi.fn(),
setSavedDatasources: vi.fn(),
},
timeRange: {
end: new Date('2025-01-02T00:00:00.000Z'),
Expand Down
Loading
Loading