e2e/lib/strapi-utils.ts (view raw)
1import fs from "fs";
2import { USER, USER_PASSWORD } from "../constants";
3import { sdk } from "./gqlSdk";
4import { wait } from "./wait";
5
6export const restartStrapi = async () => {
7 await fs.promises.writeFile("../backend/restart.test", "Restart Strapi");
8 console.log(`Wait for Strapi to restart`);
9 await wait(8000);
10 await waitForStrapi();
11};
12
13export const getJwtToken = async () => {
14 const { login } = await sdk.login({
15 identifier: USER.email as string,
16 password: USER_PASSWORD,
17 });
18 return login?.jwt;
19};
20
21const waitForStrapi = async () => {
22 let isAvailable = false;
23 while (!isAvailable) {
24 await wait(1000);
25 try {
26 await fetch("http://localhost:1337/graphql");
27 isAvailable = true;
28 } catch (error) {
29 console.log("Strapi is not ready");
30 }
31 }
32 console.log("STRAPI IS STARTED");
33};