Skip to content

Commit

Permalink
test: add unit tests for hurl parse utils
Browse files Browse the repository at this point in the history
  • Loading branch information
jellydn committed Oct 12, 2024
1 parent abde28e commit 2c8ab24
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions test/hurl-parser.test.ts
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);
});
});

0 comments on commit 2c8ab24

Please sign in to comment.