Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export async function script2({url, expectStatus, expectText}: {
- url: string;
- expectStatus?: number;
- expectText?: string;
- }): Promise<{
- pass: boolean;
- error?: string;
- }> {
- try {
- const response = await fetch(url, {});
- if (expectStatus && response.status !== expectStatus) {
- return {
- pass: false,
- error: `Server returned status ${response.status} where ${expectStatus} was expected`
- };
- }
- if (expectText) {
- const body = await response.text();
- if (body.indexOf(expectText) < 0) {
- return {
- pass: false,
- error: `Response did not contain the expected text "${expectText}"`
- };
- }
- }
- return {
- pass: true
- };
- } catch (error) {
- return {
- pass: false,
- error: error.message
- };
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement