From ab0aa2fae6885e2dcfcdb3a4cbf01dbacbfa559d Mon Sep 17 00:00:00 2001 From: Jipson Minibhavan Date: Mon, 5 Feb 2024 11:20:15 +0100 Subject: [PATCH] localhost to env --- frontend/.gitignore | 2 +- frontend/cypress.config.ts | 2 +- frontend/cypress/cypress.config.js | 9 +++++++ .../cypress/cypress/fixtures/example.json | 5 ++++ frontend/cypress/cypress/support/commands.js | 25 +++++++++++++++++++ frontend/cypress/cypress/support/e2e.js | 20 +++++++++++++++ frontend/cypress/e2e/tsconfig.json | 1 + frontend/env.d.ts | 8 ++++++ frontend/package.json | 10 +++++--- frontend/src/components/BasisHeader.vue | 3 ++- frontend/src/components/BasisLogin.vue | 8 +++--- frontend/src/components/CreateLink.vue | 4 +-- frontend/src/components/EditLink.vue | 5 ++-- frontend/src/components/LinkList.vue | 6 ++--- frontend/src/store/link.ts | 6 ++--- frontend/src/utils/config.ts | 3 +++ frontend/src/utils/cypress.config.ts | 1 + frontend/test/test.js | 2 ++ frontend/tsconfig.node.json | 3 ++- 19 files changed, 102 insertions(+), 21 deletions(-) create mode 100644 frontend/cypress/cypress.config.js create mode 100644 frontend/cypress/cypress/fixtures/example.json create mode 100644 frontend/cypress/cypress/support/commands.js create mode 100644 frontend/cypress/cypress/support/e2e.js create mode 100644 frontend/src/utils/config.ts create mode 100644 frontend/src/utils/cypress.config.ts create mode 100644 frontend/test/test.js diff --git a/frontend/.gitignore b/frontend/.gitignore index cfa7514..a6dd390 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -13,7 +13,7 @@ dist dist-ssr coverage *.local - +.env /cypress/videos/ /cypress/screenshots/ diff --git a/frontend/cypress.config.ts b/frontend/cypress.config.ts index f5a7e44..e80e0e1 100644 --- a/frontend/cypress.config.ts +++ b/frontend/cypress.config.ts @@ -3,6 +3,6 @@ import { defineConfig } from 'cypress' export default defineConfig({ e2e: { specPattern: 'cypress/e2e/**/*.{cy,spec}.{js,jsx,ts,tsx}', - baseUrl: 'http://localhost:4000' + baseUrl: process.env.CYPRESS_BASE_URL } }) diff --git a/frontend/cypress/cypress.config.js b/frontend/cypress/cypress.config.js new file mode 100644 index 0000000..97f47c4 --- /dev/null +++ b/frontend/cypress/cypress.config.js @@ -0,0 +1,9 @@ +const { defineConfig } = require("cypress"); + +module.exports = defineConfig({ + e2e: { + setupNodeEvents(on, config) { + // implement node event listeners here + }, + }, +}); diff --git a/frontend/cypress/cypress/fixtures/example.json b/frontend/cypress/cypress/fixtures/example.json new file mode 100644 index 0000000..02e4254 --- /dev/null +++ b/frontend/cypress/cypress/fixtures/example.json @@ -0,0 +1,5 @@ +{ + "name": "Using fixtures to represent data", + "email": "hello@cypress.io", + "body": "Fixtures are a great way to mock data for responses to routes" +} diff --git a/frontend/cypress/cypress/support/commands.js b/frontend/cypress/cypress/support/commands.js new file mode 100644 index 0000000..66ea16e --- /dev/null +++ b/frontend/cypress/cypress/support/commands.js @@ -0,0 +1,25 @@ +// *********************************************** +// This example commands.js shows you how to +// create various custom commands and overwrite +// existing commands. +// +// For more comprehensive examples of custom +// commands please read more here: +// https://on.cypress.io/custom-commands +// *********************************************** +// +// +// -- This is a parent command -- +// Cypress.Commands.add('login', (email, password) => { ... }) +// +// +// -- This is a child command -- +// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... }) +// +// +// -- This is a dual command -- +// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... }) +// +// +// -- This will overwrite an existing command -- +// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) \ No newline at end of file diff --git a/frontend/cypress/cypress/support/e2e.js b/frontend/cypress/cypress/support/e2e.js new file mode 100644 index 0000000..0e7290a --- /dev/null +++ b/frontend/cypress/cypress/support/e2e.js @@ -0,0 +1,20 @@ +// *********************************************************** +// This example support/e2e.js is processed and +// loaded automatically before your test files. +// +// This is a great place to put global configuration and +// behavior that modifies Cypress. +// +// You can change the location of this file or turn off +// automatically serving support files with the +// 'supportFile' configuration option. +// +// You can read more here: +// https://on.cypress.io/configuration +// *********************************************************** + +// Import commands.js using ES2015 syntax: +import './commands' + +// Alternatively you can use CommonJS syntax: +// require('./commands') \ No newline at end of file diff --git a/frontend/cypress/e2e/tsconfig.json b/frontend/cypress/e2e/tsconfig.json index 37748fe..12b2725 100644 --- a/frontend/cypress/e2e/tsconfig.json +++ b/frontend/cypress/e2e/tsconfig.json @@ -2,6 +2,7 @@ "extends": "@vue/tsconfig/tsconfig.dom.json", "include": ["./**/*", "../support/**/*"], "compilerOptions": { + "baseUrl": "./", "isolatedModules": false, "target": "es5", "lib": ["es5", "dom"], diff --git a/frontend/env.d.ts b/frontend/env.d.ts index 11f02fe..51c9d4d 100644 --- a/frontend/env.d.ts +++ b/frontend/env.d.ts @@ -1 +1,9 @@ /// +interface ImportMetaEnv { + readonly VITE_API_URL: string + // more env variables... +} + +interface ImportMeta { + readonly env: ImportMetaEnv +} diff --git a/frontend/package.json b/frontend/package.json index e2048df..acd60cc 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -4,16 +4,18 @@ "private": true, "scripts": { "build": "run-p type-check build-only", + "cypress:open": "cypress open", + "cypress:run": "cypress run --e2e", "test:unit": "vitest", - "test:e2e": "start-server-and-test preview http://localhost:4000 'cypress run --e2e'", + "test:e2e": "start-server-and-test preview 'cypress run --e2e'", "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore", "build-only": "vite build", "build-storybook": "storybook build", - "dev": "vite", + "dev": "vite ", "format": "prettier --write src/", - "preview": "vite preview --host --port 4000", + "preview": "vite preview --host ", "storybook": "storybook dev -p 6006", - "test:e2e:dev": "start-server-and-test 'vite dev --port 4000' http://localhost:4000 'cypress open --e2e'", + "test:e2e:dev": "start-server-and-test 'vite dev --host' $VITE_DEV_SERVER_URL 'cypress open --e2e'", "type-check": "vue-tsc --noEmit -p tsconfig.vitest.json --composite false" }, "dependencies": { diff --git a/frontend/src/components/BasisHeader.vue b/frontend/src/components/BasisHeader.vue index ab7a8b3..d971236 100644 --- a/frontend/src/components/BasisHeader.vue +++ b/frontend/src/components/BasisHeader.vue @@ -25,6 +25,7 @@