From 6949efb1fcde54bae2a2cd5042b50bf9136c3ee6 Mon Sep 17 00:00:00 2001 From: David Mears Date: Fri, 12 Jul 2024 17:17:57 +0100 Subject: [PATCH] Do linting --- .github/workflows/lint.yml | 4 +- .github/workflows/playwright.yml | 40 +++++------ .github/workflows/unit-tests.yml | 4 +- app.vue | 18 ++--- assets/icons/index.js | 20 +++--- components/AppHeader.vue | 83 ++++++++++++----------- components/BreadCrumb.vue | 15 ++-- components/SideBar.vue | 56 ++++++++------- components/WebsocketConnection.client.vue | 70 +++++++++---------- components/socket.ts | 26 +++---- layouts/default.vue | 32 ++++----- pages/comparison.vue | 16 ++--- pages/index.vue | 16 +++-- pages/scenario/new.vue | 12 ++-- playwright.config.ts | 12 ++-- plugins/coreui.ts | 3 +- server/plugins/socket.io.ts | 69 +++++++++---------- tests/components/defaultLayout.spec.ts | 64 ++++++++--------- tests/e2e/defaultLayout.spec.ts | 17 ++--- tests/e2e/first-test.spec.ts | 4 +- tests/ssr/first-test.spec.ts | 10 +-- vitest.config.ts | 10 +-- 22 files changed, 308 insertions(+), 293 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 8e08131b..d8e4b3b0 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -5,7 +5,7 @@ on: - main pull_request: branches: - - "*" + - '*' jobs: test: runs-on: ubuntu-latest @@ -16,7 +16,7 @@ jobs: uses: actions/setup-node@v4 with: node-version: 20 - cache: 'npm' + cache: npm - name: Install dependencies run: npm ci - name: Lint diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 83a83c53..89c62475 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -5,28 +5,28 @@ on: - main pull_request: branches: - - "*" + - '*' jobs: test: timeout-minutes: 60 runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Set up Node - uses: actions/setup-node@v4 - with: - node-version: 20 - cache: npm - - name: Install dependencies - run: npm ci - - name: Install Playwright Browsers - run: npx playwright install --with-deps && npx playwright install msedge - - name: Run Playwright tests - run: npm run test:e2e - - uses: actions/upload-artifact@v4 - if: always() - with: - name: playwright-report - path: playwright-report/ - retention-days: 30 + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Node + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: npm + - name: Install dependencies + run: npm ci + - name: Install Playwright Browsers + run: npx playwright install --with-deps && npx playwright install msedge + - name: Run Playwright tests + run: npm run test:e2e + - uses: actions/upload-artifact@v4 + if: always() + with: + name: playwright-report + path: playwright-report/ + retention-days: 30 diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 61cbd8bc..69ea5599 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -5,7 +5,7 @@ on: - main pull_request: branches: - - "*" + - '*' jobs: test: timeout-minutes: 60 @@ -17,7 +17,7 @@ jobs: uses: actions/setup-node@v4 with: node-version: 20 - cache: 'npm' + cache: npm - name: Install dependencies run: npm ci - name: Test diff --git a/app.vue b/app.vue index b7a2f8ad..2e311a3c 100644 --- a/app.vue +++ b/app.vue @@ -1,3 +1,11 @@ + + - - \ No newline at end of file + diff --git a/assets/icons/index.js b/assets/icons/index.js index ff652c33..d7f96359 100644 --- a/assets/icons/index.js +++ b/assets/icons/index.js @@ -1,15 +1,15 @@ import { - cilMenu, + cilArrowThickToLeft, + cilBookmark, + cilChevronLeft, cilCloudDownload, - cilPlus, + cilGlobeAlt, cilHistory, - cilShareAlt, + cilMenu, cilNoteAdd, - cilBookmark, - cilGlobeAlt, - cilArrowThickToLeft, - cilChevronLeft -} from '@coreui/icons'; + cilPlus, + cilShareAlt, +} from '@coreui/icons' export const iconsSet = { cilMenu, @@ -21,5 +21,5 @@ export const iconsSet = { cilNoteAdd, cilGlobeAlt, cilArrowThickToLeft, - cilChevronLeft -}; \ No newline at end of file + cilChevronLeft, +} diff --git a/components/AppHeader.vue b/components/AppHeader.vue index 921f0eeb..84fe86b6 100644 --- a/components/AppHeader.vue +++ b/components/AppHeader.vue @@ -1,68 +1,71 @@ + + - - diff --git a/components/SideBar.vue b/components/SideBar.vue index b9173609..ae1673e7 100644 --- a/components/SideBar.vue +++ b/components/SideBar.vue @@ -1,3 +1,19 @@ + + - - \ No newline at end of file + diff --git a/components/WebsocketConnection.client.vue b/components/WebsocketConnection.client.vue index 8ccc47e2..bd7420e6 100644 --- a/components/WebsocketConnection.client.vue +++ b/components/WebsocketConnection.client.vue @@ -1,67 +1,67 @@ - - + + \ No newline at end of file + diff --git a/components/socket.ts b/components/socket.ts index d2c3ddf2..90cfe4b4 100644 --- a/components/socket.ts +++ b/components/socket.ts @@ -3,25 +3,27 @@ // Make sure you never try to use this code during server-side rendering -import { io } from "socket.io-client"; +import { io } from 'socket.io-client' // https://dev.to/mellewynia/quick-guide-to-add-websocket-to-nuxt-3-4bi4 -const url = `${location.protocol === 'https:' ? 'wss://' : 'ws://' }${location.host}` +const url = `${location.protocol === 'https:' ? 'wss://' : 'ws://'}${location.host}` export const socket = io(url) interface SocketIOError extends Error { - description?: string; - context?: unknown; + description?: string + context?: unknown } -socket.on("connect_error", (err: SocketIOError) => { - // the reason of the error, for example "xhr poll error" - console.log(err.message); +socket.on('connect_error', (err: SocketIOError) => { + /* eslint-disable no-console */ - // some additional description, for example the status code of the initial HTTP response - console.log(err.description); + // the reason of the error, for example "xhr poll error" + console.log(err.message) - // some additional context, for example the XMLHttpRequest object - console.log(err.context); -}); + // some additional description, for example the status code of the initial HTTP response + console.log(err.description) + + // some additional context, for example the XMLHttpRequest object + console.log(err.context) +}) diff --git a/layouts/default.vue b/layouts/default.vue index 812772e7..73d29c4a 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -1,3 +1,18 @@ + + - - \ No newline at end of file + diff --git a/pages/comparison.vue b/pages/comparison.vue index 3712e8df..54951f43 100644 --- a/pages/comparison.vue +++ b/pages/comparison.vue @@ -1,9 +1,3 @@ - - + + diff --git a/pages/index.vue b/pages/index.vue index 6fcd319e..c587c42b 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -1,14 +1,16 @@ - - + + diff --git a/pages/scenario/new.vue b/pages/scenario/new.vue index 4d58f833..9843baf0 100644 --- a/pages/scenario/new.vue +++ b/pages/scenario/new.vue @@ -1,15 +1,15 @@ + + - - diff --git a/playwright.config.ts b/playwright.config.ts index 81ce5f46..83222532 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -1,11 +1,13 @@ -import { defineConfig, devices } from '@playwright/test'; +/* eslint-disable node/prefer-global/process */ +import { defineConfig, devices } from '@playwright/test' /** * Read environment variables from file. * https://github.com/motdotla/dotenv */ -import dotenv from 'dotenv'; -dotenv.config(); +import dotenv from 'dotenv' + +dotenv.config() /** * See https://playwright.dev/docs/test-configuration. @@ -71,11 +73,11 @@ export default defineConfig({ ], /* Run your local dev server before starting the tests */ - // Multiple web servers (or background processes) can be launched: https://playwright.dev/docs/api/class-testconfig#test-config-web-server + // Multiple web servers (or background processes) can be launched: https://playwright.dev/docs/api/class-testconfig#test-config-web-server webServer: { command: 'NUXT_HOST="127.0.0.1" NUXT_PORT="3000" npm run dev', url: 'http://127.0.0.1:3000', timeout: 120 * 1000, reuseExistingServer: !process.env.CI, }, -}); +}) diff --git a/plugins/coreui.ts b/plugins/coreui.ts index 0027e000..ecf0ef35 100644 --- a/plugins/coreui.ts +++ b/plugins/coreui.ts @@ -13,8 +13,6 @@ // on every page, but if you have components that are only used on certain pages, you should // import them in the page components themselves. -import { defineNuxtPlugin } from '#app' - import { CSidebar } from '@coreui/vue/src/components/sidebar/CSidebar' import { CSidebarHeader } from '@coreui/vue/src/components/sidebar/CSidebarHeader' import { CSidebarBrand } from '@coreui/vue/src/components/sidebar/CSidebarBrand' @@ -31,6 +29,7 @@ import { CHeaderNav } from '@coreui/vue/src/components/header/CHeaderNav' import { CBreadcrumb } from '@coreui/vue/src/components/breadcrumb/CBreadcrumb' import { CBreadcrumbItem } from '@coreui/vue/src/components/breadcrumb/CBreadcrumbItem' import { CProgress } from '@coreui/vue/src/components/progress/CProgress' +import { defineNuxtPlugin } from '#app' export default defineNuxtPlugin((nuxtApp) => { nuxtApp.vueApp.component('CSidebar', CSidebar) diff --git a/server/plugins/socket.io.ts b/server/plugins/socket.io.ts index f73d7cfb..64b8d4cd 100644 --- a/server/plugins/socket.io.ts +++ b/server/plugins/socket.io.ts @@ -1,17 +1,17 @@ // This is the server side of socket.io // Copied from https://socket.io/how-to/use-with-nuxt -import type { NitroApp } from "nitropack"; -import { Server as Engine } from "engine.io"; -import { Server } from "socket.io"; -import { defineEventHandler } from "h3"; +import type { NitroApp } from 'nitropack' +import { Server as Engine } from 'engine.io' +import { Server } from 'socket.io' +import { defineEventHandler } from 'h3' export default defineNitroPlugin((nitroApp: NitroApp) => { - const engine = new Engine(); + const engine = new Engine() const io = new Server({ serveClient: false, // Since we're using the client library from node modules, we don't need to serve it. https://socket.io/docs/v4/client-installation/#installation cors: { - origin: "http://localhost:3000" // According to https://socket.io/how-to/use-with-vue + origin: 'http://localhost:3000', // According to https://socket.io/how-to/use-with-vue }, // https://socket.io/docs/v4/connection-state-recovery connectionStateRecovery: { @@ -19,45 +19,46 @@ export default defineNitroPlugin((nitroApp: NitroApp) => { maxDisconnectionDuration: 2 * 60 * 1000, // whether to skip middlewares upon successful recovery skipMiddlewares: true, - } - }); + }, + }) - io.bind(engine); + io.bind(engine) - io.on("connection", (socket) => { + io.on('connection', (socket) => { // For debugging websockets connection only: // Every 1000ms, emit a message to the client containing the current time on the server setInterval(() => { - socket.emit("time", new Date().toTimeString()); - }, 1000); - }); - - io.engine.on("connection_error", (err) => { - console.log(err.req); // the request object - console.log(err.code); // the error code, for example 1 - console.log(err.message); // the error message, for example "Session ID unknown" - console.log(err.context); // some additional error context - }); - - nitroApp.router.use("/socket.io/", defineEventHandler({ + socket.emit('time', new Date().toTimeString()) + }, 1000) + }) + + io.engine.on('connection_error', (err) => { + /* eslint-disable no-console */ + console.log(err.req) // the request object + console.log(err.code) // the error code, for example 1 + console.log(err.message) // the error message, for example "Session ID unknown" + console.log(err.context) // some additional error context + }) + + nitroApp.router.use('/socket.io/', defineEventHandler({ handler(event) { - engine.handleRequest(event.node.req, event.node.res); - event._handled = true; + engine.handleRequest(event.node.req, event.node.res) + event._handled = true }, websocket: { open(peer) { - const nodeContext = peer.ctx.node; - const req = nodeContext.req; + const nodeContext = peer.ctx.node + const req = nodeContext.req // @ts-expect-error private method - engine.prepare(req); + engine.prepare(req) - const rawSocket = nodeContext.req.socket; - const websocket = nodeContext.ws; + const rawSocket = nodeContext.req.socket + const websocket = nodeContext.ws // @ts-expect-error private method - engine.onWebSocket(req, rawSocket, websocket); - } - } - })); -}); \ No newline at end of file + engine.onWebSocket(req, rawSocket, websocket) + }, + }, + })) +}) diff --git a/tests/components/defaultLayout.spec.ts b/tests/components/defaultLayout.spec.ts index 3568fcb9..572a1d0a 100644 --- a/tests/components/defaultLayout.spec.ts +++ b/tests/components/defaultLayout.spec.ts @@ -1,15 +1,15 @@ // @vitest-environment nuxt -import { describe, it, expect } from 'vitest'; +import { describe, expect, it } from 'vitest' import { mountSuspended } from '@nuxt/test-utils/runtime' -import DefaultLayout from '../../layouts/default.vue'; +import DefaultLayout from '../../layouts/default.vue' const stubs = { SideBar: { name: 'SideBar', template: '