From 83d321a9817f45f99fd90f4480359d12b01440ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20No=C3=ABl?= Date: Mon, 24 Jan 2022 17:01:51 +0100 Subject: [PATCH] better handle env variables in e2e tests --- package.json | 1 + test/e2e.js | 8 +------- test/helpers/strapi.js | 3 +++ yarn.lock | 5 +++++ 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index e61c89d4f4..8470f68368 100644 --- a/package.json +++ b/package.json @@ -79,6 +79,7 @@ "chalk": "4.1.1", "chokidar": "3.5.1", "cross-env": "7.0.3", + "dotenv": "14.2.0", "enzyme": "3.9.0", "enzyme-adapter-react-16": "1.15.6", "eslint": "7.25.0", diff --git a/test/e2e.js b/test/e2e.js index 33d523d209..a1084c83cd 100644 --- a/test/e2e.js +++ b/test/e2e.js @@ -8,7 +8,6 @@ const appName = 'testApp'; process.env.ENV_PATH = path.resolve(__dirname, '..', appName, '.env'); const { cleanTestApp, generateTestApp } = require('./helpers/test-app-generator'); -const { createStrapiInstance } = require('./helpers/strapi'); const databases = { postgres: { @@ -41,10 +40,6 @@ const databases = { }; const runAllTests = async args => { - // start and destroy instance once so it correctly generate env variables without concurrent instances - await createStrapiInstance(); - await strapi.destroy(); - return execa('yarn', ['test:e2e', ...args], { stdio: 'inherit', cwd: path.resolve(__dirname, '..'), @@ -60,8 +55,7 @@ const main = async (database, args) => { await cleanTestApp(appName); await generateTestApp({ appName, database }); - await runAllTests(args).catch(e => { - console.error(e); + await runAllTests(args).catch(() => { process.stdout.write('Tests failed\n', () => { process.exit(1); }); diff --git a/test/helpers/strapi.js b/test/helpers/strapi.js index 33a1153c53..8b41dbde0c 100644 --- a/test/helpers/strapi.js +++ b/test/helpers/strapi.js @@ -2,6 +2,7 @@ const path = require('path'); const _ = require('lodash'); +const dotenv = require('dotenv'); const strapi = require('../../packages/core/strapi/lib'); const { createUtils } = require('./utils'); @@ -21,6 +22,8 @@ const createStrapiInstance = async ({ logLevel = 'fatal', bypassAuth = true, } = {}) => { + // read .env file as it could have been updated + dotenv.config({ path: process.env.ENV_PATH }); const options = { dir: TEST_APP_URL }; const instance = strapi(options); diff --git a/yarn.lock b/yarn.lock index afe6053414..b49724cfeb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9639,6 +9639,11 @@ dotenv@10.0.0: resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81" integrity sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q== +dotenv@14.2.0: + version "14.2.0" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-14.2.0.tgz#7e77fd5dd6cff5942c4496e1acf2d0f37a9e67aa" + integrity sha512-05POuPJyPpO6jqzTNweQFfAyMSD4qa4lvsMOWyTRTdpHKy6nnnN+IYWaXF+lHivhBH/ufDKlR4IWCAN3oPnHuw== + dotenv@8.5.1: version "8.5.1" resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.5.1.tgz#e3a4c7862daba51b92bce0da5c349f11faa28663"