From 01017b007556254e92f9c1b644482c10b844eac7 Mon Sep 17 00:00:00 2001 From: Dominik Henneke Date: Thu, 10 Aug 2023 16:57:34 +0200 Subject: [PATCH] Add a new script to include an example module for Cypress tests Signed-off-by: Dominik Henneke --- module_system/BuildConfig.ts | 5 +++-- package.json | 1 + webpack.config.js | 5 +++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/module_system/BuildConfig.ts b/module_system/BuildConfig.ts index 59e17d0da93..98a1e0d8386 100644 --- a/module_system/BuildConfig.ts +++ b/module_system/BuildConfig.ts @@ -26,8 +26,9 @@ export type BuildConfig = { }; export function readBuildConfig(): BuildConfig { - if (fs.existsSync("./build_config.yaml")) { - return YAML.parse(fs.readFileSync("./build_config.yaml", "utf-8")); + const configFile = process.env.ELEMENT_BUILD_CONFIG ?? "./build_config.yaml"; + if (fs.existsSync(configFile)) { + return YAML.parse(fs.readFileSync(configFile, "utf-8")); } return {}; // no config } diff --git a/package.json b/package.json index 5cfbd751c3a..ebf4d4be171 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "start:https": "concurrently --kill-others-on-fail --prefix \"{time} [{name}]\" -n res,element-js \"yarn start:res\" \"yarn start:js --https\"", "start:res": "yarn build:jitsi && node scripts/copy-res.js -w", "start:js": "webpack-dev-server --output-filename=bundles/_dev_/[name].js --output-chunk-filename=bundles/_dev_/[name].js -w --mode development --disable-host-check --hot", + "start:e2e": "ELEMENT_BUILD_CONFIG='node_modules/matrix-react-sdk/cypress/example_module/build_config.yaml' yarn start", "lint": "yarn lint:types && yarn lint:js && yarn lint:style", "lint:js": "yarn lint:js:src && yarn lint:js:module_system", "lint:js:src": "eslint --max-warnings 0 src test && prettier --check .", diff --git a/webpack.config.js b/webpack.config.js index 198be2059a7..22d30c487e0 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -277,6 +277,11 @@ module.exports = (env, argv) => { // probably be removed. if (f.includes("@vector-im/compound-web")) return true; + // In Cypress we define an example module to test the Module API. + // This is written in typescript and directly imported, so we need + // to apply babel to it to compile it. + if (f.includes("example_module")) return true; + // but we can't run all of our dependencies through babel (many of them still // use module.exports which breaks if babel injects an 'include' for its // polyfills: probably fixable but babeling all our dependencies is probably