Skip to content

Commit

Permalink
test: select tenant use env
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan_Chen committed Jul 24, 2024
1 parent 8326d0f commit acd1189
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/test/e2e/tests/selectAzureTenant.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT license.

import { expect, test } from '../baseTest';
import { APICenter, Timeout, VSCode, TestENV } from '../utils/constants';
import { APICenter, TestENV, Timeout, VSCode } from '../utils/constants';
import VscodeOperator from '../utils/vscodeOperator';

test('select Tenant', async ({ workbox }) => {
Expand All @@ -13,7 +13,7 @@ test('select Tenant', async ({ workbox }) => {
// select tenant
expect(await VscodeOperator.isTreeItemExist(workbox, APICenter.SELECT_TENANT)).toBeTruthy();
await VscodeOperator.clickTreeItem(workbox, APICenter.SELECT_TENANT);
await VscodeOperator.selectOptionByIndex(workbox, 0);
await VscodeOperator.selectOptionByName(workbox, TestENV.AZURE_TENANT_NAME!);
// check subscription
const isSelectSubsExist = await VscodeOperator.isTreeItemExist(workbox, APICenter.SELECT_SUBS);
if (isSelectSubsExist) {
Expand Down
22 changes: 18 additions & 4 deletions src/test/e2e/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,24 @@ import dotenv from "dotenv";
import fs from "fs";
dotenv.config();

fs.existsSync(".env.local") && fs.readFileSync(".env.local", "utf-8").split("\n").forEach((line) => {
const [key, value] = line.split("=");
process.env[key] = value;
});
if (fs.existsSync(".env.local")) {
const lines = fs.readFileSync(".env.local", "utf-8").split("\n");
lines.forEach((line) => {
const indexOfEquals = line.indexOf("=");
if (indexOfEquals !== -1) {
const key = line.slice(0, indexOfEquals).trim();
let value = line.slice(indexOfEquals + 1).trim();

// Remove surrounding quotes if present
if ((value.startsWith('"') && value.endsWith('"')) ||
(value.startsWith("'") && value.endsWith("'"))) {
value = value.slice(1, -1);
}

process.env[key] = value;
}
});
}

export class Timeout {
public static readonly CLICK_WAIT = 1000;
Expand Down

0 comments on commit acd1189

Please sign in to comment.