From ec83e569311bb03811a499754c160795d1e7634c Mon Sep 17 00:00:00 2001 From: Joel Davies Date: Fri, 15 Mar 2024 11:09:20 +0000 Subject: [PATCH] Make cypress run again and exclude some files from coverage #1379 --- cypress.config.ts | 9 ++------- cypress/support/e2e.js | 2 -- package.json | 5 ++--- server/e2e-test-server.js | 26 ++++++++++++++------------ vite.config.ts | 10 ++++------ yarn.lock | 22 +--------------------- 6 files changed, 23 insertions(+), 51 deletions(-) diff --git a/cypress.config.ts b/cypress.config.ts index 13cd5717..675ad99a 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -1,4 +1,4 @@ -import { defineConfig } from 'cypress' +import { defineConfig } from 'cypress'; export default defineConfig({ chromeWebSecurity: false, @@ -8,11 +8,6 @@ export default defineConfig({ openMode: 0, }, e2e: { - setupNodeEvents(on, config) { - on('task', { - failed: require('cypress-failed-log/src/failed')(), - }) - }, baseUrl: 'http://127.0.0.1:3000', }, -}) +}); diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js index fd36e15a..37a498fb 100644 --- a/cypress/support/e2e.js +++ b/cypress/support/e2e.js @@ -18,5 +18,3 @@ import './commands'; // Alternatively you can use CommonJS syntax: // require('./commands') - -require('cypress-failed-log'); diff --git a/package.json b/package.json index a785c3d1..2c2432a9 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,6 @@ "connected-react-router": "6.9.3", "cookie-parser": "1.4.5", "custom-event-polyfill": "1.0.7", - "cypress-failed-log": "2.10.0", "eslint-config-prettier": "9.1.0", "eslint-plugin-cypress": "2.15.1", "eslint-plugin-prettier": "5.1.3", @@ -67,7 +66,7 @@ "lint:cypress": "eslint --ext=tsx --ext=js --ext=jsx --fix ./cypress", "serve:plugins": "node micro-frontend-tools/serve-plugins.js", "start": "cross-env concurrently \"yarn serve:plugins\" \"node server/auth-server.js\" \"react-scripts start\"", - "build:e2e": "cross-env GENERATE_SOURCEMAP=false react-scripts build", + "build:e2e": "cross-env GENERATE_SOURCEMAP=false yarn build", "test": "vitest --coverage", "test:watch": "react-scripts test --env=jsdom --watch", "e2e:serve": "yarn build:e2e && concurrently \"node server/auth-server.js e2e\" \"node ./server/e2e-test-server.js\"", @@ -138,4 +137,4 @@ "wait-on": "7.2.0" }, "packageManager": "yarn@4.1.0" -} \ No newline at end of file +} diff --git a/server/e2e-test-server.js b/server/e2e-test-server.js index 0263f4ba..41c60555 100644 --- a/server/e2e-test-server.js +++ b/server/e2e-test-server.js @@ -1,24 +1,26 @@ -var express = require('express'); -var path = require('path'); -var serveStatic = require('serve-static'); -var axios = require('axios'); +import express from 'express'; +import path from 'path'; +import serveStatic from 'serve-static'; +import axios from 'axios'; var app = express(); -app.get('/settings.json', function(req, res) { - res.sendFile(path.join(__dirname, 'e2e-settings.json')); +app.get('/settings.json', function (req, res) { + res.sendFile(path.resolve('./server/e2e-settings.json')); }); -app.get('/plugins/*', function(req, res) { - res.sendFile(path.join(__dirname, req.originalUrl.replace('/plugins/', ''))); +app.get('/plugins/*', function (req, res) { + res.sendFile( + path.resolve(`./server/${req.originalUrl.replace('/plugins/', '')}`) + ); }); app.use( express.json(), - serveStatic(path.resolve('./build'), { index: ['index.html', 'index.htm'] }) + serveStatic(path.resolve('./dist'), { index: ['index.html', 'index.htm'] }) ); -app.post('/api/*', function(req, res) { +app.post('/api/*', function (req, res) { axios .post('http://127.0.0.1:8000' + req.url, req.body) .then(apiRes => { @@ -29,8 +31,8 @@ app.post('/api/*', function(req, res) { }); }); -app.get('/*', function(req, res) { - res.sendFile(path.resolve('./build/index.html')); +app.get('/*', function (req, res) { + res.sendFile(path.resolve('./dist/index.html')); }); app.listen(3000); diff --git a/vite.config.ts b/vite.config.ts index 0865dd57..9cd1d626 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -53,12 +53,10 @@ export default defineConfig(({ command, mode }) => { exclude: [ 'public/*', 'server/*', - // Leave handlers to show up unused code - // 'src/mocks/browser.ts', - // 'src/mocks/server.ts', - // 'src/vite-env.d.ts', - // 'src/main.tsx', - // 'src/testUtils.tsx', + '__mocks__/axios.ts', + 'micro-frontend-tools/serve-plugins.js', + '.eslintrc.cjs', + 'src/main.tsx', ], }, }, diff --git a/yarn.lock b/yarn.lock index eb7473ef..34c4cb52 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4324,7 +4324,7 @@ __metadata: languageName: node linkType: hard -"chalk@npm:^2.3.0, chalk@npm:^2.4.2": +"chalk@npm:^2.4.2": version: 2.4.2 resolution: "chalk@npm:2.4.2" dependencies: @@ -4835,16 +4835,6 @@ __metadata: languageName: node linkType: hard -"cypress-failed-log@npm:2.10.0": - version: 2.10.0 - resolution: "cypress-failed-log@npm:2.10.0" - dependencies: - debug: "npm:4.3.4" - logdown: "npm:3.3.1" - checksum: 10/5321f401175d53a3c1ef8751b9e4c635f74e2f8a8461034469950d14cb7ccdaca5231ed6cd88c78341786e3bf2e938d107ed9f7443a656e9c407d761228c699b - languageName: node - linkType: hard - "cypress@npm:13.6.4": version: 13.6.4 resolution: "cypress@npm:13.6.4" @@ -7842,15 +7832,6 @@ __metadata: languageName: node linkType: hard -"logdown@npm:3.3.1": - version: 3.3.1 - resolution: "logdown@npm:3.3.1" - dependencies: - chalk: "npm:^2.3.0" - checksum: 10/2139caa178bd43ff8050df43e9aacb6cbc79815f07f2388a6715e3ea2b72078526671bbc44919e3bb2aba78c95c70f9afa7faa2f0bea148fb865943c114687f9 - languageName: node - linkType: hard - "loglevel@npm:1.9.1": version: 1.9.1 resolution: "loglevel@npm:1.9.1" @@ -9734,7 +9715,6 @@ __metadata: cross-env: "npm:7.0.3" custom-event-polyfill: "npm:1.0.7" cypress: "npm:13.6.4" - cypress-failed-log: "npm:2.10.0" eslint: "npm:8.56.0" eslint-config-prettier: "npm:9.1.0" eslint-config-react-app: "npm:7.0.0"