From 213422abb89cbad534c9ea67bc99eb6d95125bd3 Mon Sep 17 00:00:00 2001 From: Martin Marosi Date: Tue, 9 Apr 2024 11:07:49 +0200 Subject: [PATCH] chore: update tests to accept fake cdn assets --- .gitignore | 1 + dev-script.js | 6 +++++- examples/test-app-e2e/project.json | 1 + .../src/e2e/test-app/module-loading-errors.cy.ts | 4 ++-- federation-cdn-mock/webpack.config.js | 3 ++- package.json | 2 +- 6 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 5e9a2a2..08acce6 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,4 @@ Thumbs.db .nx .webpack-cache .vscode +.cdn-cache diff --git a/dev-script.js b/dev-script.js index c34e347..9cfd2d1 100644 --- a/dev-script.js +++ b/dev-script.js @@ -1,9 +1,10 @@ const concurrently = require('concurrently') const path = require('path') const fs = require('fs') +const { execSync } = require('child_process') const cdnPath = path.resolve(__dirname, './federation-cdn-mock') -const cdnAssetsPath = path.resolve(__dirname, './federation-cdn-mock/distx') +const cdnAssetsPath = path.resolve(__dirname, './federation-cdn-mock/dist') try { fs.statSync(cdnAssetsPath) @@ -12,6 +13,9 @@ try { fs.mkdirSync(cdnAssetsPath) } +// ensure the deps exist before we start the servers +execSync('npm run build', { cwd: cdnPath, stdio: 'inherit'}) + concurrently( [{ cwd: cdnPath, diff --git a/examples/test-app-e2e/project.json b/examples/test-app-e2e/project.json index 13609d8..df172ee 100644 --- a/examples/test-app-e2e/project.json +++ b/examples/test-app-e2e/project.json @@ -7,6 +7,7 @@ "e2e": { "executor": "@nx/cypress:cypress", "options": { + "skipServe": true, "cypressConfig": "examples/test-app-e2e/cypress.config.ts", "testingType": "e2e", "devServerTarget": "test-app:serve", diff --git a/examples/test-app-e2e/src/e2e/test-app/module-loading-errors.cy.ts b/examples/test-app-e2e/src/e2e/test-app/module-loading-errors.cy.ts index 02771e7..07d4f54 100644 --- a/examples/test-app-e2e/src/e2e/test-app/module-loading-errors.cy.ts +++ b/examples/test-app-e2e/src/e2e/test-app/module-loading-errors.cy.ts @@ -3,7 +3,7 @@ describe('Module error loading handling', () => { cy.visit('http://localhost:4200/legacy'); // intercept webpack chunk and return 500 response - cy.intercept('GET', '/src_modules_preLoad_tsx.js', { + cy.intercept('GET', 'http://localhost:8001/exposed-./PreLoadedModule.js', { statusCode: 500, }); @@ -16,7 +16,7 @@ describe('Module error loading handling', () => { cy.get('#render-preload-module').click(); cy.wait(1000); - cy.contains(`Loading chunk src_modules_preLoad_tsx failed.`).should('exist'); + cy.contains(`Loading chunk exposed-./PreLoadedModule failed.`).should('exist'); }); it('should handle runtime module error', () => { diff --git a/federation-cdn-mock/webpack.config.js b/federation-cdn-mock/webpack.config.js index 4490ec7..ee5c7f0 100644 --- a/federation-cdn-mock/webpack.config.js +++ b/federation-cdn-mock/webpack.config.js @@ -110,10 +110,11 @@ function init() { /** @type { import("webpack").Configuration } */ const config = { entry: {}, + cache: { type: 'filesystem', cacheDirectory: resolve(__dirname, '.cdn-cache')}, output: { publicPath: 'auto', }, - mode: 'production', + mode: 'development', plugins: [TestSDKPLugin], module: { rules: [ diff --git a/package.json b/package.json index b5e2728..1442a1b 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "dev": "node dev-script.js", "test:unit": "nx run-many -t test", "test:unit:affected": "nx affected -t test", - "test:e2e": "nx run test-app-e2e:e2e", + "test:e2e": "concurrently \"npm run dev\" \"nx run test-app-e2e:e2e\"", "test": "npm-run-all --parallel test:*", "build": "nx run-many -t build", "lint": "nx run-many -t lint",