Move e2e to api tests and unify test command

This commit is contained in:
Alexandre Bodin 2022-10-27 19:49:37 +02:00
parent 527b7852a5
commit 57e1eb5ee8
122 changed files with 87 additions and 130 deletions

View File

@ -1,5 +1,5 @@
name: 'Run E2E tests' name: 'Run API tests'
description: 'Run end to end tests' description: 'Run api tests'
inputs: inputs:
dbOptions: dbOptions:
description: 'Database options' description: 'Database options'

View File

@ -9,4 +9,4 @@ export JWT_SECRET="aSecret"
opts=($DB_OPTIONS) opts=($DB_OPTIONS)
yarn run -s test:generate-app "${opts[@]}" yarn run -s test:generate-app "${opts[@]}"
yarn run -s test:e2e $@ yarn run -s test:api --no-generate-app

View File

@ -74,10 +74,10 @@ jobs:
- name: Run test - name: Run test
run: yarn run -s test:front --coverage && codecov -C -F front run: yarn run -s test:front --coverage && codecov -C -F front
e2e_ce_pg: api_ce_pg:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [lint, unit_back, unit_front] needs: [lint, unit_back, unit_front]
name: '[CE] E2E (postgres, node: ${{ matrix.node }})' name: '[CE] API Integration (postgres, node: ${{ matrix.node }})'
strategy: strategy:
matrix: matrix:
node: [14, 16, 18] node: [14, 16, 18]
@ -106,14 +106,14 @@ jobs:
node-version: ${{ matrix.node }} node-version: ${{ matrix.node }}
cache: yarn cache: yarn
- uses: ./.github/actions/install-modules - uses: ./.github/actions/install-modules
- uses: ./.github/actions/run-e2e-tests - uses: ./.github/actions/run-api-tests
with: with:
dbOptions: '--dbclient=postgres --dbhost=localhost --dbport=5432 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi' dbOptions: '--dbclient=postgres --dbhost=localhost --dbport=5432 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi'
e2e_ce_mysql: api_ce_mysql:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [lint, unit_back, unit_front] needs: [lint, unit_back, unit_front]
name: '[CE] E2E (mysql, node: ${{ matrix.node }})' name: '[CE] API Integration (mysql, node: ${{ matrix.node }})'
strategy: strategy:
matrix: matrix:
node: [14, 16, 18] node: [14, 16, 18]
@ -141,14 +141,14 @@ jobs:
node-version: ${{ matrix.node }} node-version: ${{ matrix.node }}
cache: yarn cache: yarn
- uses: ./.github/actions/install-modules - uses: ./.github/actions/install-modules
- uses: ./.github/actions/run-e2e-tests - uses: ./.github/actions/run-api-tests
with: with:
dbOptions: '--dbclient=mysql --dbhost=localhost --dbport=3306 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi' 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 runs-on: ubuntu-latest
needs: [lint, unit_back, unit_front] needs: [lint, unit_back, unit_front]
name: '[CE] E2E (mysql:5 , node: ${{ matrix.node }})' name: '[CE] API Integration (mysql:5 , node: ${{ matrix.node }})'
strategy: strategy:
matrix: matrix:
node: [14, 16, 18] node: [14, 16, 18]
@ -176,14 +176,14 @@ jobs:
node-version: ${{ matrix.node }} node-version: ${{ matrix.node }}
cache: yarn cache: yarn
- uses: ./.github/actions/install-modules - uses: ./.github/actions/install-modules
- uses: ./.github/actions/run-e2e-tests - uses: ./.github/actions/run-api-tests
with: with:
dbOptions: '--dbclient=mysql --dbhost=localhost --dbport=3306 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi' dbOptions: '--dbclient=mysql --dbhost=localhost --dbport=3306 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi'
e2e_ce_sqlite: api_ce_sqlite:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [lint, unit_back, unit_front] 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: strategy:
matrix: matrix:
node: [14, 16, 18] node: [14, 16, 18]
@ -195,16 +195,16 @@ jobs:
node-version: ${{ matrix.node }} node-version: ${{ matrix.node }}
cache: yarn cache: yarn
- uses: ./.github/actions/install-modules - uses: ./.github/actions/install-modules
- uses: ./.github/actions/run-e2e-tests - uses: ./.github/actions/run-api-tests
env: env:
SQLITE_PKG: ${{ matrix.sqlite_pkg }} SQLITE_PKG: ${{ matrix.sqlite_pkg }}
with: with:
dbOptions: '--dbclient=sqlite-legacy --dbfile=./tmp/data.db' dbOptions: '--dbclient=sqlite-legacy --dbfile=./tmp/data.db'
# EE # EE
e2e_ee_pg: api_ee_pg:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [lint, unit_back, unit_front] 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]') if: github.event.pull_request.head.repo.full_name == github.repository && !(github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]')
env: env:
STRAPI_LICENSE: ${{ secrets.strapiLicense }} STRAPI_LICENSE: ${{ secrets.strapiLicense }}
@ -236,15 +236,15 @@ jobs:
node-version: ${{ matrix.node }} node-version: ${{ matrix.node }}
cache: yarn cache: yarn
- uses: ./.github/actions/install-modules - uses: ./.github/actions/install-modules
- uses: ./.github/actions/run-e2e-tests - uses: ./.github/actions/run-api-tests
with: with:
dbOptions: '--dbclient=postgres --dbhost=localhost --dbport=5432 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi' dbOptions: '--dbclient=postgres --dbhost=localhost --dbport=5432 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi'
runEE: true runEE: true
e2e_ee_mysql: api_ee_mysql:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [lint, unit_back, unit_front] 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]') if: github.event.pull_request.head.repo.full_name == github.repository && !(github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]')
env: env:
STRAPI_LICENSE: ${{ secrets.strapiLicense }} STRAPI_LICENSE: ${{ secrets.strapiLicense }}
@ -275,15 +275,15 @@ jobs:
node-version: ${{ matrix.node }} node-version: ${{ matrix.node }}
cache: yarn cache: yarn
- uses: ./.github/actions/install-modules - uses: ./.github/actions/install-modules
- uses: ./.github/actions/run-e2e-tests - uses: ./.github/actions/run-api-tests
with: with:
dbOptions: '--dbclient=mysql --dbhost=localhost --dbport=3306 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi' dbOptions: '--dbclient=mysql --dbhost=localhost --dbport=3306 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi'
runEE: true runEE: true
e2e_ee_sqlite: api_ee_sqlite:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [lint, unit_back, unit_front] 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]') if: github.event.pull_request.head.repo.full_name == github.repository && !(github.actor == 'dependabot[bot]' || github.actor == 'dependabot-preview[bot]')
env: env:
STRAPI_LICENSE: ${{ secrets.strapiLicense }} STRAPI_LICENSE: ${{ secrets.strapiLicense }}
@ -298,7 +298,7 @@ jobs:
node-version: ${{ matrix.node }} node-version: ${{ matrix.node }}
cache: yarn cache: yarn
- uses: ./.github/actions/install-modules - uses: ./.github/actions/install-modules
- uses: ./.github/actions/run-e2e-tests - uses: ./.github/actions/run-api-tests
env: env:
SQLITE_PKG: ${{ matrix.sqlite_pkg }} SQLITE_PKG: ${{ matrix.sqlite_pkg }}
with: with:

View File

@ -114,15 +114,15 @@ The administration panel should now be available at http://localhost:4000/admin.
- `yarn test:front` runs front-end related tests. - `yarn test:front` runs front-end related tests.
- `yarn test:front:watch` runs an interactive test watcher for the front-end. - `yarn test:front:watch` runs an interactive test watcher for the front-end.
- `yarn test:unit` runs the back-end unit tests. - `yarn test:unit` runs the back-end unit tests.
- `yarn test:e2e` runs an end-to-end test suite. - `yarn test:api` runs an end-to-end test suite.
- `yarn test:generate-app` generates a test application. - `yarn test:generate-app` generates a test application.
- `yarn test:start-app` starts the 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 ```bash
$ yarn test:generate-app sqlite $ yarn test:generate-app sqlite
@ -130,36 +130,27 @@ $ yarn test:generate-app postgres
$ yarn test:generate-app mysql $ 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 behing the scenes. Options for jest can be passed in the command. (e.g. to update snapshots `yarn test:api -u`).
### Changing the database ### 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 test commmand creates an app that uses `sqlite`. But you can run the test suites using different databases:
```bash ```bash
$ node test/e2e.js --db=sqlite $ yarn test:api --db=sqlite
$ node test/e2e.js --db=postgres $ yarn test:api --db=postgres
$ node test/e2e.js --db=mysql $ 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 ```bash
$ STRAPI_DISABLE_EE=true node test/e2e.js $ STRAPI_LICENSE=<license> yarn test:api
$ 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
``` ```
--- ---

View File

@ -1,9 +1,8 @@
module.exports = { module.exports = {
displayName: 'API integration tests', displayName: 'API integration tests',
testMatch: ['**/?(*.)+(spec|test).e2e.js'], testMatch: ['**/?(*.)+(spec|test).api.js'],
testEnvironment: 'node', testEnvironment: 'node',
setupFilesAfterEnv: ['<rootDir>/test/jest2e2.setup.js'], setupFilesAfterEnv: ['<rootDir>/test/jest-api.setup.js'],
testPathIgnorePatterns: ['<rootDir>/packages/core/database.old'],
coveragePathIgnorePatterns: [ coveragePathIgnorePatterns: [
'<rootDir>/dist/', '<rootDir>/dist/',
'<rootDir>/node_modules/', '<rootDir>/node_modules/',

View File

@ -13,7 +13,7 @@
"**/dist/*", "**/dist/*",
"**/build/*", "**/build/*",
"**/*.test.js", "**/*.test.js",
"**/*.test.e2e.js", "**/*.test.api.js",
"**/examples/getstarted/*", "**/examples/getstarted/*",
"**/examples/kitchensink/*" "**/examples/kitchensink/*"
] ]

View File

@ -51,7 +51,7 @@
"test:front:watch:ce": "cross-env IS_EE=false jest --config ./jest.config.front.js --watchAll", "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:front:update:ce": "cross-env IS_EE=false jest --config ./jest.config.front.js --u",
"test:unit": "jest --verbose", "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", "test:generate-app": "node test/create-test-app.js",
"doc:api": "node scripts/open-api/serve.js" "doc:api": "node scripts/open-api/serve.js"
}, },
@ -104,7 +104,7 @@
"stylelint-config-styled-components": "0.1.1", "stylelint-config-styled-components": "0.1.1",
"stylelint-processor-styled-components": "1.10.0", "stylelint-processor-styled-components": "1.10.0",
"supertest": "6.2.4", "supertest": "6.2.4",
"yargs": "13.3.2" "yargs": "17.6.0"
}, },
"engines": { "engines": {
"node": ">=14.19.1 <=18.x.x", "node": ">=14.19.1 <=18.x.x",

Some files were not shown because too many files have changed in this diff Show More