2023-02-06 20:48:18 +01:00
|
|
|
/**
|
|
|
|
* This test file is used to test the text parser.
|
|
|
|
*/
|
|
|
|
const parser = require("../src/bruToJson");
|
|
|
|
|
|
|
|
describe("script parser", () => {
|
|
|
|
it("should parse request script", () => {
|
|
|
|
const input = `
|
2023-02-07 00:09:23 +01:00
|
|
|
script:pre-request {
|
2023-02-06 20:48:18 +01:00
|
|
|
$req.setHeader('Content-Type', 'application/json');
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const output = parser(input);
|
|
|
|
const expected = {
|
|
|
|
"script": {
|
|
|
|
"req": "$req.setHeader('Content-Type', 'application/json');"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
expect(output).toEqual(expected);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should parse response script", () => {
|
|
|
|
const input = `
|
2023-02-07 00:09:23 +01:00
|
|
|
script:post-response {
|
2023-02-06 20:48:18 +01:00
|
|
|
expect(response.status).to.equal(200);
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const output = parser(input);
|
|
|
|
const expected = {
|
|
|
|
"script": {
|
|
|
|
"res": "expect(response.status).to.equal(200);"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
expect(output).toEqual(expected);
|
|
|
|
});
|
|
|
|
});
|