Skip to content

Commit

Permalink
Setup travis jobs and stages
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrebodin committed Mar 12, 2019
1 parent 5c6618c commit 6b417aa
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 49 deletions.
82 changes: 56 additions & 26 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
services:
- mongodb
- postgresql
- mysql

sudo: required
dist: trusty
Expand All @@ -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
2 changes: 1 addition & 1 deletion cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"chromeWebSecurity": false,
"backendUrl": "http://localhost:1337",
"baseUrl": "http://localhost:1337",
"frontLoadingDelay": 3000,
"frontLoadingDelay": 5000,
"animDelay": 1000,
"serverRestartDelay": 11000,
"viewportHeight": 900,
Expand Down
2 changes: 1 addition & 1 deletion cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@
"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",
"test:snyk": "snyk test",
"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": "[email protected]",
Expand Down
9 changes: 6 additions & 3 deletions packages/strapi-generate-api/test/endpoint.test.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
});
});
Expand Down
12 changes: 7 additions & 5 deletions packages/strapi-hook-bookshelf/lib/utils/connectivity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
21 changes: 14 additions & 7 deletions packages/strapi-plugin-content-manager/test/index.test.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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: {
Expand All @@ -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],
},
});

Expand All @@ -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',
});

Expand All @@ -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',
});

Expand Down Expand Up @@ -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);
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/strapi-plugin-settings-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@
"npm": ">= 6.0.0"
},
"license": "MIT"
}
}
2 changes: 1 addition & 1 deletion test/cypress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down
4 changes: 2 additions & 2 deletions test/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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);
Expand Down

0 comments on commit 6b417aa

Please sign in to comment.