From 6b417aa1fa121f44696494ce61b7738e5a37b2b7 Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Tue, 12 Mar 2019 11:58:30 +0100 Subject: [PATCH] Setup travis jobs and stages --- .travis.yml | 82 +++++++++++++------ cypress.json | 2 +- cypress/support/commands.js | 2 +- package.json | 4 +- .../test/endpoint.test.e2e.js | 9 +- .../lib/utils/connectivity.js | 12 +-- .../test/index.test.e2e.js | 21 +++-- .../package.json | 2 +- test/cypress.js | 2 +- test/e2e.js | 4 +- 10 files changed, 91 insertions(+), 49 deletions(-) diff --git a/.travis.yml b/.travis.yml index 571a0d5a08e..e4d7f19e308 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ services: - mongodb - postgresql + - mysql sudo: required dist: trusty @@ -9,39 +10,68 @@ language: node_js node_js: - '10' - # - '11' + +cache: + directories: + - node_modules + - ~/.npm + - ~/.cache + +# end to end testing template +e2e_tests: &e2e_tests + stage: 'End to End tests' + script: + - npm run -s test:generate-app -- $DB_STRING + - npm run -s test:start-app & wait-on http://localhost:1337 + - npm run -s test:e2e install: - - npm run setup:build + - npm run setup:ci - npm install -g wait-on - - cypress install -before_script: - - psql -c 'create database strapi_test;' -U postgres +jobs: + include: + - stage: test + name: 'Lint / Snyk / Unit Tests ' + script: + - npm run -s lint + - npm run -s test:snyk + - npm run -s test:unit -script: - # run snyk - - npm run -s test:snyk + - <<: *e2e_tests + name: 'E2E Postgresql' + before_install: + - psql -c 'create database strapi_test;' -U postgres + env: + - DB_STRING='--dbclient=postgres --dbhost=localhost --dbport=5432 --dbname=strapi_test --dbusername=postgres --dbpassword=' - # default unit test - - npm run -s test:unit + - <<: *e2e_tests + name: 'E2E Mysql' + before_install: + - mysql -e 'CREATE DATABASE strapi_test;' + env: + # mysql + - DB_STRING='--dbclient=mysql --dbhost=localhost --dbport=3306 --dbname=strapi_test --dbusername=travis --dbpassword=' - # e2e trests - - npm run -s test:generate-app --dbclient=postgres --dbhost=localhost --dbport=5432 --dbname=strapi_test --dbusername=postgres --dbpassword= - - npm run -s test:start-app & wait-on http://localhost:1337 - - npm run -s test:e2e + - <<: *e2e_tests + name: 'E2E Sqlite' + env: + # sqlite + - DB_STRING='--dbclient=sqlite --dbfile=./tmp/data.db' - # cypress tests - - npm run -s test:generate-app --dbclient=mongo --dbhost=localhost --dbport=27017 --dbname=strapi_test --dbusername= --dbpassword= - - npm run -s test:start-app & wait-on http://localhost:1337 - - npm run -s cypress:run + - <<: *e2e_tests + name: 'E2E MongoDB' + env: + # mongo + - DB_STRING='--dbclient=mongo --dbhost=localhost --dbport=27017 --dbname=strapi_test --dbusername= --dbpassword=' - # lint and doc - - npm run -s lint - - npm run -s doc + - name: 'Cypress tests' + install: + - npm run setup:build + - npm install -g wait-on + - cypress install + script: + - npm run -s test:generate-app -- --dbclient=mongo --dbhost=localhost --dbport=27017 --dbname=strapi_test --dbusername= --dbpassword= + - npm run -s test:start-app & wait-on http://localhost:1337 + - node test/cypress.js -cache: - directories: - - node_modules - - ~/.npm - - ~/.cache diff --git a/cypress.json b/cypress.json index 5e0dd3f8789..5049d4c3f71 100644 --- a/cypress.json +++ b/cypress.json @@ -2,7 +2,7 @@ "chromeWebSecurity": false, "backendUrl": "http://localhost:1337", "baseUrl": "http://localhost:1337", - "frontLoadingDelay": 3000, + "frontLoadingDelay": 5000, "animDelay": 1000, "serverRestartDelay": 11000, "viewportHeight": 900, diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 44f2bc6d0f1..04f3dba1f8b 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -27,7 +27,7 @@ const stringify = JSON.stringify; const backendUrl = Cypress.config('backendUrl'); const serverRestartDelay = Cypress.config('serverRestartDelay'); -const WAIT_ON_CMD = 'wait-on http://localhost:1337'; +const WAIT_ON_CMD = `wait-on ${backendUrl}`; Cypress.Commands.add('waitRestart', () => { return cy.exec(WAIT_ON_CMD); diff --git a/package.json b/package.json index 5d71e4e4dd1..77d23d7771c 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "removesymlinkdependencies": "node ./scripts/removeSymlinkDependencies.js", "setup:build": "npm run setup --build", "setup": "npm run clean:all && npm install ./packages/strapi-lint --save-dev && npm install && node ./scripts/setup.js && npm run clean", + "setup:ci": "npm install && node ./scripts/setup.js", "prettier": "node ./packages/strapi-lint/lib/internals/prettier/index.js", "lint": "node ./scripts/lint.js", "snyk": "node ./scripts/snyk.js", @@ -43,8 +44,7 @@ "test:unit": "FORCE_COLOR=true lerna run test --parallel", "test:e2e": "FORCE_COLOR=true jest --config jest.config.e2e.js --runInBand --verbose --forceExit --detectOpenHandles", "test:generate-app": "node test/createTestApp.js", - "test:start-app": "node test/startTestApp.js", - "cypress:run": "node test/cypress" + "test:start-app": "node test/startTestApp.js" }, "author": { "email": "hi@strapi.io", diff --git a/packages/strapi-generate-api/test/endpoint.test.e2e.js b/packages/strapi-generate-api/test/endpoint.test.e2e.js index 37f00ff768a..3c08b8a85c0 100644 --- a/packages/strapi-generate-api/test/endpoint.test.e2e.js +++ b/packages/strapi-generate-api/test/endpoint.test.e2e.js @@ -20,7 +20,10 @@ describe('Create Strapi API End to End', () => { url: '/auth/local/register', method: 'POST', body: auth, - }).catch(() => {}); + }).catch(err => { + if (err.error.message.includes('Email is already taken.')) return; + throw err; + }); const body = await login(); @@ -656,11 +659,11 @@ describe('Create Strapi API End to End', () => { }); const { body: referenceToGet } = await rq({ - url: `/references/${referenceToCreate.id}`, + url: `/references/${referenceToCreate.id || referenceToCreate._id}`, method: 'GET', }); - if (Object.keys(referenceToGet.tag).length == 0) return; + if (!referenceToGet.tag || Object.keys(referenceToGet.tag).length == 0) return; expect(referenceToGet.tag).toBe(null); }); }); diff --git a/packages/strapi-hook-bookshelf/lib/utils/connectivity.js b/packages/strapi-hook-bookshelf/lib/utils/connectivity.js index c9e51e40b31..09d68974cc1 100644 --- a/packages/strapi-hook-bookshelf/lib/utils/connectivity.js +++ b/packages/strapi-hook-bookshelf/lib/utils/connectivity.js @@ -76,16 +76,18 @@ module.exports = (scope, success, error) => { }); }) .catch((err) => { + if (scope.debug) { + console.log('🐛 Full error log:'); + console.log(err); + return error(); + } + if (err.sql) { console.log('⚠️ Server connection has failed! Make sure your database server is running.'); } else { console.log(`⚠️ Database connection has failed! Make sure your "${scope.database.settings.database}" database exist.`); } - - if (scope.debug) { - console.log('🐛 Full error log:'); - console.log(err); - } + console.log(err.message); error(); }); diff --git a/packages/strapi-plugin-content-manager/test/index.test.e2e.js b/packages/strapi-plugin-content-manager/test/index.test.e2e.js index 1e95772b919..b4ee01f5c28 100644 --- a/packages/strapi-plugin-content-manager/test/index.test.e2e.js +++ b/packages/strapi-plugin-content-manager/test/index.test.e2e.js @@ -22,7 +22,8 @@ describe('Content Manager End to End', () => { method: 'POST', body: auth, }).catch(err => { - console.log(err); + if (err.error.message.includes('Email is already taken.')) return; + throw err; }); const body = await login(); @@ -278,7 +279,7 @@ describe('Content Manager End to End', () => { }); test('Delete all articles should remove the association in each tags related to them', async () => { - const { body: tagToCreate } = await rq({ + const { body: createdTag } = await rq({ url: '/content-manager/explorer/tag/?source=content-manager', method: 'POST', formData: { @@ -292,17 +293,23 @@ describe('Content Manager End to End', () => { formData: { title: 'article12', content: 'Content', - tags: [tagToCreate], + tags: [createdTag], }, }); + const { body: updatedTag } = await rq({ + url: `/content-manager/explorer/tag/${createdTag.id}?source=content-manager`, + method: 'GET', + }); + + const { body: article13 } = await rq({ url: '/content-manager/explorer/article/?source=content-manager', method: 'POST', formData: { title: 'article13', content: 'Content', - tags: [tagToCreate], + tags: [updatedTag], }, }); @@ -314,7 +321,7 @@ describe('Content Manager End to End', () => { expect(articles[1].tags.length).toBe(1); let { body: tagToGet } = await rq({ - url: `/content-manager/explorer/tag/${tagToCreate.id}?source=content-manager`, + url: `/content-manager/explorer/tag/${createdTag.id}?source=content-manager`, method: 'GET', }); @@ -329,7 +336,7 @@ describe('Content Manager End to End', () => { }); let { body: tagToGet2 } = await rq({ - url: `/content-manager/explorer/tag/${tagToCreate.id}?source=content-manager`, + url: `/content-manager/explorer/tag/${createdTag.id}?source=content-manager`, method: 'GET', }); @@ -723,7 +730,7 @@ describe('Content Manager End to End', () => { method: 'GET', }); - if (Object.keys(referenceToGet.tag).length == 0) return; + if (!referenceToGet.tag || Object.keys(referenceToGet.tag).length == 0) return; expect(referenceToGet.tag).toBe(null); }); }); diff --git a/packages/strapi-plugin-settings-manager/package.json b/packages/strapi-plugin-settings-manager/package.json index 0ead21458df..59ccb49b451 100644 --- a/packages/strapi-plugin-settings-manager/package.json +++ b/packages/strapi-plugin-settings-manager/package.json @@ -53,4 +53,4 @@ "npm": ">= 6.0.0" }, "license": "MIT" -} \ No newline at end of file +} diff --git a/test/cypress.js b/test/cypress.js index ecb86614555..3beea9b84be 100644 --- a/test/cypress.js +++ b/test/cypress.js @@ -11,7 +11,7 @@ cypress .run(config) .then(results => { if (results.totalFailed > 0) { - process.stdout.write('Cypress tests finished with errors\n', () => { + return process.stdout.write('Cypress tests finished with errors\n', () => { process.exit(1); }); } diff --git a/test/e2e.js b/test/e2e.js index ccdbc4d275c..96637c6b319 100644 --- a/test/e2e.js +++ b/test/e2e.js @@ -6,7 +6,7 @@ const waitOn = require('wait-on'); const appName = 'testApp'; const databases = { - mongo: `--dbclient=mongo --dbhost=127.0.0.1 --dbport=27017 --dbname=strapi-test-${new Date().getTime()} --dbusername= --dbpassword=`, + mongo: `--dbclient=mongo --dbhost=127.0.0.1 --dbport=27017 --dbname=strapi_test --dbusername=root --dbpassword=strapi`, postgres: '--dbclient=postgres --dbhost=127.0.0.1 --dbport=5432 --dbname=strapi_test --dbusername=strapi --dbpassword=strapi', mysql: @@ -26,7 +26,7 @@ const test = async () => { }; const main = async () => { - const database = process.argv.length > 2 ? process.argv.slice(2).join(' ') : databases.mysql; + const database = process.argv.length > 2 ? process.argv.slice(2).join(' ') : databases.mongo; try { await cleanTestApp(appName);