Skip to content

Commit

Permalink
Updates routes to /api/v1
Browse files Browse the repository at this point in the history
  • Loading branch information
blacelle committed Sep 19, 2024
1 parent 52cbc19 commit fe271fb
Show file tree
Hide file tree
Showing 39 changed files with 526 additions and 333 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
branches: [ main, master ]
jobs:
test:
timeout-minutes: 60
timeout-minutes: 5
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -20,6 +20,11 @@ jobs:
cache: maven
- name: Install Kumite Server
run: mvn package -DskipTests
- name: Check Running ContestsServer
run: (cd ./server; mvn spring-boot:run;)
- name: Check Running ContestsServer from JS
working-directory: ./js
run: (cd ./server; mvn spring-boot:run;)

- uses: actions/setup-node@v4
with:
Expand All @@ -30,9 +35,9 @@ jobs:
- name: Install Playwright Browsers
working-directory: ./js
run: npx playwright install --with-deps
- name: Run Playwright tests
working-directory: ./js
run: npx playwright test
#- name: Run Playwright tests
# working-directory: ./js
# run: npm run pw_localhost8080
- uses: actions/upload-artifact@v4
if: always()
with:
Expand Down
16 changes: 8 additions & 8 deletions js/.prettierrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ tabWidth: 4
printWidth: 160

overrides:
# // https://github.com/prettier/prettier/issues/5892#issuecomment-466318688
- files: "*.html"
options:
parser: html
- files:
- "*.vue"
options:
parser: vue
# // https://github.com/prettier/prettier/issues/5892#issuecomment-466318688
- files: "*.html"
options:
parser: html
- files:
- "*.vue"
options:
parser: vue
8 changes: 4 additions & 4 deletions js/CONTRIBUTING.MD
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
npm ci
npm audit
npm run lint

npm outdated
npm update

# End-to-end tests with Playwright

https://playwright.dev/docs/intro

npx playwright test --ui
npx playwright show-report

## Generate new tests

https://playwright.dev/docs/codegen-intro

npx playwright codegen http://localhost:8080/
npx playwright codegen http://localhost:8080/
43 changes: 23 additions & 20 deletions js/e2e-tests/fake-player.mjs
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
import { expect } from '@playwright/test';
import { expect } from "@playwright/test";

// https://stackoverflow.com/questions/33178843/es6-export-default-with-multiple-functions-referring-to-each-other
export default {
async clear(request, url) {
const response = await request.post(url + '/api/clear');
const response = await request.post(url + "/api/v1/clear");

return response;
},

async login(page) {
await page.getByRole('link', {name: /You need to login/}).click();
await page.getByRole("link", { name: /You need to login/ }).click();
},

async playOptimization(page) {
await page.getByRole('link', { name: 'Games', exact: true }).click();
await page.getByRole("link", { name: "Games", exact: true }).click();

await page.getByRole("link", { name: /Travelling Salesman Problem/ }).click();
await page.getByRole("link", { name: /Create your own contest/ }).click();

await page.getByRole('link', { name: /Travelling Salesman Problem/ }).click();
await page.getByRole('link', { name: /Create your own contest/ }).click();

// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random
const contestName = String(Math.floor(Math.random() * 1024));
await page.locator("#contestName").fill(contestName);
await page.getByRole('button', { name: 'Submit' }).click();
await page.getByRole("button", { name: "Submit" }).click();

// await page.getByRole('link', { name: /Auto-generated/ }).first().click();
await page.getByRole('link', { name: new RegExp(`${contestName}`, 'gi') }).first().click();

await page.getByRole('button', { name: 'Preview the board' }).click();
await page.getByRole('button', { name: 'Join contest as player' }).click();
await page.getByRole('button', { name: 'Load some available moves' }).click();
await page.getByRole('button', { name: 'Prefill with an example move' }).click();
await page.getByText('greedy').click();
await page.getByRole('button', { name: 'Submit' }).click();
await page.getByText('11111111-1111-1111-1111-111111111111 has score').click();
await page
.getByRole("link", { name: new RegExp(`${contestName}`, "gi") })
.first()
.click();

await page.getByRole("button", { name: "Preview the board" }).click();
await page.getByRole("button", { name: "Join contest as player" }).click();
await page.getByRole("button", { name: "Load some available moves" }).click();
await page.getByRole("button", { name: "Prefill with an example move" }).click();
await page.getByText("greedy").click();
await page.getByRole("button", { name: "Submit" }).click();
await page.getByText("11111111-1111-1111-1111-111111111111 has score").click();
},
};
10 changes: 5 additions & 5 deletions js/e2e-tests/heroku-dev.spec.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { test, expect } from '@playwright/test';
import { test, expect } from "@playwright/test";

import fakePlayer from "./fake-player.mjs"
import fakePlayer from "./fake-player.mjs";

const url = "https://kumite-dev-d2844865d26b.herokuapp.com/";

test('login', async ({ page }) => {
test("login", async ({ page }) => {
await page.goto(url);
await fakePlayer.login(page);
});

test('play-optimization', async ({ page }) => {
test("play-optimization", async ({ page }) => {
await page.goto(url);
await fakePlayer.playOptimization(page);
});
});
14 changes: 7 additions & 7 deletions js/e2e-tests/localhost8080-dev.spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { test, expect, request } from '@playwright/test';
import { test, expect, request } from "@playwright/test";

import fakePlayer from "./fake-player.mjs"
import fakePlayer from "./fake-player.mjs";

const url = "http://localhost:8080";

test.beforeAll(async ({ request }) => {
// Create a new repository
const response = await fakePlayer.clear(request, url);
expect(response.ok()).toBeTruthy();
// Create a new repository
const response = await fakePlayer.clear(request, url);
expect(response.ok()).toBeTruthy();
});

// FakeUser skips the login phase
Expand All @@ -16,7 +16,7 @@ test.beforeAll(async ({ request }) => {
// await fakePlayer.login(page);
//});

test('play-optimization', async ({ page }) => {
test("play-optimization", async ({ page }) => {
await page.goto(url);
await fakePlayer.playOptimization(page);
});
});
6 changes: 0 additions & 6 deletions js/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import eslintPluginVue from "eslint-plugin-vue";
import vueEslintParser from "vue-eslint-parser";

// https://github.com/prettier/eslint-config-prettier
// Turns off all rules that are unnecessary or might conflict with Prettier.
// Disabled as included by `eslintPluginPrettierRecommended`
// import eslintConfigPrettier from "eslint-config-prettier";

// `eslint-plugin-prettier` will apply Prettier through ESLint
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";

Expand All @@ -32,6 +28,4 @@ export default [
},
// `eslintPluginPrettierRecommended` is last to override previous config, and it includes eslintConfigPrettier
eslintPluginPrettierRecommended,
// `eslintConfigPrettier` is last to override previous config
// eslintConfigPrettier,
];
3 changes: 2 additions & 1 deletion js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"lint": "eslint --fix src/main/resources/static",
"lint_debug": "eslint --fix src/main/resources/static --debug",
"preview": "vite preview",
"pw_localhost8080": "npx playwright test localhost8080 --project=chromium"
"pw_localhost8080": "npx playwright test localhost8080 --project=chromium",
"pw_localhost8080_ui": "npx playwright test localhost8080 --project=chromium --ui"
},
"type": "module",
"version": "0.0.0"
Expand Down
149 changes: 76 additions & 73 deletions js/playwright.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,88 +12,91 @@ import { defineConfig, devices } from "@playwright/test";
* @see https://playwright.dev/docs/test-configuration
*/
const config = defineConfig({
testDir: './e2e-tests',
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',
testDir: "./e2e-tests",
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: "html",
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},

// https://playwright.dev/docs/test-timeouts
timeout: 5000,
expect: { timeout: 3000 },

// https://github.com/microsoft/playwright/issues/14854
use: {
screenshot: "only-on-failure",
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on-first-retry",
},

/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },

// https://martinmcgee.dev/posts/how-to-ignore-cors-playwright/
// https://playwright.dev/docs/api/class-testoptions#test-options-bypass-csp
bypassCSP: true, // add this to disable cors
launchOptions: {
args: ['--disable-web-security'], // add this to disable cors
},
},
// https://playwright.dev/docs/test-timeouts
timeout: 5000,
expect: { timeout: 3000 },

{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
// https://github.com/microsoft/playwright/issues/14854
use: {
screenshot: "only-on-failure",
},

{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},
/* Configure projects for major browsers */
projects: [
{
name: "chromium",
use: { ...devices["Desktop Chrome"] },

// https://martinmcgee.dev/posts/how-to-ignore-cors-playwright/
// https://playwright.dev/docs/api/class-testoptions#test-options-bypass-csp
bypassCSP: true, // add this to disable cors
launchOptions: {
args: ["--disable-web-security"], // add this to disable cors
},
},

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },
{
name: "firefox",
use: { ...devices["Desktop Firefox"] },
},

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],
{
name: "webkit",
use: { ...devices["Desktop Safari"] },
},

/* Run your local dev server before starting the tests */
webServer: {
// command: 'npm run start',
command: '(cd ../server; mvn spring-boot:run;)',
// url: 'http://127.0.0.1:3000',
url: 'http://127.0.0.1:8080',
reuseExistingServer: !process.env.CI,
},
/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your local dev server before starting the tests */
webServer: {
// command: 'npm run start',
// `mvn install` to ensure `js` is fresh (especially important in local dev)
// `cd ../server` to relocate in the backend folder
// `mvn spring-boot:run` to effectively starts a server
command: "(mvn install; cd ../server; mvn spring-boot:run;)",
// url: 'http://127.0.0.1:3000',
url: "http://127.0.0.1:8080",
reuseExistingServer: !process.env.CI,
},
});

// https://github.com/microsoft/playwright/issues/12138
Expand Down
Loading

0 comments on commit fe271fb

Please sign in to comment.