generated from antfu/starter-vscode
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add unit tests for hurl parse utils
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { describe, it, expect } from "vitest"; | ||
import { parseHurlOutput } from "../src/hurl-parser"; | ||
|
||
describe('parseHurlOutput', () => { | ||
it('should parse a simple GET request', () => { | ||
const stderr = ` | ||
* Executing entry 1 | ||
* Request: | ||
* GET https://example.com/api | ||
* curl 'https://example.com/api' | ||
> GET /api HTTP/1.1 | ||
> Host: example.com | ||
> User-Agent: hurl/1.0 | ||
> Accept: */* | ||
> | ||
< HTTP/1.1 200 OK | ||
< Content-Type: application/json | ||
< Content-Length: 123 | ||
< | ||
* Timings: | ||
* namelookup: 1000 µs | ||
* connect: 2000 µs | ||
* total: 10000 µs | ||
* | ||
`; | ||
const stdout = '{"message": "Hello, World!"}'; | ||
|
||
const result = parseHurlOutput(stderr, stdout); | ||
|
||
expect(result.entries).toHaveLength(1); | ||
expect(result.entries[0]).toEqual({ | ||
requestMethod: 'GET', | ||
requestUrl: '/api', | ||
requestHeaders: { | ||
'Host': 'example.com', | ||
'User-Agent': 'hurl/1.0', | ||
'Accept': '*/*' | ||
}, | ||
response: { | ||
status: 'HTTP/1.1 200 OK', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Content-Length': '123' | ||
}, | ||
body: '{"message": "Hello, World!"}' | ||
}, | ||
curlCommand: "curl 'https://example.com/api'", | ||
timings: { | ||
namelookup: '1.00 ms', | ||
connect: '2.00 ms', | ||
total: '10.00 ms' | ||
} | ||
}); | ||
}); | ||
|
||
it('should handle empty input', () => { | ||
const result = parseHurlOutput('', ''); | ||
expect(result.entries).toHaveLength(0); | ||
}); | ||
}); |