mirror of
https://github.com/strapi/strapi.git
synced 2025-12-27 07:03:38 +00:00
chore(tests): backport e2e config (#19654)
This commit is contained in:
parent
20c4c0d001
commit
97eb67b367
3
.github/actions/run-e2e-tests/action.yml
vendored
3
.github/actions/run-e2e-tests/action.yml
vendored
@ -5,6 +5,8 @@ inputs:
|
||||
description: 'Should run EE or CE e2e tests'
|
||||
jestOptions:
|
||||
description: 'Jest options'
|
||||
enableFutureFeatures:
|
||||
description: 'Enable future unstable features'
|
||||
runs:
|
||||
using: 'composite'
|
||||
steps:
|
||||
@ -12,4 +14,5 @@ runs:
|
||||
env:
|
||||
RUN_EE: ${{ inputs.runEE }}
|
||||
JEST_OPTIONS: ${{ inputs.jestOptions }}
|
||||
STRAPI_FEATURES_FUTURE_RELEASES_SCHEDULING: ${{ inputs.enableFutureFeatures }}
|
||||
shell: bash
|
||||
|
||||
1
.github/workflows/tests.yml
vendored
1
.github/workflows/tests.yml
vendored
@ -225,6 +225,7 @@ jobs:
|
||||
uses: ./.github/actions/run-e2e-tests
|
||||
with:
|
||||
runEE: true
|
||||
enableFutureFeatures: true
|
||||
jestOptions: --project=${{ matrix.project }}
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@ -146,6 +146,7 @@ front-workspace.code-workspace
|
||||
playwright-report
|
||||
test-results
|
||||
!e2e/data/*.tar
|
||||
e2e/.env
|
||||
|
||||
############################
|
||||
# Strapi
|
||||
|
||||
@ -81,6 +81,14 @@ Playwright enables reliable end-to-end testing for modern web apps. It's cross b
|
||||
|
||||
For more information check out their [docs](https://playwright.dev/docs/intro). If you're struggling with their APIs, then check out their specific [API documentation](https://playwright.dev/docs/api/class-playwright).
|
||||
|
||||
## Running tests with environment variables
|
||||
|
||||
To set specific environment variables for your tests, a `.env` file can be created in the root of the e2e folder. This is useful if you need to run tests with a Strapi license or set future flags.
|
||||
|
||||
## Running tests with future flags
|
||||
|
||||
If you are writing tests for an unstable future feature you will need to add `app-template/config/features.js`. Currently the app template generation does not take the config folder into consideration. However, the run-e2e-tests script will apply the features config to the generated app. See the documentation for [features.js](https://docs.strapi.io/dev-docs/configurations/features#enabling-a-future-flag)
|
||||
|
||||
## What makes a good end to end test?
|
||||
|
||||
This is the million dollar question. E2E tests typically test complete user flows that touch numerous points of the application it's testing, we're not interested in what happens during a process, only the user perspective and end results. Consider writing them with your story hat on. E.g. "As a user I want to create a new entity, publish that entity, and then be able to retrieve its data from the content API".
|
||||
|
||||
5
e2e/app-template/config/features.js
Normal file
5
e2e/app-template/config/features.js
Normal file
@ -0,0 +1,5 @@
|
||||
module.exports = ({ env }) => ({
|
||||
future: {
|
||||
contentReleasesScheduling: env.bool('STRAPI_FEATURES_FUTURE_RELEASES_SCHEDULING', false),
|
||||
},
|
||||
});
|
||||
@ -10,13 +10,6 @@ describeOnCondition(edition === 'EE')('Releases page', () => {
|
||||
await resetDatabaseAndImportDataFromPath('./e2e/data/with-admin.tar');
|
||||
await page.goto('/admin');
|
||||
await login({ page });
|
||||
|
||||
await page.evaluate(() => {
|
||||
// Remove after Scheduling Beta release
|
||||
window.strapi.future = {
|
||||
isEnabled: () => true,
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
test('A user should be able to create a release without scheduling it and view their pending and done releases', async ({
|
||||
|
||||
@ -5,12 +5,55 @@ const execa = require('execa');
|
||||
const fs = require('node:fs/promises');
|
||||
const yargs = require('yargs');
|
||||
|
||||
const chalk = require('chalk');
|
||||
const dotenv = require('dotenv');
|
||||
const { cleanTestApp, generateTestApp } = require('../helpers/test-app');
|
||||
const { createConfig } = require('../../playwright.base.config');
|
||||
const chalk = require('chalk');
|
||||
|
||||
const cwd = path.resolve(__dirname, '../..');
|
||||
const testAppDirectory = path.join(cwd, 'test-apps', 'e2e');
|
||||
const testRoot = path.join(cwd, 'e2e');
|
||||
const templateDir = path.join(testRoot, 'app-template');
|
||||
|
||||
const pathExists = async (path) => {
|
||||
try {
|
||||
await fs.access(path);
|
||||
return true;
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the env file for a generated test app
|
||||
* - Removes the PORT key/value from generated app .env
|
||||
* - Uses e2e/app-template/config/features.js to enable future features in the generated app
|
||||
*/
|
||||
const setupTestEnvironment = async (generatedAppPath) => {
|
||||
/**
|
||||
* Because we're running multiple test apps at the same time
|
||||
* and the env file is generated by the generator with no way
|
||||
* to override it, we manually remove the PORT key/value so when
|
||||
* we set it further down for each playwright instance it works.
|
||||
*/
|
||||
const pathToEnv = path.join(generatedAppPath, '.env');
|
||||
const envFile = (await fs.readFile(pathToEnv)).toString();
|
||||
const envWithoutPort = envFile.replace('PORT=1337', '');
|
||||
await fs.writeFile(pathToEnv, envWithoutPort);
|
||||
|
||||
/*
|
||||
* Enable future features in the generated app manually since a template
|
||||
* does not allow the config folder.
|
||||
*/
|
||||
const testRootFeaturesConfigPath = path.join(templateDir, 'config', 'features.js');
|
||||
const hasFeaturesConfig = await pathExists(testRootFeaturesConfigPath);
|
||||
|
||||
if (!hasFeaturesConfig) return;
|
||||
|
||||
const configFeatures = await fs.readFile(testRootFeaturesConfigPath);
|
||||
const appFeaturesConfigPath = path.join(generatedAppPath, 'config', 'features.js');
|
||||
await fs.writeFile(appFeaturesConfigPath, configFeatures);
|
||||
};
|
||||
|
||||
yargs
|
||||
.parserConfiguration({
|
||||
@ -51,6 +94,11 @@ yargs
|
||||
},
|
||||
handler: async (argv) => {
|
||||
try {
|
||||
if (await pathExists(path.join(testRoot, '.env'))) {
|
||||
// Run tests with the env variables specified in the e2e/app-template/.env
|
||||
dotenv.config({ path: path.join(testRoot, '.env') });
|
||||
}
|
||||
|
||||
const { concurrency, domains, setup } = argv;
|
||||
|
||||
/**
|
||||
@ -109,16 +157,8 @@ yargs
|
||||
template: path.join(cwd, 'e2e', 'app-template'),
|
||||
link: true,
|
||||
});
|
||||
/**
|
||||
* Because we're running multiple test apps at the same time
|
||||
* and the env file is generated by the generator with no way
|
||||
* to override it, we manually remove the PORT key/value so when
|
||||
* we set it further down for each playwright instance it works.
|
||||
*/
|
||||
const pathToEnv = path.join(appPath, '.env');
|
||||
const envFile = (await fs.readFile(pathToEnv)).toString();
|
||||
const envWithoutPort = envFile.replace('PORT=1337', '');
|
||||
await fs.writeFile(pathToEnv, envWithoutPort);
|
||||
|
||||
await setupTestEnvironment(appPath);
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user