• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

decentraland / decentraland-gatsby / 27959714352

22 Jun 2026 02:21PM UTC coverage: 55.902% (-1.0%) from 56.918%
27959714352

push

github

web-flow
Merge pull request #1324 from decentraland/fix/flaky-catalyst-test

fix: rename Catalyst.test.ts to follow integration test convention

500 of 1105 branches covered (45.25%)

Branch coverage included in aggregate %.

1257 of 2038 relevant lines covered (61.68%)

11.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

40.0
/src/utils/api/Options.ts
1
export type RequestOptions = Omit<RequestInit, 'headers'> &
2
  Partial<{
3
    headers: Record<string, string>
4
  }>
5

6
export type RequestTimeoutOptions = Partial<{
7
  timeout: number
8
  timeoutFallback: any
9
}>
10

11
export type RequestAuthorizationOptions = Partial<{
12
  identity: boolean
13
  sign: boolean
14
  optional: boolean
15
}>
16

17
export default class Options {
88✔
18
  #options: RequestOptions = {}
116✔
19
  #authorization: RequestAuthorizationOptions = {}
116✔
20
  #timeout: RequestTimeoutOptions = {}
116✔
21
  #metadata: Record<string, string | number> = {}
116✔
22

23
  constructor(options: RequestOptions = {}) {
×
24
    this.#options = options
116✔
25
  }
26

27
  merge(options: Options) {
28
    const raw = options.toObject()
28✔
29
    const newOptions = {
28✔
30
      ...this.#options,
31
      ...raw,
32
    }
33

34
    if (this.#options.headers || raw.headers) {
28✔
35
      newOptions.headers = {
×
36
        ...this.#options.headers,
37
        ...raw.headers,
38
      }
39
    }
40

41
    const result = new Options(newOptions)
28✔
42
    result.#authorization = {
28✔
43
      ...this.#authorization,
44
      ...options.#authorization,
45
    }
46

47
    result.#metadata = {
28✔
48
      ...this.#metadata,
49
      ...options.#metadata,
50
    }
51

52
    result.#timeout = {
28✔
53
      ...this.#timeout,
54
      ...options.#timeout,
55
    }
56

57
    return result
28✔
58
  }
59

60
  set(options: Omit<RequestOptions, 'headers' | 'body'> = {}) {
×
61
    const newOptions = {
×
62
      ...this.#options,
63
      ...options,
64
    }
65

66
    if (this.#options.headers) {
×
67
      newOptions.headers = this.#options.headers
×
68
    }
69

70
    if (this.#options.body) {
×
71
      newOptions.body = this.#options.body
×
72
    }
73

74
    this.#options = newOptions
×
75

76
    return this
×
77
  }
78

79
  /**
80
   * Timeout a request using an [AbortController](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) object.
81
   *
82
   * If the remote servers doesn't repond in the timeframe the request Request
83
   * will fail with a 408 http error and will internally abort the request to
84
   * prevent memory leaks.
85
   *
86
   * If you want to return a fallback value instead of failing, use the `timeoutWithFallback`
87
   * method instead.
88
   */
89
  timeout(timeout: number) {
90
    this.#timeout.timeout = Math.max(0, timeout)
10✔
91
    return this
10✔
92
  }
93

94
  /**
95
   * Timeout a request using an [AbortController](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) object.
96
   *
97
   * If the remote servers doesn't repond in the timeframe the request Request
98
   * will return the fallback parameter instead of failing and will internally
99
   * abort the request to prevent memory leaks.
100
   */
101
  timeoutWithFallback(timeout: number, fallback: any) {
102
    this.timeout(timeout)
6✔
103
    this.#timeout.timeoutFallback = fallback
6✔
104
    return this
6✔
105
  }
106

107
  authorization(
108
    options: RequestAuthorizationOptions = { identity: true, optional: true }
×
109
  ) {
110
    this.#authorization = options
×
111
    return this
×
112
  }
113

114
  header(key: string, value: string) {
115
    if (!this.#options.headers) {
×
116
      this.#options.headers = {}
×
117
    }
118

119
    key = key.toLowerCase()
×
120
    if (this.#options.headers[key]) {
×
121
      console.warn(
×
122
        `Can not set header "${key}" as "${value}" because is already defined as "${
123
          this.#options.headers[key]
124
        }"`
125
      )
126
    } else {
127
      this.#options.headers[key] = value
×
128
    }
129

130
    return this
×
131
  }
132

133
  headers(headers: Record<string, string>) {
134
    Object.keys(headers).forEach((key) =>
×
135
      this.header(key.toLowerCase(), headers[key])
×
136
    )
137
    return this
×
138
  }
139

140
  method(method: string) {
141
    this.#options.method = method
14✔
142
    return this
14✔
143
  }
144

145
  getMethod() {
146
    return this.#options.method || 'GET'
×
147
  }
148

149
  metadata(data: Record<string, string | number>) {
150
    this.#metadata = {
×
151
      ...this.#metadata,
152
      ...data,
153
    }
154

155
    return this
×
156
  }
157

158
  getMetadata(): Record<string, string | number> {
159
    return this.#metadata
×
160
  }
161

162
  json(data: any) {
163
    this.header('content-type', 'application/json')
×
164
    this.#options.body = JSON.stringify(data)
×
165
    return this
×
166
  }
167

168
  getAuthorization() {
169
    return this.#authorization
56✔
170
  }
171

172
  getTimeout() {
173
    return this.#timeout
28✔
174
  }
175

176
  toObject(extend: RequestOptions = {}) {
25✔
177
    return { ...this.#options, ...extend }
56✔
178
  }
179
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc