better handle env variables in e2e tests

This commit is contained in:
Pierre Noël 2022-01-24 17:01:51 +01:00
parent e58b7266e1
commit 83d321a981
4 changed files with 10 additions and 7 deletions

View File

@ -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",

View File

@ -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);
});

View File

@ -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);

View File

@ -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"