@grafana/plugin-e2e 1.6.0-canary.970.deb7892.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/auth.setup.js +2 -3
- package/dist/fixtures/commands/createUser.js +2 -41
- package/dist/fixtures/commands/gotoDataSourceConfigPage.js +2 -10
- package/dist/fixtures/commands/login.js +3 -2
- package/dist/fixtures/grafanaAPIClient.d.ts +7 -0
- package/dist/fixtures/grafanaAPIClient.js +27 -0
- package/dist/index.js +2 -0
- package/dist/models/GrafanaAPIClient.d.ts +9 -0
- package/dist/models/GrafanaAPIClient.js +52 -0
- package/dist/types.d.ts +12 -0
- package/package.json +2 -2
package/dist/auth/auth.setup.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const __1 = require("../");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (user && (user.user !== options_1.DEFAULT_ADMIN_USER.user || user.password !== options_1.DEFAULT_ADMIN_USER.password)) {
|
|
4
|
+
(0, __1.test)('authenticate', async ({ login, createUser, user, grafanaAPICredentials }) => {
|
|
5
|
+
if (user && (user.user !== grafanaAPICredentials.user || user.password !== grafanaAPICredentials.password)) {
|
|
7
6
|
await createUser();
|
|
8
7
|
}
|
|
9
8
|
await login();
|
|
@@ -1,51 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createUser = void 0;
|
|
4
|
-
const
|
|
5
|
-
const getHeaders = (user) => ({
|
|
6
|
-
Authorization: `Basic ${Buffer.from(`${user.user}:${user.password}`).toString('base64')}`,
|
|
7
|
-
});
|
|
8
|
-
const getUserIdByUsername = async (request, userName, grafanaAPIUser) => {
|
|
9
|
-
const getUserIdByUserNameReq = await request.get(`/api/users/lookup?loginOrEmail=${userName}`, {
|
|
10
|
-
headers: getHeaders(grafanaAPIUser),
|
|
11
|
-
});
|
|
12
|
-
(0, test_1.expect)(getUserIdByUserNameReq.ok()).toBeTruthy();
|
|
13
|
-
const json = await getUserIdByUserNameReq.json();
|
|
14
|
-
return json.id;
|
|
15
|
-
};
|
|
16
|
-
const createUser = async ({ request, user, grafanaAPICredentials }, use) => {
|
|
4
|
+
const createUser = async ({ grafanaAPIClient, user }, use) => {
|
|
17
5
|
await use(async () => {
|
|
18
6
|
if (!user) {
|
|
19
7
|
throw new Error('Playwright option `User` was not provided');
|
|
20
8
|
}
|
|
21
|
-
|
|
22
|
-
data: {
|
|
23
|
-
name: user?.user,
|
|
24
|
-
login: user?.user,
|
|
25
|
-
password: user?.password,
|
|
26
|
-
},
|
|
27
|
-
headers: getHeaders(grafanaAPICredentials),
|
|
28
|
-
});
|
|
29
|
-
let userId;
|
|
30
|
-
if (createUserReq.ok()) {
|
|
31
|
-
const respJson = await createUserReq.json();
|
|
32
|
-
userId = respJson.id;
|
|
33
|
-
}
|
|
34
|
-
else if (createUserReq.status() === 412) {
|
|
35
|
-
// user already exists
|
|
36
|
-
userId = await getUserIdByUsername(request, user?.user, grafanaAPICredentials);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
throw new Error(`Could not create user '${user?.user}': ${await createUserReq.text()}`);
|
|
40
|
-
}
|
|
41
|
-
if (user.role) {
|
|
42
|
-
const updateRoleReq = await request.patch(`/api/org/users/${userId}`, {
|
|
43
|
-
data: { role: user.role },
|
|
44
|
-
headers: getHeaders(grafanaAPICredentials),
|
|
45
|
-
});
|
|
46
|
-
const updateRoleReqText = await updateRoleReq.text();
|
|
47
|
-
(0, test_1.expect)(updateRoleReq.ok(), `Could not assign role '${user.role}' to user '${user.user}': ${updateRoleReqText}`).toBeTruthy();
|
|
48
|
-
}
|
|
9
|
+
await grafanaAPIClient.createUser(user);
|
|
49
10
|
});
|
|
50
11
|
};
|
|
51
12
|
exports.createUser = createUser;
|
|
@@ -2,17 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.gotoDataSourceConfigPage = void 0;
|
|
4
4
|
const DataSourceConfigPage_1 = require("../../models/pages/DataSourceConfigPage");
|
|
5
|
-
const gotoDataSourceConfigPage = async ({ request, page, selectors, grafanaVersion,
|
|
5
|
+
const gotoDataSourceConfigPage = async ({ request, page, selectors, grafanaVersion, grafanaAPIClient }, use, testInfo) => {
|
|
6
6
|
await use(async (uid) => {
|
|
7
|
-
const
|
|
8
|
-
headers: {
|
|
9
|
-
Authorization: `Basic ${Buffer.from(`${grafanaAPICredentials.user}:${grafanaAPICredentials.password}`).toString('base64')}`,
|
|
10
|
-
},
|
|
11
|
-
});
|
|
12
|
-
if (!response.ok()) {
|
|
13
|
-
throw new Error(`Failed to get datasource by uid: ${response.statusText()}. If you're using a provisioned data source, make sure it has a UID`);
|
|
14
|
-
}
|
|
15
|
-
const settings = await response.json();
|
|
7
|
+
const settings = await grafanaAPIClient.getDataSourceSettingsByUID(uid);
|
|
16
8
|
const dataSourceConfigPage = new DataSourceConfigPage_1.DataSourceConfigPage({ page, selectors, grafanaVersion, request, testInfo }, settings);
|
|
17
9
|
await dataSourceConfigPage.goto();
|
|
18
10
|
return dataSourceConfigPage;
|
|
@@ -5,12 +5,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.login = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const test_1 = require("@playwright/test");
|
|
9
8
|
const login = async ({ request, user }, use) => {
|
|
10
9
|
await use(async () => {
|
|
11
10
|
const loginReq = await request.post('/login', { data: user });
|
|
12
11
|
const text = await loginReq.text();
|
|
13
|
-
|
|
12
|
+
if (!loginReq.ok()) {
|
|
13
|
+
throw new Error(`Could not login to Grafana using user '${user?.user}': ${text}`);
|
|
14
|
+
}
|
|
14
15
|
await request.storageState({ path: path_1.default.join(process.cwd(), `playwright/.auth/${user?.user}.json`) });
|
|
15
16
|
});
|
|
16
17
|
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TestFixture, APIRequestContext } from '@playwright/test';
|
|
2
|
+
import { PlaywrightArgs, User } from '../types';
|
|
3
|
+
import { GrafanaAPIClient } from '../models/GrafanaAPIClient';
|
|
4
|
+
type GrafanaAPIClientFixture = TestFixture<GrafanaAPIClient, PlaywrightArgs>;
|
|
5
|
+
export declare const createAdminClientStorageState: (request: APIRequestContext, grafanaAPICredentials: User) => Promise<void>;
|
|
6
|
+
export declare const grafanaAPIClient: GrafanaAPIClientFixture;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.grafanaAPIClient = exports.createAdminClientStorageState = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const test_1 = require("@playwright/test");
|
|
9
|
+
const GrafanaAPIClient_1 = require("../models/GrafanaAPIClient");
|
|
10
|
+
const adminClientStorageState = path_1.default.join(process.cwd(), `playwright/.auth/grafanaAPICredentials.json`);
|
|
11
|
+
const createAdminClientStorageState = async (request, grafanaAPICredentials) => {
|
|
12
|
+
const loginReq = await request.post('/login', { data: grafanaAPICredentials });
|
|
13
|
+
const text = await loginReq.text();
|
|
14
|
+
await test_1.expect.soft(loginReq.ok(), `Could not log in to Grafana: ${text}`).toBeTruthy();
|
|
15
|
+
await request.storageState({ path: adminClientStorageState });
|
|
16
|
+
};
|
|
17
|
+
exports.createAdminClientStorageState = createAdminClientStorageState;
|
|
18
|
+
const grafanaAPIClient = async ({ browser, grafanaAPICredentials }, use) => {
|
|
19
|
+
const context = await browser.newContext({ storageState: undefined });
|
|
20
|
+
const loginReq = await context.request.post('/login', { data: grafanaAPICredentials });
|
|
21
|
+
if (!loginReq.ok()) {
|
|
22
|
+
console.log(`Could not login to grafana using credentials '${grafanaAPICredentials?.user}'. Find information on how user can be managed in the plugin-e2e docs: https://grafana.com/developers/plugin-tools/e2e-test-a-plugin/use-authentication#managing-users : ${await loginReq.text()}`);
|
|
23
|
+
}
|
|
24
|
+
await context.request.storageState({ path: adminClientStorageState });
|
|
25
|
+
await use(new GrafanaAPIClient_1.GrafanaAPIClient(context.request));
|
|
26
|
+
};
|
|
27
|
+
exports.grafanaAPIClient = grafanaAPIClient;
|
package/dist/index.js
CHANGED
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
exports.selectors = exports.expect = exports.test = exports.resolveSelectors = exports.AppPage = exports.PluginConfigPage = exports.AppConfigPage = exports.VariablePage = exports.VariableEditPage = exports.PanelEditPage = exports.GrafanaPage = exports.ExplorePage = exports.DataSourceConfigPage = exports.DashboardPage = exports.AnnotationPage = exports.AnnotationEditPage = exports.TimeRange = exports.Panel = exports.DataSourcePicker = void 0;
|
|
18
18
|
const test_1 = require("@playwright/test");
|
|
19
19
|
const annotationEditPage_1 = require("./fixtures/annotationEditPage");
|
|
20
|
+
const grafanaAPIClient_1 = require("./fixtures/grafanaAPIClient");
|
|
20
21
|
const createDataSource_1 = require("./fixtures/commands/createDataSource");
|
|
21
22
|
const createDataSourceConfigPage_1 = require("./fixtures/commands/createDataSourceConfigPage");
|
|
22
23
|
const createUser_1 = require("./fixtures/commands/createUser");
|
|
@@ -86,6 +87,7 @@ exports.test = test_1.test.extend({
|
|
|
86
87
|
selectors: selectors_1.selectors,
|
|
87
88
|
grafanaVersion: grafanaVersion_1.grafanaVersion,
|
|
88
89
|
login: login_1.login,
|
|
90
|
+
grafanaAPIClient: grafanaAPIClient_1.grafanaAPIClient,
|
|
89
91
|
createDataSourceConfigPage: createDataSourceConfigPage_1.createDataSourceConfigPage,
|
|
90
92
|
page: page_1.page,
|
|
91
93
|
dashboardPage: dashboardPage_1.dashboardPage,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { APIRequestContext } from '@playwright/test';
|
|
2
|
+
import { DataSourceSettings, User } from '../types';
|
|
3
|
+
export declare class GrafanaAPIClient {
|
|
4
|
+
private request;
|
|
5
|
+
constructor(request: APIRequestContext);
|
|
6
|
+
getUserIdByUsername(userName: string): Promise<any>;
|
|
7
|
+
createUser(user: User): Promise<void>;
|
|
8
|
+
getDataSourceSettingsByUID(uid: string): Promise<DataSourceSettings<{}, {}>>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GrafanaAPIClient = void 0;
|
|
4
|
+
class GrafanaAPIClient {
|
|
5
|
+
request;
|
|
6
|
+
constructor(request) {
|
|
7
|
+
this.request = request;
|
|
8
|
+
}
|
|
9
|
+
async getUserIdByUsername(userName) {
|
|
10
|
+
const getUserIdByUserNameReq = await this.request.get(`/api/users/lookup?loginOrEmail=${userName}`);
|
|
11
|
+
const json = await getUserIdByUserNameReq.json();
|
|
12
|
+
return json.id;
|
|
13
|
+
}
|
|
14
|
+
async createUser(user) {
|
|
15
|
+
const createUserReq = await this.request.post(`/api/admin/users`, {
|
|
16
|
+
data: {
|
|
17
|
+
name: user?.user,
|
|
18
|
+
login: user?.user,
|
|
19
|
+
password: user?.password,
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
let userId;
|
|
23
|
+
if (createUserReq.ok()) {
|
|
24
|
+
const respJson = await createUserReq.json();
|
|
25
|
+
userId = respJson.id;
|
|
26
|
+
}
|
|
27
|
+
else if (createUserReq.status() === 412) {
|
|
28
|
+
// user already exists
|
|
29
|
+
userId = await this.getUserIdByUsername(user?.user);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
throw new Error(`Could not create user '${user?.user}'. Find information on how user can be managed in the plugin-e2e docs: https://grafana.com/developers/plugin-tools/e2e-test-a-plugin/use-authentication#managing-users : ${await createUserReq.text()}`);
|
|
33
|
+
}
|
|
34
|
+
if (user.role) {
|
|
35
|
+
const updateRoleReq = await this.request.patch(`/api/org/users/${userId}`, {
|
|
36
|
+
data: { role: user.role },
|
|
37
|
+
});
|
|
38
|
+
if (!updateRoleReq.ok()) {
|
|
39
|
+
throw new Error(`Could not assign role '${user.role}' to user '${user.user}': ${await updateRoleReq.text()}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async getDataSourceSettingsByUID(uid) {
|
|
44
|
+
const response = await this.request.get(`/api/datasources/uid/${uid}`);
|
|
45
|
+
if (!response.ok()) {
|
|
46
|
+
throw new Error(`Failed to get datasource by uid: ${response.statusText()}. If you're using a provisioned data source, make sure it has a UID`);
|
|
47
|
+
}
|
|
48
|
+
const settings = await response.json();
|
|
49
|
+
return settings;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.GrafanaAPIClient = GrafanaAPIClient;
|
package/dist/types.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { PanelEditPage } from './models/pages/PanelEditPage';
|
|
|
10
10
|
import { VariableEditPage } from './models/pages/VariableEditPage';
|
|
11
11
|
import { VariablePage } from './models/pages/VariablePage';
|
|
12
12
|
import { AlertRuleEditPage } from './models/pages/AlertRuleEditPage';
|
|
13
|
+
import { GrafanaAPIClient } from './models/GrafanaAPIClient';
|
|
13
14
|
export type PluginOptions = {
|
|
14
15
|
/**
|
|
15
16
|
* When using the readProvisioning fixture, files will be read from this directory. If no directory is provided,
|
|
@@ -171,6 +172,17 @@ export type PluginFixture = {
|
|
|
171
172
|
* Function that checks if a feature toggle is enabled. Only works for frontend feature toggles.
|
|
172
173
|
*/
|
|
173
174
|
isFeatureToggleEnabled<T = object>(featureToggle: keyof T): Promise<boolean>;
|
|
175
|
+
/**
|
|
176
|
+
* Client that allows you to use certain endpoints in the Grafana http API.
|
|
177
|
+
*
|
|
178
|
+
The GrafanaAPIClient doesn't call the Grafana HTTP API on behalf of the logged in user -
|
|
179
|
+
* it uses the {@link types.grafanaAPICredentials} credentials. grafanaAPICredentials defaults to admin:admin, but you may override this
|
|
180
|
+
* by specifying grafanaAPICredentials in the playwright config options.
|
|
181
|
+
*
|
|
182
|
+
* Note that storage state for the admin client is not persisted throughout the test suite. For every test where the grafanaAPICredentials fixtures is used,
|
|
183
|
+
* new storage state is created.
|
|
184
|
+
*/
|
|
185
|
+
grafanaAPIClient: GrafanaAPIClient;
|
|
174
186
|
/**
|
|
175
187
|
* Isolated {@link DashboardPage} instance for each test.
|
|
176
188
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grafana/plugin-e2e",
|
|
3
|
-
"version": "1.6.0
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"start": "cls || clear"
|
|
56
56
|
}
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "0d126394b9c16cdbd47e3749cb25f258a233ac1a"
|
|
59
59
|
}
|