Skip to content

Commit

Permalink
Move e2e to api tests and unify test command
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrebodin committed Oct 27, 2022
1 parent 527b785 commit 57e1eb5
Show file tree
Hide file tree
Showing 122 changed files with 87 additions and 130 deletions.
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 an end-to-end test suite.
- `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 behing the scenes. Options for jest can be passed in 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 test commmand creates an app that uses `sqlite`. 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
27 changes: 21 additions & 6 deletions test/e2e.js → test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,32 @@ const databases = {
},
};

const jestCmd =
'jest --config jest.config.api.js --verbose --runInBand --forceExit --detectOpenHandles'.split(
' '
);

const runAllTests = async (args) => {
return execa('yarn', ['test:e2e', ...args], {
console.log(args);
return execa('yarn', [...jestCmd, ...args], {
stdio: 'inherit',
cwd: path.resolve(__dirname, '..'),
env: {
// if STRAPI_LICENSE is in the env the test will run in ee automatically
STRAPI_DISABLE_EE: !process.env.STRAPI_LICENSE,
FORCE_COLOR: 1,
ENV_PATH: process.env.ENV_PATH,
JWT_SECRET: 'aSecret',
},
});
};

const main = async (database, args) => {
const main = async ({ database, generateApp }, args) => {
try {
await cleanTestApp(appName);
await generateTestApp({ appName, database });
if (generateApp) {
await cleanTestApp(appName);
await generateTestApp({ appName, database });
}

await runAllTests(args).catch(() => {
process.stdout.write('Tests failed\n', () => {
Expand All @@ -74,6 +84,9 @@ const main = async (database, args) => {
};

yargs
.parserConfiguration({
'unknown-options-as-args': true,
})
.command(
'$0',
'run end to end tests',
Expand All @@ -84,11 +97,13 @@ yargs
choices: Object.keys(databases),
default: 'sqlite',
});

yarg.boolean('generate-app');
},
(argv) => {
const { database, _: args } = argv;
const { database, generateApp = true } = argv;

main(databases[database], args);
main({ generateApp, database: databases[database] }, argv._);
}
)
.help()
Expand Down
1 change: 1 addition & 0 deletions test/create-test-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const databases = {
connection: {
filename: './tmp/data.db',
},
useNullAsDefault: true,
},
};

Expand Down
File renamed without changes.
Loading

0 comments on commit 57e1eb5

Please sign in to comment.