Skip to content

Commit

Permalink
Merge pull request #660 from dadi/feature/visual-tests
Browse files Browse the repository at this point in the history
Add functional test suite
  • Loading branch information
eduardoboucas authored Jan 30, 2019
2 parents b6c06d4 + b22ee07 commit 433a0dd
Show file tree
Hide file tree
Showing 65 changed files with 5,429 additions and 35 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ stats.json
jest*
workspace/
.DS_Store

test/api/workspace/db
test/functional/output
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ language: node_js
cache:
directories:
- node_modules
after_failure:
- "./test/functional/scripts/upload-artifacts.sh /home/travis/build/dadi/publish/test/functional/output"
notifications:
email: false
slack:
on_failure: always
on_success: never
rooms:
secure: MCz3nE/G7lBVfd6GFCzC9rsbx5UwviAyq1S2cz485YOrn1l44GyHXhzpZywSYVtMNwUUBa5nIatZf/VETxLfbneQ3rm/DmaPxUhxNyDfICg8cytWNbF+yOXpcc+Y14HunUJ1K2DNRUech86Zqc/ndV0uuz+hmMZye3jAwMzFw58TPI0LjRB9uwyY1Yq2w3MIGm2Ns5neZM/PyEyJURMApSvOU7yeMcEIhXskezmuua4qKorFQsZx6+m9Ylgicf3k7X2VHcsArwLjGxDzx8AoGrQ1DTL4Mv+ogjn1+/oapZ6wtxH3TiiUGlkBZKa+owhnDNmLlY8hah6XH0S8K8oY0uNDQlQ19xsdBmYSqu9PBTye8cT7dTJABPtMOs/ByYyIVnI4q2V+B5a9kfT1FcRD7VnVnbdg0chxwiZG+DmjJ5U2efMqeDO9JT7G6834dqBiG7njurJAStEVfjvYLVxhWmuYWpAytEoadRn2S4Er8GboJoiA1LaDJCKXaTxtYeMYeGdL0rzWFyFBnXgX5IOR6rkeG4gT77xQPycz0clZEZOeQy7S3tB/RmkaIg3VkxSEET5xAKBhJYEdsK7SpTEEm60AE4CRWlmrmbkWOA8qTXGd5p3/DKJ+rKj0+V9cmEssnUC49/uLU6/SO/u1QHZcH2vduJTAHIEFFmgpljrIRlk=
secure: jnmTBfHGzU4rR9RAVsRmwMI3Rdul5PEKioh2oIsWv245DQrqr5DIwEONPRMsCbs1Duk69jiQFAzfLgzjtOjHleac79p0076pSxaG2zXNyzgya5YBMgYv6wrFh9eNZJoXyMvDw8jcipbRbx/Xp05aayClY39BJ7UUFlklvIeFb5wFqRfIlVXbLu5MFFatwCzB1IOeSeD90ZTX9VsWw97SJoJdta5gn7dx0P06SStPSJNOrLmV1/aXrSorBYmeTNJgUWPg4zHanocll8b7TR1a8Iyc5JBip0tEUpf1vJOMb/7bMdmNJ1XL8rzWw/87JujuzdOKikrsi52fzHE70TgsEBf0+BkwtFK2SzRvrwIKVesjj+ek/E2P1gal2qeqDVLVGZYuKAqbigv/0r6MHDcqJLoWb9MGHTLgcobZOfX3+UZetIc8dDA9/yme1auC8efrD4LOdo4Glhf6EZP4xCFUJpZive3VCKQfg/sMBaWAMWY508cxV+ey+fucV8fEqIsZHNPv7mCWoeMc5PnMd5TlR49UDgNrq0xcS8q2n9EKdZZARdsnqwdpmwJ3Ygd3gPsQTdYKsIBUxEoQKhMycO1XaqkbcUSHi8nSw85775cdEUscEob01WRN7D9IX7sGGp3LksFeR1CtjigBtMM9gHwmODUcPmcD+YRPYnnquoGzV9I=
node_js:
- '6'
- '8'
4 changes: 4 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@ App.prototype.start = function () {
return this.server.start()
}

App.prototype.stop = function () {
return this.server.stop()
}

module.exports = new App()
module.exports.app = App
18 changes: 18 additions & 0 deletions app/lib/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,24 @@ Server.prototype.start = function () {
return this.createPrimaryServer()
}

Server.prototype.stop = function () {
return new Promise((resolve, reject) => {
try {
this.primaryServer.close(() => {
if (this.redirectServer) {
this.redirectServer.close(() => {
resolve()
})
} else {
resolve()
}
})
} catch (error) {
console.log(error)
}
})
}

Server.prototype.restartServers = function () {
if (this.primaryServer) {
this.primaryServer.close(server => {
Expand Down
91 changes: 91 additions & 0 deletions codecept.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"output": "./test/functional/output",
"helpers": {
"Puppeteer": {
"url": "http://localhost:3003",
"show": false,
"restart": false,
"waitForAction": 1000,
"keepBrowserState": true,
"uniqueScreenshotNames": true,
"waitForTimeout": 11000,
"waitForNavigation": "domcontentloaded",
"windowSize": "1425x710",
"chrome": {
"args": [
"--no-sandbox"
]
}
},
"Assertions": {
"require": "./test/functional/helpers/assertions_helper.js"
},
"DataHelper": {
"require": "./test/functional/helpers/data_helper.js"
},
"Editor": {
"require": "./test/functional/helpers/editor_helper.js"
}
},
"include": {
"I": "./test/functional/stepDefinitions/steps_file.js",
"articlePage": "./test/functional/pages/Article.js",
"fieldPage": "./test/functional/pages/Field.js",
"homePage": "./test/functional/pages/Home.js",
"loginPage": "./test/functional/pages/Login.js",
"mediaPage": "./test/functional/pages/Media.js",
"profilePage": "./test/functional/pages/Profile.js"
},
"mocha": {
"reporterOptions": {
"codeceptjs-cli-reporter": {
"stdout": "-",
"options": {
"verbose": false,
"steps": true
}
},
"mochawesome": {
"stdout": "./test/functional/output/console.log",
"options": {
"reportDir": "./test/functional/output",
"reportFilename": "report"
}
}
}
},
"bootstrap": "./test/functional/setup.js",
"teardown": "./test/functional/setup.js",
"hooks": [],
"multiple": {
"basic": {
"browsers": [
"chrome",
"firefox"
]
},
"parallel": {
"chunks": 2,
"browsers": [
"chrome"
]
}
},
"plugins": {
"allure": {
"outputDir": "./test/functional/output/allure",
"enabled": false
},
"screenshotOnFail": {
"enabled": true
},
"customEvents": {
"require": "./test/functional/events/index",
"enabled": true
}
},
"tests": "./test/functional/features/*/*_test.js",
"_tests": "./test/functional/features/*/*_test.js",
"timeout": 10000,
"name": "publish-test"
}
58 changes: 37 additions & 21 deletions config/config.test.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,43 @@
{
"app": {
"name": "DADI Publish Test",
"publisher": "DADI"
},
"publicUrl": {
"host": "127.0.0.1",
"port": 443,
"protocol": "https"
"name": "DADI Publish",
"publisher": "Publisher Name"
},
"server": {
"host": "0.0.0.0",
"port": 3000
"port": 3003
},
"apis": [
{
"name": "Demo API",
"host": "http://0.0.0.0",
"port": 3001,
"database": "publish",
"version": "1.0"
}
],
"auth": {
"enabled": false
}
}
"apis": [{
"name": "Publish Test API",
"host": "http://localhost",
"port": 3004,
"menu": [{
"collections": [
"pages",
"team"
],
"title": "Content"
},
{
"collections": [
"categories",
"sub-categories",
"milestones"
],
"title": "Taxonomy"
},
{
"collections": [
"field-test-boolean",
"field-test-date",
"field-test-media",
"field-test-other",
"field-test-number",
"field-test-reference",
"field-test-string"
],
"title": "Field Testing"
}
]
}]
}
12 changes: 10 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,24 @@ Publish.prototype.getStartupMessage = function () {
}

Publish.prototype.run = function () {
dadiBoot.start(require('./package.json'))
if (config.get('env') !== 'test') {
dadiBoot.start(require('./package.json'))
}

app
return app
.start()
.then(this.getStartupMessage)
.catch(err => {
console.log('App failed to start', err)
})
}

Publish.prototype.stop = function () {
return app.stop().catch(err => {
console.log('App failed to stop', err)
})
}

// Run-type switch
if (require.main === module) {
// App called directly
Expand Down
24 changes: 17 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
"precommit": "npm run lint && node scripts/precommit.js",
"snyk-protect": "snyk protect",
"start": "NODE_ENV=development node index.js",
"test": "npm-run-all test-all lint",
"test-watch": "jest --watch",
"test-all": "jest --coverage && node scripts/coverage/coverage.js",
"test": "npm run build && npm run test:unit && npm run test:functional && npm run lint",
"test:functional:pre": "rm -rf test/functional/output && mkdir -p test/api/test/api/workspace && cp -R test/api/workspace/hooks test/api/test/api/workspace && cp test/api/workspace/db.template test/api/workspace/db",
"test:functional:run": "API_CLIENT_ID=testClient API_CLIENT_SECRET=testSecret API_HOST=localhost API_PORT=3004 NODE_ENV=test ./node_modules/codeceptjs/bin/codecept.js run --steps",
"test:functional:post": "",
"test:functional": "npm run test:functional:pre && npm run test:functional:run && npm run test:functional:post",
"test:unit": "jest --coverage && node scripts/coverage/coverage.js",
"watch": "NODE_ENV=development npm-run-all --parallel watch:server watch:build",
"watch:build": "webpack --watch",
"watch:server": "nodemon \"./index.js\" --watch \"./app\"",
Expand Down Expand Up @@ -59,6 +62,8 @@
"ws": "^6.1.2"
},
"devDependencies": {
"@dadi/api": "^4.4.4",
"@dadi/api-filestore": "^0.11.1",
"@dadi/api-validator": "^1.2.0",
"@dadi/api-wrapper-core": "^3.1.0",
"@dadi/preact-router": "^2.6.3",
Expand All @@ -79,6 +84,7 @@
"babel-preset-stage-2": "^6.18.0",
"babili-webpack-plugin": "^0.1.1",
"chai": "^3.5.0",
"codeceptjs": "^2.0.2",
"colors": "^1.3.1",
"component-tree-webpack-plugin": "^1.0.0",
"coveralls": "^3.0.2",
Expand All @@ -88,16 +94,20 @@
"fecha": "^2.3.0",
"file-loader": "^0.9.0",
"file-size": "^1.0.0",
"form-data": "^2.3.3",
"fs": "0.0.1-security",
"history": "^4.5.1",
"html-looks-like": "^1.0.3",
"husky": "^0.13.3",
"inquirer": "^3.0.6",
"jest": "^20.0.4",
"js-cookie": "^2.2.0",
"js-promise-queue": "^1.1.0",
"marked": "^0.5.1",
"mkdirp": "^0.5.1",
"mocha": "^5.2.0",
"mochawesome": "^3.0.3",
"moment": "^2.23.0",
"nock": "^9.6.1",
"node-mocks-http": "^1.6.3",
"nodemon": "^1.18.9",
Expand All @@ -119,12 +129,14 @@
"preact-render-to-string": "^3.8.2",
"preact-router-redux": "^4.1.0",
"proptypes": "^0.14.3",
"puppeteer": "^1.9.0",
"react-docgen": "^2.21.0",
"react-test-renderer": "^15.5.4",
"redux": "^3.6.0",
"redux-thunk": "^2.2.0",
"request-promise": "^4.1.1",
"rollup": "^0.47.4",
"slugify": "^1.3.4",
"snyk": "^1.92.6",
"standard": "^8.6.0",
"style-loader": "^0.13.1",
Expand Down Expand Up @@ -156,9 +168,7 @@
"collectCoverage": true,
"automock": false,
"collectCoverageFrom": [
"**/frontend/**/*.{js}",
"**/app/**/*.{js}",
"!**/frontend/**/Mock*.{js,jsx}"
"**/app/**/*.{js}"
],
"coverageReporters": [
"cobertura",
Expand Down Expand Up @@ -192,7 +202,7 @@
"./test/jestSetup.js"
],
"testMatch": [
"**/test/**/*.test.js"
"**/test/unit/**/*.test.js"
],
"testURL": "http://localhost"
},
Expand Down
1 change: 1 addition & 0 deletions test/api/cache/api/db.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"filename":"cache/api/db.json","collections":[{"name":"cache","data":[],"idIndex":[],"binaryIndices":{},"constraints":null,"uniqueNames":[],"transforms":{},"objType":"cache","dirty":false,"cachedIndex":null,"cachedBinaryIndex":null,"cachedData":null,"adaptiveBinaryIndices":true,"transactional":false,"cloneObjects":false,"cloneMethod":"parse-stringify","asyncListeners":false,"disableMeta":false,"disableChangesApi":true,"disableDeltaChangesApi":true,"autoupdate":false,"serializableIndices":true,"ttl":null,"maxId":0,"DynamicViews":[],"events":{"insert":[],"update":[],"pre-insert":[],"pre-update":[],"close":[],"flushbuffer":[],"error":[],"delete":[null],"warning":[null]},"changes":[]}],"databaseVersion":1.5,"engineVersion":1.5,"autosave":true,"autosaveInterval":1000,"autosaveHandle":null,"throttledSaves":true,"options":{"autoload":true,"autosave":true,"autosaveInterval":1000,"serializationMethod":"normal","destructureDelimiter":"$<\n","recursiveWait":true,"recursiveWaitLimit":false,"recursiveWaitLimitDuration":2000,"started":1547565359365},"persistenceMethod":"fs","persistenceAdapter":null,"verbose":false,"events":{"init":[null],"loaded":[],"flushChanges":[],"close":[],"changes":[],"warning":[]},"ENV":"NODEJS"}
55 changes: 55 additions & 0 deletions test/api/config/config.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"cluster": false,
"app": {
"name": "Publish Test API"
},
"publicUrl": {
"host": "localhost",
"port": 3004,
"protocol": "http"
},
"server": {
"host": "0.0.0.0",
"port": 3004
},
"datastore": "@dadi/api-filestore",
"auth": {
"tokenUrl": "/token",
"tokenTtl": 1800000,
"clientCollection": "client-store",
"tokenCollection": "token-store",
"datastore": "@dadi/api-filestore",
"database": "dadicloud"
},
"caching": {
"ttl": 1200,
"directory": {
"enabled": false,
"path": "./cache/api",
"extension": "json",
"autoFlush": true,
"autoFlushInterval": 60
},
"redis": {
"enabled": false,
"host": "127.0.0.1",
"port": 6379
}
},
"paths": {
"collections": "workspace/collections",
"endpoints": "workspace/endpoints",
"hooks": "test/api/workspace/hooks"
},
"logging": {
"enabled": true,
"level": "debug",
"path": "./log",
"filename": "api",
"extension": "log"
},
"feedback": false,
"query": {
"useVersionFilter": true
}
}
Loading

0 comments on commit 433a0dd

Please sign in to comment.