Skip to content

Commit bfc964c

Browse files
fix linter
Signed-off-by: Thomas Poignant <[email protected]>
1 parent 248696d commit bfc964c

File tree

5 files changed

+97
-105
lines changed

5 files changed

+97
-105
lines changed

libs/providers/go-feature-flag/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
"@ljharb/eslint-config": "^21.2.0",
1818
"eslint-plugin-tree-shaking": "^1.12.2"
1919
}
20-
}
20+
}

libs/providers/go-feature-flag/project.json

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,11 @@
2929
},
3030
"lint": {
3131
"executor": "@nx/eslint:lint",
32-
"outputs": [
33-
"{options.outputFile}"
34-
]
32+
"outputs": ["{options.outputFile}"]
3533
},
3634
"test": {
3735
"executor": "@nx/jest:jest",
38-
"outputs": [
39-
"{workspaceRoot}/coverage/libs/providers/go-feature-flag"
40-
],
36+
"outputs": ["{workspaceRoot}/coverage/libs/providers/go-feature-flag"],
4137
"options": {
4238
"jestConfig": "libs/providers/go-feature-flag/jest.config.ts"
4339
},
@@ -49,9 +45,7 @@
4945
},
5046
"package": {
5147
"executor": "@nx/rollup:rollup",
52-
"outputs": [
53-
"{options.outputPath}"
54-
],
48+
"outputs": ["{options.outputPath}"],
5549
"dependsOn": [
5650
{
5751
"target": "copy-wasm"
@@ -66,10 +60,7 @@
6660
"generateExportsField": true,
6761
"umdName": "go-feature-flag",
6862
"external": "all",
69-
"format": [
70-
"cjs",
71-
"esm"
72-
],
63+
"format": ["cjs", "esm"],
7364
"assets": [
7465
{
7566
"glob": "package.json",
@@ -91,4 +82,4 @@
9182
}
9283
},
9384
"tags": []
94-
}
85+
}

libs/providers/go-feature-flag/src/lib/service/api.test.ts

Lines changed: 1 addition & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -9,96 +9,7 @@ import {
99
ImpossibleToSendDataToTheCollectorException,
1010
InvalidOptionsException,
1111
} from '../exception';
12-
13-
// Mock Response class
14-
class MockResponse {
15-
public status: number;
16-
public headers: Headers;
17-
public body: string;
18-
public ok: boolean;
19-
20-
constructor(status: number, body = '', headers: Record<string, string> = {}) {
21-
this.status = status;
22-
this.body = body;
23-
this.headers = new Headers(headers);
24-
this.ok = status >= 200 && status < 300;
25-
}
26-
27-
async text(): Promise<string> {
28-
return this.body;
29-
}
30-
31-
async json(): Promise<any> {
32-
return JSON.parse(this.body);
33-
}
34-
}
35-
36-
// Mock fetch implementation
37-
class MockFetch {
38-
private responses: Map<string, MockResponse> = new Map();
39-
private lastRequest?: {
40-
url: string;
41-
options: RequestInit;
42-
};
43-
44-
setResponse(url: string, response: MockResponse): void {
45-
this.responses.set(url, response);
46-
}
47-
48-
setResponseByStatus(status: string, response: MockResponse): void {
49-
this.responses.set(status, response);
50-
}
51-
52-
getLastRequest() {
53-
return this.lastRequest;
54-
}
55-
56-
reset(): void {
57-
this.responses.clear();
58-
this.lastRequest = undefined;
59-
}
60-
61-
async fetch(url: string, options: RequestInit = {}): Promise<Response> {
62-
this.lastRequest = { url, options };
63-
64-
// Handle AbortSignal for timeout tests
65-
if (options.signal) {
66-
const signal = options.signal as AbortSignal;
67-
if (signal.aborted) {
68-
throw new Error('Request aborted');
69-
}
70-
71-
// For timeout tests, we'll simulate a delay and then check if aborted
72-
if (url.includes('timeout')) {
73-
await new Promise((resolve) => setTimeout(resolve, 100));
74-
if (signal.aborted) {
75-
throw new Error('Request aborted');
76-
}
77-
}
78-
}
79-
80-
// Check if we have a specific response for this URL
81-
if (this.responses.has(url)) {
82-
return this.responses.get(url)! as unknown as Response;
83-
}
84-
85-
// Check if we have a response by status code
86-
const statusMatch = url.match(/(\d{3})/);
87-
if (statusMatch && this.responses.has(statusMatch[1])) {
88-
return this.responses.get(statusMatch[1])! as unknown as Response;
89-
}
90-
91-
// Check if we have a response by status code in the responses map
92-
for (const [key, response] of this.responses.entries()) {
93-
if (key.match(/^\d{3}$/) && response.status === parseInt(key)) {
94-
return response as unknown as Response;
95-
}
96-
}
97-
98-
// Default response
99-
return new MockResponse(200, '{}') as unknown as Response;
100-
}
101-
}
12+
import { MockFetch, MockResponse } from '../testutil/mock-fetch';
10213

10314
describe('GoFeatureFlagApi', () => {
10415
let mockFetch: MockFetch;
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// Mock Response class
2+
export class MockResponse {
3+
public status: number;
4+
public headers: Headers;
5+
public body: string;
6+
public ok: boolean;
7+
8+
constructor(status: number, body = '', headers: Record<string, string> = {}) {
9+
this.status = status;
10+
this.body = body;
11+
this.headers = new Headers(headers);
12+
this.ok = status >= 200 && status < 300;
13+
}
14+
15+
async text(): Promise<string> {
16+
return this.body;
17+
}
18+
19+
async json(): Promise<any> {
20+
return JSON.parse(this.body);
21+
}
22+
}
23+
24+
// Mock fetch implementation
25+
export class MockFetch {
26+
private responses: Map<string, MockResponse> = new Map();
27+
private lastRequest?: {
28+
url: string;
29+
options: RequestInit;
30+
};
31+
32+
setResponse(url: string, response: MockResponse): void {
33+
this.responses.set(url, response);
34+
}
35+
36+
setResponseByStatus(status: string, response: MockResponse): void {
37+
this.responses.set(status, response);
38+
}
39+
40+
getLastRequest() {
41+
return this.lastRequest;
42+
}
43+
44+
reset(): void {
45+
this.responses.clear();
46+
this.lastRequest = undefined;
47+
}
48+
49+
async fetch(url: string, options: RequestInit = {}): Promise<Response> {
50+
this.lastRequest = { url, options };
51+
52+
// Handle AbortSignal for timeout tests
53+
if (options.signal) {
54+
const signal = options.signal as AbortSignal;
55+
if (signal.aborted) {
56+
throw new Error('Request aborted');
57+
}
58+
59+
// For timeout tests, we'll simulate a delay and then check if aborted
60+
if (url.includes('timeout')) {
61+
await new Promise((resolve) => setTimeout(resolve, 100));
62+
if (signal.aborted) {
63+
throw new Error('Request aborted');
64+
}
65+
}
66+
}
67+
68+
// Check if we have a specific response for this URL
69+
if (this.responses.has(url)) {
70+
return this.responses.get(url)! as unknown as Response;
71+
}
72+
73+
// Check if we have a response by status code
74+
const statusMatch = url.match(/(\d{3})/);
75+
if (statusMatch && this.responses.has(statusMatch[1])) {
76+
return this.responses.get(statusMatch[1])! as unknown as Response;
77+
}
78+
79+
// Check if we have a response by status code in the responses map
80+
for (const [key, response] of this.responses.entries()) {
81+
if (key.match(/^\d{3}$/) && response.status === parseInt(key)) {
82+
return response as unknown as Response;
83+
}
84+
}
85+
86+
// Default response
87+
return new MockResponse(200, '{}') as unknown as Response;
88+
}
89+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,4 @@
100100
"verdaccio": "^5.0.4"
101101
}
102102
}
103+

0 commit comments

Comments
 (0)