Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move e2e to api tests and unify test command #14733

Merged
merged 4 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'Run E2E tests'
description: 'Run end to end tests'
name: 'Run API tests'
description: 'Run api tests'
inputs:
dbOptions:
description: 'Database options'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ export JWT_SECRET="aSecret"
opts=($DB_OPTIONS)

yarn run -s test:generate-app "${opts[@]}"
yarn run -s test:e2e $@
yarn run -s test:api --no-generate-app
42 changes: 21 additions & 21 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ jobs:
- name: Run test
run: yarn run -s test:front --coverage && codecov -C -F front

e2e_ce_pg:
api_ce_pg:
runs-on: ubuntu-latest
needs: [lint, unit_back, unit_front]
name: '[CE] E2E (postgres, node: ${{ matrix.node }})'
name: '[CE] API Integration (postgres, node: ${{ matrix.node }})'
strategy:
matrix:
node: [14, 16, 18]
Expand Down Expand Up @@ -106,14 +106,14 @@ jobs:
node-version: ${{ matrix.node }}
cache: yarn
- uses: ./.github/actions/install-modules
- uses: ./.github/actions/run-e2e-tests
- uses: ./.github/actions/run-api-tests
with:
dbOptions: '--dbclient=postgres --dbhost=localhost --dbport=5432 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi'

e2e_ce_mysql:
api_ce_mysql:
runs-on: ubuntu-latest
needs: [lint, unit_back, unit_front]
name: '[CE] E2E (mysql, node: ${{ matrix.node }})'
name: '[CE] API Integration (mysql, node: ${{ matrix.node }})'
strategy:
matrix:
node: [14, 16, 18]
Expand Down Expand Up @@ -141,14 +141,14 @@ jobs:
node-version: ${{ matrix.node }}
cache: yarn
- uses: ./.github/actions/install-modules
- uses: ./.github/actions/run-e2e-tests
- uses: ./.github/actions/run-api-tests
with:
dbOptions: '--dbclient=mysql --dbhost=localhost --dbport=3306 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi'

e2e_ce_mysql_5:
api_ce_mysql_5:
runs-on: ubuntu-latest
needs: [lint, unit_back, unit_front]
name: '[CE] E2E (mysql:5 , node: ${{ matrix.node }})'
name: '[CE] API Integration (mysql:5 , node: ${{ matrix.node }})'
strategy:
matrix:
node: [14, 16, 18]
Expand Down Expand Up @@ -176,14 +176,14 @@ jobs:
node-version: ${{ matrix.node }}
cache: yarn
- uses: ./.github/actions/install-modules
- uses: ./.github/actions/run-e2e-tests
- uses: ./.github/actions/run-api-tests
with:
dbOptions: '--dbclient=mysql --dbhost=localhost --dbport=3306 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi'

e2e_ce_sqlite:
api_ce_sqlite:
runs-on: ubuntu-latest
needs: [lint, unit_back, unit_front]
name: '[CE] E2E (sqlite: ${{ matrix.sqlite_pkg }}, node: ${{ matrix.node }})'
name: '[CE] API Integration (sqlite: ${{ matrix.sqlite_pkg }}, node: ${{ matrix.node }})'
strategy:
matrix:
node: [14, 16, 18]
Expand All @@ -195,16 +195,16 @@ jobs:
node-version: ${{ matrix.node }}
cache: yarn
- uses: ./.github/actions/install-modules
- uses: ./.github/actions/run-e2e-tests
- uses: ./.github/actions/run-api-tests
env:
SQLITE_PKG: ${{ matrix.sqlite_pkg }}
with:
dbOptions: '--dbclient=sqlite-legacy --dbfile=./tmp/data.db'
# EE
e2e_ee_pg:
api_ee_pg:
runs-on: ubuntu-latest
needs: [lint, unit_back, unit_front]
name: '[EE] E2E (postgres, node: ${{ matrix.node }})'
name: '[EE] API Integration (postgres, node: ${{ matrix.node }})'
if: github.event.pull_request.head.repo.full_name == github.repository && !(github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]')
env:
STRAPI_LICENSE: ${{ secrets.strapiLicense }}
Expand Down Expand Up @@ -236,15 +236,15 @@ jobs:
node-version: ${{ matrix.node }}
cache: yarn
- uses: ./.github/actions/install-modules
- uses: ./.github/actions/run-e2e-tests
- uses: ./.github/actions/run-api-tests
with:
dbOptions: '--dbclient=postgres --dbhost=localhost --dbport=5432 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi'
runEE: true

e2e_ee_mysql:
api_ee_mysql:
runs-on: ubuntu-latest
needs: [lint, unit_back, unit_front]
name: '[EE] E2E (mysql, node: ${{ matrix.node }})'
name: '[EE] API Integration (mysql, node: ${{ matrix.node }})'
if: github.event.pull_request.head.repo.full_name == github.repository && !(github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]')
env:
STRAPI_LICENSE: ${{ secrets.strapiLicense }}
Expand Down Expand Up @@ -275,15 +275,15 @@ jobs:
node-version: ${{ matrix.node }}
cache: yarn
- uses: ./.github/actions/install-modules
- uses: ./.github/actions/run-e2e-tests
- uses: ./.github/actions/run-api-tests
with:
dbOptions: '--dbclient=mysql --dbhost=localhost --dbport=3306 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi'
runEE: true

e2e_ee_sqlite:
api_ee_sqlite:
runs-on: ubuntu-latest
needs: [lint, unit_back, unit_front]
name: '[EE] E2E (sqlite: ${{ matrix.sqlite_pkg }}, node: ${{ matrix.node }})'
name: '[EE] API Integration (sqlite: ${{ matrix.sqlite_pkg }}, node: ${{ matrix.node }})'
if: github.event.pull_request.head.repo.full_name == github.repository && !(github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]')
env:
STRAPI_LICENSE: ${{ secrets.strapiLicense }}
Expand All @@ -298,7 +298,7 @@ jobs:
node-version: ${{ matrix.node }}
cache: yarn
- uses: ./.github/actions/install-modules
- uses: ./.github/actions/run-e2e-tests
- uses: ./.github/actions/run-api-tests
env:
SQLITE_PKG: ${{ matrix.sqlite_pkg }}
with:
Expand Down
35 changes: 13 additions & 22 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,52 +114,43 @@ The administration panel should now be available at http://localhost:4000/admin.
- `yarn test:front` runs front-end related tests.
- `yarn test:front:watch` runs an interactive test watcher for the front-end.
- `yarn test:unit` runs the back-end unit tests.
- `yarn test:e2e` runs an end-to-end test suite.
- `yarn test:api` runs the api integration tests.
- `yarn test:generate-app` generates a test application.
- `yarn test:start-app` starts the test application.

---

## Running the End-To-End (e2e) tests
## Running the API Integration tests

The end-to-end tests require a Strapi app to be able to run. You can generate a "test app" using `yarn test:generate-app <database>`:
The API integration tests require a Strapi app to be able to run. You can generate a "test app" using `yarn test:generate-app <database>`:

```bash
$ yarn test:generate-app sqlite
$ yarn test:generate-app postgres
$ yarn test:generate-app mysql
```

A new app is required every time you run the end-to-end tests otherwise, the test suite will fail. A script is available to make this process easier: `node test/e2e.js`. It will delete the current test app, generate a new one and run the test suite.
A new app is required every time you run the API integration tests, otherwise the test suite will fail. A command is available to make this process easier: `yarn test:api`.

The script takes a path as optional argument (e.g. `node test/e2e.js path/to/test`). Options for jest can be passed using the double-dash notion: e.g. to update snapshots `node test/e2e.js -- -u`.
This command runs tests using jest behind the scenes. Options for jest can be passed to the command. (e.g. to update snapshots `yarn test:api -u`).

### Changing the database

By default the script `test/e2e.js` creates an app that uses `sqlite`. But you can run the test suites using different databases:
By default the script run by `test:api` an app that uses `sqlite` as a database. But you can run the test suites using different databases:

```bash
$ node test/e2e.js --db=sqlite
$ node test/e2e.js --db=postgres
$ node test/e2e.js --db=mysql
$ yarn test:api --db=sqlite
$ yarn test:api --db=postgres
$ yarn test:api --db=mysql
```

### Running the tests for the Community Editon (CE)\*\*
### Running the tests for the Enterprise Editon (EE)

The test suites run the tests for the Enterprise Edition (EE) version of Strapi by default. Should you want to test the Community Edition (CE) version, you will need to set the environment variable `STRAPI_DISABLE_EE` to true:
The test suites run the tests for the Community Edition (CE) version of Strapi by default.
In order to run the Enterprise Edition tests you need a valid license. To specify a license, you can use the environment variable `STRAPI_LICENSE`:

```bash
$ STRAPI_DISABLE_EE=true node test/e2e.js
$ STRAPI_DISABLE_EE=true yarn test:e2e
```

### Specifying a license to use for the Enterprise Edition (EE)

The Enterprise Edition tests need a valid license to run correctly. To specify a license, you can use the environment variable `STRAPI_LICENSE`:

```bash
$ STRAPI_LICENSE=<license> node test/e2e.js
$ STRAPI_LICENSE=<license> yarn test:e2e
$ STRAPI_LICENSE=<license> yarn test:api
```

---
Expand Down
5 changes: 2 additions & 3 deletions jest.config.e2e.js → jest.config.api.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
module.exports = {
displayName: 'API integration tests',
testMatch: ['**/?(*.)+(spec|test).e2e.js'],
testMatch: ['**/?(*.)+(spec|test).api.js'],
testEnvironment: 'node',
setupFilesAfterEnv: ['<rootDir>/test/jest2e2.setup.js'],
testPathIgnorePatterns: ['<rootDir>/packages/core/database.old'],
setupFilesAfterEnv: ['<rootDir>/test/jest-api.setup.js'],
coveragePathIgnorePatterns: [
'<rootDir>/dist/',
'<rootDir>/node_modules/',
Expand Down
2 changes: 1 addition & 1 deletion jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"**/dist/*",
"**/build/*",
"**/*.test.js",
"**/*.test.e2e.js",
"**/*.test.api.js",
"**/examples/getstarted/*",
"**/examples/kitchensink/*"
]
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"test:front:watch:ce": "cross-env IS_EE=false jest --config ./jest.config.front.js --watchAll",
"test:front:update:ce": "cross-env IS_EE=false jest --config ./jest.config.front.js --u",
"test:unit": "jest --verbose",
"test:e2e": "FORCE_COLOR=true jest --config jest.config.e2e.js --verbose --runInBand --testRunner=jest-circus/runner --forceExit --detectOpenHandles",
"test:api": "node test/api.js",
"test:generate-app": "node test/create-test-app.js",
"doc:api": "node scripts/open-api/serve.js"
},
Expand Down Expand Up @@ -104,7 +104,7 @@
"stylelint-config-styled-components": "0.1.1",
"stylelint-processor-styled-components": "1.10.0",
"supertest": "6.2.4",
"yargs": "13.3.2"
"yargs": "17.6.0"
},
"engines": {
"node": ">=14.19.1 <=18.x.x",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { createStrapiInstance } = require('../../../../../test/helpers/strapi');
const { createAuthRequest } = require('../../../../../test/helpers/request');
const constants = require('../services/constants');

describe('Admin API Token v2 CRUD (e2e)', () => {
describe('Admin API Token v2 CRUD (api)', () => {
let rq;
let strapi;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Admin Auth End to End', () => {
if (edition === 'EE') {
internals.role = await utils.createRole({
name: 'auth_test_role',
description: 'Only used for auth crud test (e2e)',
description: 'Only used for auth crud test (api)',
});
} else {
internals.role = await utils.getSuperAdminRole();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const omitRegistrationToken = omit(['registrationToken']);
* 16. Finds a list of users (missing user)
*/

describe('Admin User CRUD (e2e)', () => {
describe('Admin User CRUD (api)', () => {
let rq;
let utils;
let strapi;
Expand All @@ -50,7 +50,7 @@ describe('Admin User CRUD (e2e)', () => {
const createUserRole = async () =>
utils.createRole({
name: 'user_test_role',
description: 'Only used for user crud test (e2e)',
description: 'Only used for user crud test (api)',
});

// Initialization Actions
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
'use strict';

// Helpers.
const { createTestBuilder } = require('../../../../../../test/helpers/builder');
const { createStrapiInstance } = require('../../../../../../test/helpers/strapi');
const form = require('../../../../../../test/helpers/generators');
const { createAuthRequest } = require('../../../../../../test/helpers/request');

const builder = createTestBuilder();
let strapi;
let rq;

const restart = async () => {
await strapi.destroy();
strapi = await createStrapiInstance();
rq = await createAuthRequest({ strapi });
};

describe('Content Manager - Hide relations', () => {
beforeAll(async () => {
await builder.addContentTypes([form.article]).build();

strapi = await createStrapiInstance();
rq = await createAuthRequest({ strapi });
});

afterAll(async () => {
await strapi.destroy();
await builder.cleanup();
});

test('Hide relations', async () => {
await rq({
url: '/content-manager/content-types/api::article.article/configuration',
method: 'PUT',
body: {
layouts: {
edit: [],
editRelations: [],
list: [],
},
},
});

const { body } = await rq({
url: '/content-manager/content-types/api::article.article/configuration',
method: 'GET',
});

expect(body.data.contentType.layouts.editRelations).toStrictEqual([]);
});

test('Hide relations after server restart', async () => {
await rq({
url: '/content-manager/content-types/api::article.article/configuration',
method: 'PUT',
body: {
layouts: {
edit: [],
editRelations: [],
list: [],
},
},
});

await restart();

const { body } = await rq({
url: '/content-manager/content-types/api::article.article/configuration',
method: 'GET',
});

expect(body.data.contentType.layouts.editRelations).toStrictEqual([]);
});
});