|
| 1 | +import { error, logRaw, setLogLevel } from "@cloudflare/cli"; |
1 | 2 | import { Logger } from "../logger"; |
2 | | -import { mockConsoleMethods } from "./helpers/mock-console"; |
| 3 | +import { mockCLIOutput, mockConsoleMethods } from "./helpers/mock-console"; |
3 | 4 |
|
4 | 5 | describe("logger", () => { |
5 | 6 | const std = mockConsoleMethods(); |
@@ -238,4 +239,84 @@ describe("logger", () => { |
238 | 239 | expect(std.info).toMatchInlineSnapshot(`"This is a once message"`); |
239 | 240 | }); |
240 | 241 | }); |
| 242 | + |
| 243 | +describe("@cloudflare/cli logRaw", () => { |
| 244 | +const cliOut = mockCLIOutput(); |
| 245 | + |
| 246 | +it("should output at log level", () => { |
| 247 | +setLogLevel("log"); |
| 248 | +logRaw("This is a logRaw message"); |
| 249 | +expect(cliOut.stdout).toMatchInlineSnapshot( |
| 250 | +`"This is a logRaw message\n"` |
| 251 | +); |
| 252 | +}); |
| 253 | + |
| 254 | +it("should not output when log level is set to warn", () => { |
| 255 | +setLogLevel("warn"); |
| 256 | +logRaw("This is a logRaw message"); |
| 257 | +expect(cliOut.stdout).toMatchInlineSnapshot(`""`); |
| 258 | +}); |
| 259 | + |
| 260 | +it("should not output when log level is set to error", () => { |
| 261 | +setLogLevel("error"); |
| 262 | +logRaw("This is a logRaw message"); |
| 263 | +expect(cliOut.stdout).toMatchInlineSnapshot(`""`); |
| 264 | +}); |
| 265 | + |
| 266 | +it("should not output when log level is set to none", () => { |
| 267 | +setLogLevel("none"); |
| 268 | +logRaw("This is a logRaw message"); |
| 269 | +expect(cliOut.stdout).toMatchInlineSnapshot(`""`); |
| 270 | +}); |
| 271 | + |
| 272 | +it("should output when log level is set to debug", () => { |
| 273 | +setLogLevel("debug"); |
| 274 | +logRaw("This is a logRaw message"); |
| 275 | +expect(cliOut.stdout).toMatchInlineSnapshot( |
| 276 | +`"This is a logRaw message\n"` |
| 277 | +); |
| 278 | +}); |
| 279 | +}); |
| 280 | + |
| 281 | +describe("@cloudflare/cli error", () => { |
| 282 | +const cliOut = mockCLIOutput(); |
| 283 | + |
| 284 | +it("should output at error level", () => { |
| 285 | +setLogLevel("error"); |
| 286 | +error("This is an error message"); |
| 287 | +expect(cliOut.stderr).toMatchInlineSnapshot( |
| 288 | +`"╰ ERROR This is an error message\n"` |
| 289 | +); |
| 290 | +}); |
| 291 | + |
| 292 | +it("should not output when log level is set to none", () => { |
| 293 | +setLogLevel("none"); |
| 294 | +error("This is an error message"); |
| 295 | +expect(cliOut.stderr).toMatchInlineSnapshot(`""`); |
| 296 | +}); |
| 297 | + |
| 298 | +it("should output when log level is set to warn", () => { |
| 299 | +setLogLevel("warn"); |
| 300 | +error("This is an error message"); |
| 301 | +expect(cliOut.stderr).toMatchInlineSnapshot( |
| 302 | +`"╰ ERROR This is an error message\n"` |
| 303 | +); |
| 304 | +}); |
| 305 | + |
| 306 | +it("should output when log level is set to log", () => { |
| 307 | +setLogLevel("log"); |
| 308 | +error("This is an error message"); |
| 309 | +expect(cliOut.stderr).toMatchInlineSnapshot( |
| 310 | +`"╰ ERROR This is an error message\n"` |
| 311 | +); |
| 312 | +}); |
| 313 | + |
| 314 | +it("should output when log level is set to debug", () => { |
| 315 | +setLogLevel("debug"); |
| 316 | +error("This is an error message"); |
| 317 | +expect(cliOut.stderr).toMatchInlineSnapshot( |
| 318 | +`"╰ ERROR This is an error message\n"` |
| 319 | +); |
| 320 | +}); |
| 321 | +}); |
241 | 322 | }); |
0 commit comments