From 7394a35c51b120ef1a17d40db9929c05f2227cb0 Mon Sep 17 00:00:00 2001 From: Alexandre BODIN Date: Wed, 29 Jul 2020 13:24:27 +0200 Subject: [PATCH] Fix CE tests for travis (#7218) * Fix CE tests for travis Signed-off-by: Alexandre Bodin * Start app in CE too Signed-off-by: Alexandre Bodin * Cleanup Signed-off-by: Alexandre Bodin --- .travis.yml | 111 ++++++++++++------ .../strapi-admin/test/admin-auth.test.e2e.js | 14 ++- .../strapi-admin/test/admin-user.test.e2e.js | 15 ++- test/helpers/testAppGenerator.js | 6 +- 4 files changed, 104 insertions(+), 42 deletions(-) diff --git a/.travis.yml b/.travis.yml index 55e3be7390..c13584753c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,11 +23,66 @@ cache: # end to end testing template e2e_tests: &e2e_tests - stage: 'End to End tests' + stage: 'End to End tests CE' + script: + - STRAPI_DISABLE_EE=true yarn run -s test:generate-app -- $DB_STRING + - STRAPI_DISABLE_EE=true yarn run -s test:start-app & wait-on http://localhost:1337 + - STRAPI_DISABLE_EE=true yarn run -s test:e2e + +# end to end testing template +e2e_tests_ee: &e2e_tests_ee + stage: 'End to End tests EE' script: - yarn run -s test:generate-app -- $DB_STRING - yarn run -s test:start-app & wait-on http://localhost:1337 - yarn run -s test:e2e + if: fork = false + +pg_test: &pg_test + name: 'E2E Postgresql' + before_install: + - curl -o- -L https://yarnpkg.com/install.sh | bash + - export PATH="$HOME/.yarn/bin:$PATH" + - sudo apt-get update + - sudo apt-get --yes remove postgresql-* + - sudo apt-get install -y postgresql-11 postgresql-client-11 + - sudo cp /etc/postgresql/{9.6,11}/main/pg_hba.conf + - sudo service postgresql restart 11 + - psql -c 'create database strapi_test;' -U postgres + env: + - DB_STRING='--dbclient=postgres --dbhost=localhost --dbport=5433 --dbname=strapi_test --dbusername=postgres --dbpassword=' + +mysql_test: &mysql_test + name: 'E2E Mysql' + before_install: + - curl -o- -L https://yarnpkg.com/install.sh | bash + - export PATH="$HOME/.yarn/bin:$PATH" + - sudo cp $TRAVIS_BUILD_DIR/_travis/mysql.cnf /etc/mysql/conf.d/ + - sudo service mysql restart + - mysql -e 'CREATE DATABASE strapi_test;' + env: + - DB_STRING='--dbclient=mysql --dbhost=localhost --dbport=3306 --dbname=strapi_test --dbusername=travis --dbpassword=' + +sqlite_test: &sqlite_test + name: 'E2E Sqlite' + before_install: + - curl -o- -L https://yarnpkg.com/install.sh | bash + - export PATH="$HOME/.yarn/bin:$PATH" + env: + - DB_STRING='--dbclient=sqlite --dbfile=./tmp/data.db' + +mongo_test: &mongo_test + name: 'E2E MongoDB' + before_install: + - curl -o- -L https://yarnpkg.com/install.sh | bash + - export PATH="$HOME/.yarn/bin:$PATH" + - wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.6.6.tgz + - tar -zxvf mongodb-linux-x86_64-3.6.6.tgz + - mkdir -p ./data/db/27017 + - mkdir -p ./data/db/27000 + - ./mongodb-linux-x86_64-3.6.6/bin/mongod --fork --dbpath ./data/db/27017 --syslog --port 27017 + env: + - DB_STRING='--dbclient=mongo --dbhost=localhost --dbport=27017 --dbname=strapi_test --dbusername= --dbpassword=' before_script: - yarn build @@ -55,47 +110,25 @@ jobs: - yarn run -s test:front && codecov -C -F front - <<: *e2e_tests - name: 'E2E Postgresql' - before_install: - - curl -o- -L https://yarnpkg.com/install.sh | bash - - export PATH="$HOME/.yarn/bin:$PATH" - - sudo apt-get update - - sudo apt-get --yes remove postgresql-* - - sudo apt-get install -y postgresql-11 postgresql-client-11 - - sudo cp /etc/postgresql/{9.6,11}/main/pg_hba.conf - - sudo service postgresql restart 11 - - psql -c 'create database strapi_test;' -U postgres - env: - - DB_STRING='--dbclient=postgres --dbhost=localhost --dbport=5433 --dbname=strapi_test --dbusername=postgres --dbpassword=' + <<: *pg_test - <<: *e2e_tests - name: 'E2E Mysql' - before_install: - - curl -o- -L https://yarnpkg.com/install.sh | bash - - export PATH="$HOME/.yarn/bin:$PATH" - - sudo cp $TRAVIS_BUILD_DIR/_travis/mysql.cnf /etc/mysql/conf.d/ - - sudo service mysql restart - - mysql -e 'CREATE DATABASE strapi_test;' - env: - - DB_STRING='--dbclient=mysql --dbhost=localhost --dbport=3306 --dbname=strapi_test --dbusername=travis --dbpassword=' + <<: *mysql_test - <<: *e2e_tests - name: 'E2E Sqlite' - before_install: - - curl -o- -L https://yarnpkg.com/install.sh | bash - - export PATH="$HOME/.yarn/bin:$PATH" - env: - - DB_STRING='--dbclient=sqlite --dbfile=./tmp/data.db' + <<: *sqlite_test - <<: *e2e_tests - name: 'E2E MongoDB' - before_install: - - curl -o- -L https://yarnpkg.com/install.sh | bash - - export PATH="$HOME/.yarn/bin:$PATH" - - wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.6.6.tgz - - tar -zxvf mongodb-linux-x86_64-3.6.6.tgz - - mkdir -p ./data/db/27017 - - mkdir -p ./data/db/27000 - - ./mongodb-linux-x86_64-3.6.6/bin/mongod --fork --dbpath ./data/db/27017 --syslog --port 27017 - env: - - DB_STRING='--dbclient=mongo --dbhost=localhost --dbport=27017 --dbname=strapi_test --dbusername= --dbpassword=' + <<: *mongo_test + + - <<: *e2e_tests_ee + <<: *pg_test + + - <<: *e2e_tests_ee + <<: *mysql_test + + - <<: *e2e_tests_ee + <<: *sqlite_test + + - <<: *e2e_tests_ee + <<: *mongo_test diff --git a/packages/strapi-admin/test/admin-auth.test.e2e.js b/packages/strapi-admin/test/admin-auth.test.e2e.js index 0afb8e4dbc..d94d0ce514 100644 --- a/packages/strapi-admin/test/admin-auth.test.e2e.js +++ b/packages/strapi-admin/test/admin-auth.test.e2e.js @@ -4,6 +4,8 @@ const { registerAndLogin } = require('../../../test/helpers/auth'); const { createAuthRequest } = require('../../../test/helpers/request'); +const edition = process.env.STRAPI_DISABLE_EE === 'true' ? 'CE' : 'EE'; + let rq; const createAuthRole = async () => { @@ -42,7 +44,17 @@ describe('Admin Auth End to End', () => { beforeAll(async () => { const token = await registerAndLogin(); rq = createAuthRequest(token); - internals.role = await createAuthRole(); + + if (edition === 'EE') { + internals.role = await createAuthRole(); + } else { + internals.role = ( + await rq({ + url: '/admin/roles', + method: 'GET', + }) + ).body.data[0]; + } }, 60000); afterAll(async () => { diff --git a/packages/strapi-admin/test/admin-user.test.e2e.js b/packages/strapi-admin/test/admin-user.test.e2e.js index c84eb74cab..140d2d4766 100644 --- a/packages/strapi-admin/test/admin-user.test.e2e.js +++ b/packages/strapi-admin/test/admin-user.test.e2e.js @@ -5,6 +5,8 @@ const { login, registerAndLogin, getUser } = require('../../../test/helpers/auth const { createAuthRequest } = require('../../../test/helpers/request'); const { SUPER_ADMIN_CODE } = require('../services/constants'); +const edition = process.env.STRAPI_DISABLE_EE === 'true' ? 'CE' : 'EE'; + const omitTimestamps = obj => _.omit(obj, ['updatedAt', 'createdAt', 'updated_at', 'created_at']); const getAuthToken = async () => { @@ -85,7 +87,18 @@ describe('Admin User CRUD (e2e)', () => { beforeAll(async () => { const token = await getAuthToken(); rq = createAuthRequest(token); - testData.role = await createUserRole(); + + if (edition === 'EE') { + testData.role = await createUserRole(); + } else { + testData.role = ( + await rq({ + url: '/admin/roles', + method: 'GET', + }) + ).body.data[0]; + } + testData.firstSuperAdminUser = await getUser(); testData.superAdminRole = await getSuperAdminRole(); }); diff --git a/test/helpers/testAppGenerator.js b/test/helpers/testAppGenerator.js index cf9b3a37d0..75a4ed929a 100644 --- a/test/helpers/testAppGenerator.js +++ b/test/helpers/testAppGenerator.js @@ -65,9 +65,13 @@ const generateTestApp = async ({ appName, database }) => { * @param {string} options.appName - Name of the app / folder in which run the start script */ const startTestApp = ({ appName }) => { - return execa.shell('BROWSER=none strapi develop --no-build', { + return execa('strapi', ['develop', '--no-build'], { stdio: 'inherit', cwd: path.resolve(appName), + env: { + FORCE_COLOR: 1, + BROWSER: 'none', + }, }); };