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

Commit3f21cb8

Browse files
authored
fix: update API code to use Axios instances (#13029)
* fix: update API code to use Axios instance* docs: fix typo* fix: update all global axios imports to use Coder instance* fix: remove needless import* fix: update import order* refactor: rename coderAxiosInstance to axiosInstance* docs: update variable reference in FE contributing docs
1 parentdd27a8a commit3f21cb8

File tree

8 files changed

+259
-177
lines changed

8 files changed

+259
-177
lines changed

‎docs/contributing/frontend.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ example below:
152152
exportconst getAgentListeningPorts=async (
153153
agentID:string,
154154
):Promise<TypesGen.ListeningPortsResponse>=> {
155-
const response=awaitaxios.get(
155+
const response=awaitaxiosInstance.get(
156156
`/api/v2/workspaceagents/${agentID}/listening-ports`,
157157
);
158158
returnresponse.data;

‎site/e2e/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import{typeBrowserContext,expect,typePage,test}from"@playwright/test";
2-
importaxiosfrom"axios";
32
import{typeChildProcess,exec,spawn}from"child_process";
43
import{randomUUID}from"crypto";
54
importexpressfrom"express";
65
importcapitalizefrom"lodash/capitalize";
76
importpathfrom"path";
87
import*assshfrom"ssh2";
98
import{Duplex}from"stream";
9+
import{axiosInstance}from"api/api";
1010
importtype{
1111
WorkspaceBuildParameter,
1212
UpdateTemplateMeta,
@@ -398,7 +398,7 @@ export const waitUntilUrlIsNotResponding = async (url: string) => {
398398

399399
while(retries<maxRetries){
400400
try{
401-
awaitaxios.get(url);
401+
awaitaxiosInstance.get(url);
402402
}catch(error){
403403
return;
404404
}

‎site/e2e/reporter.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import type {
88
Reporter,
99
TestError,
1010
}from"@playwright/test/reporter";
11-
importaxiosfrom"axios";
1211
import*asfsfrom"fs/promises";
1312
importtype{Writable}from"stream";
13+
import{axiosInstance}from"api/api";
1414
import{coderdPProfPort,enterpriseLicense}from"./constants";
1515

1616
classCoderReporterimplementsReporter{
@@ -136,9 +136,10 @@ class CoderReporter implements Reporter {
136136
constlogLines=(chunk:string):string[]=>chunk.trimEnd().split("\n");
137137

138138
constexportDebugPprof=async(outputFile:string)=>{
139-
constresponse=awaitaxios.get(
139+
constresponse=awaitaxiosInstance.get(
140140
`http://127.0.0.1:${coderdPProfPort}/debug/pprof/goroutine?debug=1`,
141141
);
142+
142143
if(response.status!==200){
143144
thrownewError(`Error: Received status code${response.status}`);
144145
}

‎site/src/api/api.test.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
importaxiosfrom"axios";
21
import{
32
MockTemplate,
43
MockTemplateVersionParameter1,
@@ -8,6 +7,7 @@ import {
87
MockWorkspaceBuildParameter1,
98
}from"testHelpers/entities";
109
import*asapifrom"./api";
10+
import{axiosInstance}from"./api";
1111
importtype*asTypesGenfrom"./typesGenerated";
1212

1313
describe("api.ts",()=>{
@@ -17,13 +17,16 @@ describe("api.ts", () => {
1717
constloginResponse:TypesGen.LoginWithPasswordResponse={
1818
session_token:"abc_123_test",
1919
};
20-
jest.spyOn(axios,"post").mockResolvedValueOnce({data:loginResponse});
20+
21+
jest
22+
.spyOn(axiosInstance,"post")
23+
.mockResolvedValueOnce({data:loginResponse});
2124

2225
// when
2326
constresult=awaitapi.login("test","123");
2427

2528
// then
26-
expect(axios.post).toHaveBeenCalled();
29+
expect(axiosInstance.post).toHaveBeenCalled();
2730
expect(result).toStrictEqual(loginResponse);
2831
});
2932

@@ -38,7 +41,7 @@ describe("api.ts", () => {
3841
constaxiosMockPost=jest.fn().mockImplementationOnce(()=>{
3942
returnPromise.reject(expectedError);
4043
});
41-
axios.post=axiosMockPost;
44+
axiosInstance.post=axiosMockPost;
4245

4346
try{
4447
awaitapi.login("test","123");
@@ -54,7 +57,7 @@ describe("api.ts", () => {
5457
constaxiosMockPost=jest.fn().mockImplementationOnce(()=>{
5558
returnPromise.resolve();
5659
});
57-
axios.post=axiosMockPost;
60+
axiosInstance.post=axiosMockPost;
5861

5962
// when
6063
awaitapi.logout();
@@ -73,7 +76,8 @@ describe("api.ts", () => {
7376
constaxiosMockPost=jest.fn().mockImplementationOnce(()=>{
7477
returnPromise.reject(expectedError);
7578
});
76-
axios.post=axiosMockPost;
79+
80+
axiosInstance.post=axiosMockPost;
7781

7882
try{
7983
awaitapi.logout();
@@ -92,7 +96,8 @@ describe("api.ts", () => {
9296
constaxiosMockPost=jest.fn().mockImplementationOnce(()=>{
9397
returnPromise.resolve({data:apiKeyResponse});
9498
});
95-
axios.post=axiosMockPost;
99+
100+
axiosInstance.post=axiosMockPost;
96101

97102
// when
98103
constresult=awaitapi.getApiKey();
@@ -112,7 +117,8 @@ describe("api.ts", () => {
112117
constaxiosMockPost=jest.fn().mockImplementationOnce(()=>{
113118
returnPromise.reject(expectedError);
114119
});
115-
axios.post=axiosMockPost;
120+
121+
axiosInstance.post=axiosMockPost;
116122

117123
try{
118124
awaitapi.getApiKey();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp