Skip to content

Commit d6987a4

Browse files
sunkertolzhabayev
andauthored
fix(plugin-e2e): remove uuid and semver runtime dependencies (#2650)
Co-authored-by: Timur Olzhabayev <timur.olzhabayev@grafana.com>
1 parent 5addafc commit d6987a4

26 files changed

Lines changed: 436 additions & 95 deletions

docusaurus/docs/e2e-test-a-plugin/feature-toggles.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ Use the `isFeatureToggleEnabled` fixture to determine whether a certain feature
7070
7171
```typescript
7272
import { test, expect } from '@grafana/plugin-e2e';
73-
import * as semver from 'semver';
7473

7574
test('valid credentials should return a 200 status code', async ({
7675
createDataSourceConfigPage,

docusaurus/docs/e2e-test-a-plugin/test-a-data-source-plugin/annotation-queries.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ Note that the annotation query result is rendered in an Alert component starting
4444
:::
4545

4646
```ts title="annotations.spec.ts"
47-
import * as semver from 'semver';
48-
import { expect, test } from '@grafana/plugin-e2e';
47+
import { expect, gte, test } from '@grafana/plugin-e2e';
4948

5049
test('should run successfully and display a success alert box when query is valid', async ({
5150
annotationEditPage,
@@ -62,7 +61,7 @@ test('should run successfully and display a success alert box when query is vali
6261
from dataset
6362
where $__timeFilter(time) and humidity > 95`);
6463
await expect(annotationEditPage.runQuery()).toBeOK();
65-
if (semver.gte(grafanaVersion, '11.0.0')) {
64+
if (gte(grafanaVersion, '11.0.0')) {
6665
await expect(annotationEditPage).toHaveAlert('success');
6766
}
6867
});
@@ -88,7 +87,7 @@ test('should fail and display an error alert box when time field is missing in t
8887
from dataset
8988
where humidity > 95`);
9089
await expect(annotationEditPage.runQuery()).not.toBeOK();
91-
if (semver.gte(grafanaVersion, '11.0.0')) {
90+
if (gte(grafanaVersion, '11.0.0')) {
9291
await expect(annotationEditPage).toHaveAlert('error', { hasText: 'Time field is missing' });
9392
}
9493
});
@@ -107,7 +106,7 @@ test('annotation query in provisioned dashboard should return a 200 response', a
107106
const dashboard = await readProvisionedDashboard({ fileName: 'dashboard.json' });
108107
const annotationEditPage = await gotoAnnotationEditPage({ dashboard, id: '1' });
109108
await expect(annotationEditPage.runQuery()).toBeOK();
110-
if (semver.gte(grafanaVersion, '11.0.0')) {
109+
if (gte(grafanaVersion, '11.0.0')) {
111110
await expect(annotationEditPage).toHaveAlert('success', { hasText: /2 events.*/ });
112111
}
113112
});
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
2-
import { v4 as uuid } from 'uuid';
1+
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
32

43
class GcomApiClient {
54
constructor(baseApiUrl) {
@@ -12,24 +11,24 @@ class GcomApiClient {
1211
body: JSON.stringify(payload),
1312
headers: {
1413
'Content-Type': 'application/json',
15-
'x-request-id': uuid(),
14+
'x-request-id': crypto.randomUUID(),
1615
},
1716
});
1817

1918
if (!response.ok) {
2019
const res = await response.text();
21-
20+
2221
console.error(`Error while sending POST request: ${endpoint}`, res);
2322
throw new Error(`Error while sending POST request: ${endpoint}`);
2423
}
25-
24+
2625
return response.json();
2726
}
2827
}
2928

3029
export function useApiClient() {
3130
const { siteConfig } = useDocusaurusContext();
32-
31+
3332
const apiUrl = siteConfig.customFields.gcomUrl;
3433
return new GcomApiClient(apiUrl);
35-
}
34+
}

package-lock.json

Lines changed: 0 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/plugin-e2e/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,10 @@
4646
"devDependencies": {
4747
"@axe-core/playwright": "^4.11.1",
4848
"@playwright/test": "^1.58.1",
49-
"@types/uuid": "^11.0.0",
5049
"dotenv": "^17.2.4"
5150
},
5251
"dependencies": {
5352
"@grafana/e2e-selectors": "13.1.0-25644485979",
54-
"semver": "^7.5.4",
55-
"uuid": "^13.0.0",
5653
"yaml": "^2.3.4"
5754
}
5855
}

packages/plugin-e2e/src/fixtures/alertRuleEditPage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as semver from 'semver';
1+
import { lt } from '../utils/version';
22
import { TestFixture } from '@playwright/test';
33
import { AlertRuleEditPage } from '../models/pages/AlertRuleEditPage';
44
import { PlaywrightArgs } from '../types';
@@ -10,7 +10,7 @@ export const alertRuleEditPage: AlertRuleEditPageFixture = async (
1010
use,
1111
testInfo
1212
) => {
13-
if (semver.lt(grafanaVersion, '9.5.0')) {
13+
if (lt(grafanaVersion, '9.5.0')) {
1414
console.log(
1515
'Testing alert rules with plugin-e2e is only supported for Grafana 9.5.0 and later. Checkout https://grafana.com/developers/plugin-tools/e2e-test-a-plugin/test-a-data-source-plugin/annotation-queries#test-the-entire-annotation-query-execution-flow to see how to skip tests for a range of Grafana versions.'
1616
);

packages/plugin-e2e/src/fixtures/commands/createDataSource.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { v4 as uuidv4 } from 'uuid';
21
import { expect, TestFixture } from '@playwright/test';
32
import { CreateDataSourceArgs, DataSourceSettings, PlaywrightArgs } from '../../types';
43
import { GrafanaAPIClient } from '../../models/GrafanaAPIClient';
@@ -13,7 +12,7 @@ export const createDataSourceViaAPI = async (
1312
datasource: CreateDataSourceArgs
1413
): Promise<DataSourceSettings> => {
1514
const { type, name } = datasource;
16-
const dsName = name ?? `${type}-${uuidv4()}`;
15+
const dsName = name ?? `${type}-${crypto.randomUUID()}`;
1716

1817
const existingDataSource = await grafanaAPIClient.getDataSourceByName(dsName);
1918
if (existingDataSource.ok()) {

packages/plugin-e2e/src/fixtures/commands/gotoAlertRuleEditPage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as semver from 'semver';
1+
import { lt } from '../../utils/version';
22
import { TestFixture } from '@playwright/test';
33
import { AlertRuleArgs, PlaywrightArgs } from '../../types';
44
import { AlertRuleEditPage } from '../../models/pages/AlertRuleEditPage';
@@ -11,7 +11,7 @@ export const gotoAlertRuleEditPage: GotoAlertRuleEditPageFixture = async (
1111
testInfo
1212
) => {
1313
await use(async (args) => {
14-
if (semver.lt(grafanaVersion, '9.5.0')) {
14+
if (lt(grafanaVersion, '9.5.0')) {
1515
console.log(
1616
'Testing alert rules with plugin-e2e is only supported for Grafana 9.4.0 and later. Checkout https://grafana.com/developers/plugin-tools/e2e-test-a-plugin/test-a-data-source-plugin/annotation-queries#test-the-entire-annotation-query-execution-flow to see how to skip tests for a range of Grafana versions.'
1717
);

packages/plugin-e2e/src/fixtures/page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Page, TestFixture } from '@playwright/test';
2-
import { gte } from 'semver';
2+
import { gte } from '../utils/version';
33

44
import { PlaywrightArgs } from '../types';
55
import { DEFAULT_OPEN_FEATURE_FLAGS } from '../options';

packages/plugin-e2e/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export * from './types';
8787
// helper functions
8888
export { isLegacyFeatureEnabled, isFeatureEnabled } from './fixtures/isFeatureToggleEnabled';
8989
export { DEFAULT_A11Y_TAGS } from './fixtures/scanForA11yViolations';
90+
export { gte, lt, lte, gt, eq, satisfies } from './utils/version';
9091

9192
// first extend with internal fixtures (not exposed to tests)
9293
const testWithInternal = base.extend<InternalFixtures>({

0 commit comments

Comments
 (0)