Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

refactor: improve test isolation for Axios API logic#13125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Parkreiner merged 9 commits intomainfrommes/axios-instance-isolation
May 12, 2024
Merged
Show file tree
Hide file tree
Changes fromall 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
17 changes: 9 additions & 8 deletionssite/e2e/api.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
import type { Page } from "@playwright/test";
import { expect } from "@playwright/test";
import { formatDuration, intervalToDuration } from "date-fns";
import* asAPI from "api/api";
import{ type DeploymentConfig,API } from "api/api";
import type { SerpentOption } from "api/typesGenerated";
import { coderPort } from "./constants";
import { findSessionToken, randomName } from "./helpers";
Expand All@@ -15,6 +15,7 @@ export const setupApiCalls = async (page: Page) => {
} catch {
// If this fails, we have an unauthenticated client.
}

API.setHost(`http://127.0.0.1:${coderPort}`);
};

Expand DownExpand Up@@ -53,7 +54,7 @@ export const createGroup = async (orgId: string) => {

export async function verifyConfigFlagBoolean(
page: Page,
config:API.DeploymentConfig,
config: DeploymentConfig,
flag: string,
) {
const opt = findConfigOption(config, flag);
Expand All@@ -68,7 +69,7 @@ export async function verifyConfigFlagBoolean(

export async function verifyConfigFlagNumber(
page: Page,
config:API.DeploymentConfig,
config: DeploymentConfig,
flag: string,
) {
const opt = findConfigOption(config, flag);
Expand All@@ -80,7 +81,7 @@ export async function verifyConfigFlagNumber(

export async function verifyConfigFlagString(
page: Page,
config:API.DeploymentConfig,
config: DeploymentConfig,
flag: string,
) {
const opt = findConfigOption(config, flag);
Expand All@@ -100,7 +101,7 @@ export async function verifyConfigFlagEmpty(page: Page, flag: string) {

export async function verifyConfigFlagArray(
page: Page,
config:API.DeploymentConfig,
config: DeploymentConfig,
flag: string,
) {
const opt = findConfigOption(config, flag);
Expand All@@ -116,7 +117,7 @@ export async function verifyConfigFlagArray(

export async function verifyConfigFlagEntries(
page: Page,
config:API.DeploymentConfig,
config: DeploymentConfig,
flag: string,
) {
const opt = findConfigOption(config, flag);
Expand All@@ -138,7 +139,7 @@ export async function verifyConfigFlagEntries(

export async function verifyConfigFlagDuration(
page: Page,
config:API.DeploymentConfig,
config: DeploymentConfig,
flag: string,
) {
const opt = findConfigOption(config, flag);
Expand All@@ -157,7 +158,7 @@ export async function verifyConfigFlagDuration(
}

export function findConfigOption(
config:API.DeploymentConfig,
config: DeploymentConfig,
flag: string,
): SerpentOption {
const opt = config.options.find((option) => option.flag === flag);
Expand Down
4 changes: 2 additions & 2 deletionssite/e2e/global.setup.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
import { expect, test } from "@playwright/test";
import {hasFirstUser } from "api/api";
import {API } from "api/api";
import { Language } from "pages/CreateUserPage/CreateUserForm";
import { setupApiCalls } from "./api";
import * as constants from "./constants";
Expand All@@ -9,7 +9,7 @@ import { storageState } from "./playwright.config";
test("setup deployment", async ({ page }) => {
await page.goto("/", { waitUntil: "domcontentloaded" });
await setupApiCalls(page);
const exists = await hasFirstUser();
const exists = awaitAPI.hasFirstUser();
// First user already exists, abort early. All tests execute this as a dependency,
// if you run multiple tests in the UI, this will fail unless we check this.
if (exists) {
Expand Down
3 changes: 2 additions & 1 deletionsite/e2e/helpers.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,7 @@ import capitalize from "lodash/capitalize";
import path from "path";
import * as ssh from "ssh2";
import { Duplex } from "stream";
import {axiosInstance } from "api/api";
import {API } from "api/api";
import type {
WorkspaceBuildParameter,
UpdateTemplateMeta,
Expand DownExpand Up@@ -423,6 +423,7 @@ export const waitUntilUrlIsNotResponding = async (url: string) => {
const retryIntervalMs = 1000;
let retries = 0;

const axiosInstance = API.getAxiosInstance();
while (retries < maxRetries) {
try {
await axiosInstance.get(url);
Expand Down
3 changes: 2 additions & 1 deletionsite/e2e/reporter.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,7 +10,7 @@ import type {
} from "@playwright/test/reporter";
import * as fs from "fs/promises";
import type { Writable } from "stream";
import {axiosInstance } from "api/api";
import {API } from "api/api";
import { coderdPProfPort, enterpriseLicense } from "./constants";

class CoderReporter implements Reporter {
Expand DownExpand Up@@ -143,6 +143,7 @@ const logLines = (chunk: string | Buffer): string[] => {
};

const exportDebugPprof = async (outputFile: string) => {
const axiosInstance = API.getAxiosInstance();
const response = await axiosInstance.get(
`http://127.0.0.1:${coderdPProfPort}/debug/pprof/goroutine?debug=1`,
);
Expand Down
2 changes: 1 addition & 1 deletionsite/e2e/tests/deployment/general.spec.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
import { expect, test } from "@playwright/test";
import* asAPI from "api/api";
import{API } from "api/api";
import { setupApiCalls } from "../../api";
import { e2eFakeExperiment1, e2eFakeExperiment2 } from "../../constants";

Expand Down
4 changes: 2 additions & 2 deletionssite/e2e/tests/deployment/network.spec.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
import { test } from "@playwright/test";
import {getDeploymentConfig } from "api/api";
import {API } from "api/api";
import {
setupApiCalls,
verifyConfigFlagArray,
Expand All@@ -11,7 +11,7 @@ import {

test("enabled network settings", async ({ page }) => {
await setupApiCalls(page);
const config = await getDeploymentConfig();
const config = awaitAPI.getDeploymentConfig();

await page.goto("/deployment/network", { waitUntil: "domcontentloaded" });

Expand Down
4 changes: 2 additions & 2 deletionssite/e2e/tests/deployment/observability.spec.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
import { test } from "@playwright/test";
import {getDeploymentConfig } from "api/api";
import {API } from "api/api";
import {
setupApiCalls,
verifyConfigFlagArray,
Expand All@@ -11,7 +11,7 @@ import {

test("enabled observability settings", async ({ page }) => {
await setupApiCalls(page);
const config = await getDeploymentConfig();
const config = awaitAPI.getDeploymentConfig();

await page.goto("/deployment/observability", {
waitUntil: "domcontentloaded",
Expand Down
7 changes: 3 additions & 4 deletionssite/e2e/tests/deployment/security.spec.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
import type { Page } from "@playwright/test";
import { expect, test } from "@playwright/test";
import type * as API from "api/api";
import { getDeploymentConfig } from "api/api";
import { type DeploymentConfig, API } from "api/api";
import {
findConfigOption,
setupApiCalls,
Expand All@@ -12,7 +11,7 @@ import {

test("enabled security settings", async ({ page }) => {
await setupApiCalls(page);
const config = await getDeploymentConfig();
const config = awaitAPI.getDeploymentConfig();

await page.goto("/deployment/security", { waitUntil: "domcontentloaded" });

Expand All@@ -31,7 +30,7 @@ test("enabled security settings", async ({ page }) => {

async function verifyStrictTransportSecurity(
page: Page,
config:API.DeploymentConfig,
config: DeploymentConfig,
) {
const flag = "strict-transport-security";
const opt = findConfigOption(config, flag);
Expand Down
4 changes: 2 additions & 2 deletionssite/e2e/tests/deployment/userAuth.spec.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
import { test } from "@playwright/test";
import {getDeploymentConfig } from "api/api";
import {API } from "api/api";
import {
setupApiCalls,
verifyConfigFlagArray,
Expand All@@ -10,7 +10,7 @@ import {

test("login with OIDC", async ({ page }) => {
await setupApiCalls(page);
const config = await getDeploymentConfig();
const config = awaitAPI.getDeploymentConfig();

await page.goto("/deployment/userauth", { waitUntil: "domcontentloaded" });

Expand Down
4 changes: 2 additions & 2 deletionssite/e2e/tests/deployment/workspaceProxies.spec.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
import { test, expect, type Page } from "@playwright/test";
import {createWorkspaceProxy } from "api/api";
import {API } from "api/api";
import { setupApiCalls } from "../../api";
import { coderPort, workspaceProxyPort } from "../../constants";
import { randomName, requiresEnterpriseLicense } from "../../helpers";
Expand DownExpand Up@@ -34,7 +34,7 @@ test("custom proxy is online", async ({ page }) => {
const proxyName = randomName();

// Register workspace proxy
const proxyResponse = await createWorkspaceProxy({
const proxyResponse = awaitAPI.createWorkspaceProxy({
name: proxyName,
display_name: "",
icon: "/emojis/1f1e7-1f1f7.png",
Expand Down
2 changes: 1 addition & 1 deletionsite/e2e/tests/groups/removeMember.spec.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
import { test, expect } from "@playwright/test";
import* asAPI from "api/api";
import{API } from "api/api";
import {
createGroup,
createUser,
Expand Down
8 changes: 4 additions & 4 deletionssite/e2e/tests/templates/updateTemplateSchedule.spec.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
import { expect, test } from "@playwright/test";
import {createTemplate, createTemplateVersion, getTemplate } from "api/api";
import {API } from "api/api";
import { getCurrentOrgId, setupApiCalls } from "../../api";
import { beforeCoderTest } from "../../hooks";

Expand All@@ -11,14 +11,14 @@ test("update template schedule settings without override other settings", async
}) => {
await setupApiCalls(page);
const orgId = await getCurrentOrgId();
const templateVersion = await createTemplateVersion(orgId, {
const templateVersion = awaitAPI.createTemplateVersion(orgId, {
storage_method: "file" as const,
provisioner: "echo",
user_variable_values: [],
example_id: "docker",
tags: {},
});
const template = await createTemplate(orgId, {
const template = awaitAPI.createTemplate(orgId, {
name: "test-template",
display_name: "Test Template",
template_version_id: templateVersion.id,
Expand All@@ -33,7 +33,7 @@ test("update template schedule settings without override other settings", async
await page.getByRole("button", { name: "Submit" }).click();
await expect(page.getByText("Template updated successfully")).toBeVisible();

const updatedTemplate = await getTemplate(template.id);
const updatedTemplate = awaitAPI.getTemplate(template.id);
// Validate that the template data remains consistent, with the exception of
// the 'default_ttl_ms' field (updated during the test) and the 'updated at'
// field (automatically updated by the backend).
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp