From 47045bca59b34e56bee293ddb0d96bb063441de0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Loi=CC=88c=20Correnson?= <loic.correnson@cea.fr>
Date: Thu, 18 Apr 2024 09:57:13 +0200
Subject: [PATCH] [ivette] fix launching scripts

---
 ivette/tests/e2e/launch-app.spec.ts           | 37 --------------
 .../tests/e2e/server-connection-file.spec.ts  | 10 ++--
 ivette/tests/e2e/server-connection.spec.ts    |  7 +--
 ivette/tests/libs/e2eService.ts               | 48 ++++++-------------
 ivette/tests/monkey/monkey-testing.spec.ts    |  6 +--
 5 files changed, 20 insertions(+), 88 deletions(-)
 delete mode 100644 ivette/tests/e2e/launch-app.spec.ts

diff --git a/ivette/tests/e2e/launch-app.spec.ts b/ivette/tests/e2e/launch-app.spec.ts
deleted file mode 100644
index e9e2ce889fd..00000000000
--- a/ivette/tests/e2e/launch-app.spec.ts
+++ /dev/null
@@ -1,37 +0,0 @@
-/* ************************************************************************ */
-/*                                                                          */
-/*   This file is part of Frama-C.                                          */
-/*                                                                          */
-/*   Copyright (C) 2007-2023                                                */
-/*     CEA (Commissariat à l'énergie atomique et aux énergies               */
-/*          alternatives)                                                   */
-/*                                                                          */
-/*   you can redistribute it and/or modify it under the terms of the GNU    */
-/*   Lesser General Public License as published by the Free Software        */
-/*   Foundation, version 2.1.                                               */
-/*                                                                          */
-/*   It is distributed in the hope that it will be useful,                  */
-/*   but WITHOUT ANY WARRANTY; without even the implied warranty of         */
-/*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
-/*   GNU Lesser General Public License for more details.                    */
-/*                                                                          */
-/*   See the GNU Lesser General Public License version 2.1                  */
-/*   for more details (enclosed in the file licenses/LGPLv2.1).             */
-/*                                                                          */
-/* ************************************************************************ */
-
-import { test } from "@playwright/test";
-import * as e2eService from "../libs/e2eService";
-
-test("launch app", async () => {
-  const launchAppResult = await e2eService.launchApp(
-    e2eService.argsDefaultLaunch,
-  );
-  const electronApp = launchAppResult.app;
-  const window = launchAppResult.page;
-
-  await window.screenshot({ path: "screenshots/e2e-app-launch.png" });
-
-  // Exit app.
-  await electronApp.close();
-});
diff --git a/ivette/tests/e2e/server-connection-file.spec.ts b/ivette/tests/e2e/server-connection-file.spec.ts
index 7a379f024a1..625e12f947a 100644
--- a/ivette/tests/e2e/server-connection-file.spec.ts
+++ b/ivette/tests/e2e/server-connection-file.spec.ts
@@ -24,14 +24,10 @@ import { test } from "@playwright/test";
 import * as e2eService from "../libs/e2eService";
 
 test("server connection with a C file to analyze", async () => {
-  const launchAppResult = await e2eService.launchApp(
-    e2eService.argsLaunchWithTestFile,
-  );
+  const launchAppResult =
+    await e2eService.launchIvette("../tests/test/adpcm.c");
   const electronApp = launchAppResult.app;
   const window = launchAppResult.page;
-
-  await e2eService.testFileIsLoaded(window);
-
-  // Exit app.
+  await e2eService.testFileIsLoaded(window, "../tests/test/adpcm.c");
   await electronApp.close();
 });
diff --git a/ivette/tests/e2e/server-connection.spec.ts b/ivette/tests/e2e/server-connection.spec.ts
index 263384fd1ce..47413728453 100644
--- a/ivette/tests/e2e/server-connection.spec.ts
+++ b/ivette/tests/e2e/server-connection.spec.ts
@@ -24,14 +24,9 @@ import { test } from "@playwright/test";
 import * as e2eService from "../libs/e2eService";
 
 test("check server connection", async () => {
-  const launchAppResult = await e2eService.launchApp(
-    e2eService.argsLaunchWithDefaultSettings,
-  );
+  const launchAppResult = await e2eService.launchIvette();
   const electronApp = launchAppResult.app;
   const window = launchAppResult.page;
-
   await e2eService.testServerIsStarted(window);
-
-  // Exit app.
   await electronApp.close();
 });
diff --git a/ivette/tests/libs/e2eService.ts b/ivette/tests/libs/e2eService.ts
index e71eb4a2bec..036ca129b39 100644
--- a/ivette/tests/libs/e2eService.ts
+++ b/ivette/tests/libs/e2eService.ts
@@ -24,41 +24,20 @@ import { ElectronApplication, Page, expect } from "@playwright/test";
 import { _electron as electron } from "playwright-core";
 import * as locs from "./locatorsUtil";
 
-/**
- * Basic Electron configuration for Playwright e2e tests of Ivette
- */
-export const argsDefaultLaunch: string[] = [
-  "./out/main/index.js",
-  "--no-sandbox",
-];
-
-/**
- * Electron configuration for Playwright e2e tests of Ivette's default settings
- */
-export const argsLaunchWithDefaultSettings: string[] = [
-  "./out/main/index.js",
-  "--no-sandbox",
-  "--settings",
-  "DEFAULT"
-];
-
-/**
- * Electron configuration for Playwright e2e tests of Ivette on a C file
- */
-export const argsLaunchWithTestFile: string[] = [
-  "./out/main/index.js",
-  "--no-sandbox",
-  "--settings",
-  "./tests/settings.json",
-  "../tests/test/adpcm.c",
-];
-
 /**
  * Basic Electron launch of Ivette for Playwright e2e tests
  */
-export async function launchApp(
-  params: string[]
+export async function launchIvette(
+  ...params: string[]
 ): Promise<{ app: ElectronApplication; page: Page }> {
+  const args: string[] = [
+    "./out/main/index.js",
+    "--no-sandbox",
+    "--settings", "DEFAULT"
+  ];
+  params.forEach(p => {
+    p.trim().split(/\s+/).forEach(a => args.push(a));
+  });
   const electronApp = await electron.launch({
     env: {
       ...process.env,
@@ -87,19 +66,20 @@ export async function testServerIsStarted(window: Page): Promise<void> {
   // Check the server status in the console view
   await expect(
     locs.getConsoleComponent(window)
-    .getByText("[server] Socket server running.")
+      .getByText("[server] Socket server running.")
   ).toBeVisible();
 
   // Check the server status in the footer
   await expect(locs.getServerStatusLabel(window)).toHaveText("ON");
 }
 
-export async function testFileIsLoaded(window: Page): Promise<void> {
+export async function testFileIsLoaded(window: Page, file: string):
+  Promise<void> {
   await locs.getConsoleView(window).click();
   // Check if a message is present in the console view to confirm the file is
   // loaded
   await expect(
-    locs.getConsoleComponent(window).getByText("adpcm.c (with preprocessing)")
+    locs.getConsoleComponent(window).getByText(`${file} (with preprocessing)`)
   ).toBeVisible();
 
   // Check if the main function is visible in the functions view
diff --git a/ivette/tests/monkey/monkey-testing.spec.ts b/ivette/tests/monkey/monkey-testing.spec.ts
index 0e5d7b9e3e5..256752bfc39 100644
--- a/ivette/tests/monkey/monkey-testing.spec.ts
+++ b/ivette/tests/monkey/monkey-testing.spec.ts
@@ -28,10 +28,8 @@ let gremlins: any;
 
 test("run gremlins.js", async () => {
   test.slow(); // long timeout for a very slow test.
-
-  const launchAppResult = await e2eService.launchApp(
-    e2eService.argsLaunchWithTestFile,
-  );
+  const launchAppResult =
+    await e2eService.launchIvette("../tests/test/adpcm.c");
   const electronApp = launchAppResult.app;
   const window = launchAppResult.page;
 
-- 
GitLab