From 1502da85cf0fd15daa1adbaa05bad35c1e479709 Mon Sep 17 00:00:00 2001 From: James Allen Date: Wed, 27 Sep 2017 10:37:20 +0200 Subject: [PATCH 1/3] Set up acceptance tests to run in docker container --- services/web/Gruntfile.coffee | 25 ++++++++++++++-- services/web/Jenkinsfile | 6 ++++ services/web/package.json | 4 ++- .../coffee/AuthorizationTests.coffee | 3 ++ .../coffee/helpers/MockDocUpdaterApi.coffee | 12 ++++++++ .../coffee/helpers/MockDocstoreApi.coffee | 29 +++++++++++++++++++ .../web/test/acceptance/scripts/full-test.sh | 26 +++++++++++++++++ 7 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 services/web/test/acceptance/coffee/helpers/MockDocUpdaterApi.coffee create mode 100644 services/web/test/acceptance/coffee/helpers/MockDocstoreApi.coffee create mode 100755 services/web/test/acceptance/scripts/full-test.sh diff --git a/services/web/Gruntfile.coffee b/services/web/Gruntfile.coffee index 0845b435c2..82ec9987e3 100644 --- a/services/web/Gruntfile.coffee +++ b/services/web/Gruntfile.coffee @@ -20,6 +20,8 @@ module.exports = (grunt) -> grunt.loadNpmTasks 'grunt-parallel' grunt.loadNpmTasks 'grunt-exec' grunt.loadNpmTasks 'grunt-postcss' + grunt.loadNpmTasks 'grunt-forever' + grunt.loadNpmTasks 'grunt-shell' # grunt.loadNpmTasks 'grunt-contrib-imagemin' # grunt.loadNpmTasks 'grunt-sprity' @@ -31,6 +33,10 @@ module.exports = (grunt) -> cssmin: command:"node_modules/clean-css/bin/cleancss --s0 -o public/stylesheets/style.css public/stylesheets/style.css" + forever: + app: + options: + index: "app.js" watch: coffee: @@ -244,8 +250,11 @@ module.exports = (grunt) -> pattern: "@@RELEASE@@" replacement: process.env.BUILD_NUMBER || "(unknown build)" - - + shell: + fullAcceptanceTests: + command: "bash ./test/acceptance/scripts/full-test.sh" + dockerTests: + command: 'docker run -v "$(pwd):/app" --env SHARELATEX_ALLOW_PUBLIC_ACCESS=true --rm sharelatex/acceptance-test-runner' availabletasks: tasks: @@ -396,6 +405,18 @@ module.exports = (grunt) -> grunt.registerTask 'test:acceptance', 'Run the acceptance tests (use --grep= or --feature= for individual tests)', ['compile:acceptance_tests', 'mochaTest:acceptance'] grunt.registerTask 'test:smoke', 'Run the smoke tests', ['compile:smoke_tests', 'mochaTest:smoke'] + grunt.registerTask( + 'test:acceptance:full', + "Start server and run acceptance tests", + ['shell:fullAcceptanceTests'] + ) + + grunt.registerTask( + 'test:acceptance:docker', + "Run acceptance tests inside docker container", + ['compile:acceptance_tests', 'shell:dockerTests'] + ) + grunt.registerTask 'test:modules:unit', 'Run the unit tests for the modules', ['compile:modules:server', 'compile:modules:unit_tests'].concat(moduleUnitTestTasks) grunt.registerTask 'run:watch', "Compile and run the web-sharelatex server", ['compile', 'env:run', 'parallel'] diff --git a/services/web/Jenkinsfile b/services/web/Jenkinsfile index c43f82ac4e..dbc86d99fd 100644 --- a/services/web/Jenkinsfile +++ b/services/web/Jenkinsfile @@ -113,6 +113,12 @@ pipeline { } } + stage('Acceptance Tests') { + steps { + sh './node_modules/.bin/grunt test:acceptance:docker' + } + } + stage('Package') { steps { sh 'rm -rf ./node_modules/grunt*' diff --git a/services/web/package.json b/services/web/package.json index 335e99b85d..25122f635d 100644 --- a/services/web/package.json +++ b/services/web/package.json @@ -75,9 +75,9 @@ "bunyan": "0.22.1", "chai": "3.5.0", "chai-spies": "", - "grunt": "0.4.5", "clean-css": "^3.4.18", "es6-promise": "^4.0.5", + "grunt": "0.4.5", "grunt-available-tasks": "0.4.1", "grunt-bunyan": "0.5.0", "grunt-contrib-clean": "0.5.0", @@ -89,12 +89,14 @@ "grunt-exec": "^0.4.7", "grunt-execute": "^0.2.2", "grunt-file-append": "0.0.6", + "grunt-forever": "^0.4.7", "grunt-git-rev-parse": "^0.1.4", "grunt-mocha-test": "0.9.0", "grunt-newer": "^1.2.0", "grunt-parallel": "^0.5.1", "grunt-postcss": "^0.8.0", "grunt-sed": "^0.1.1", + "grunt-shell": "^2.1.0", "sandboxed-module": "0.2.0", "sinon": "^1.17.0", "timekeeper": "", diff --git a/services/web/test/acceptance/coffee/AuthorizationTests.coffee b/services/web/test/acceptance/coffee/AuthorizationTests.coffee index 05c1615a3e..37cc48226f 100644 --- a/services/web/test/acceptance/coffee/AuthorizationTests.coffee +++ b/services/web/test/acceptance/coffee/AuthorizationTests.coffee @@ -4,6 +4,9 @@ User = require "./helpers/User" request = require "./helpers/request" settings = require "settings-sharelatex" +MockDocstoreApi = require './helpers/MockDocstoreApi' +MockDocUpdaterApi = require './helpers/MockDocUpdaterApi' + try_read_access = (user, project_id, test, callback) -> async.series [ (cb) -> diff --git a/services/web/test/acceptance/coffee/helpers/MockDocUpdaterApi.coffee b/services/web/test/acceptance/coffee/helpers/MockDocUpdaterApi.coffee new file mode 100644 index 0000000000..07ecc33b9a --- /dev/null +++ b/services/web/test/acceptance/coffee/helpers/MockDocUpdaterApi.coffee @@ -0,0 +1,12 @@ +express = require("express") +app = express() + +module.exports = MockDocUpdaterApi = + run: () -> + app.post "/project/:project_id/flush", (req, res, next) => + res.sendStatus 200 + + app.listen 3003, (error) -> + throw error if error? + +MockDocUpdaterApi.run() diff --git a/services/web/test/acceptance/coffee/helpers/MockDocstoreApi.coffee b/services/web/test/acceptance/coffee/helpers/MockDocstoreApi.coffee new file mode 100644 index 0000000000..e7b0e4142c --- /dev/null +++ b/services/web/test/acceptance/coffee/helpers/MockDocstoreApi.coffee @@ -0,0 +1,29 @@ +express = require("express") +bodyParser = require "body-parser" +app = express() + +module.exports = MockDocUpdaterApi = + docs: {} + + run: () -> + app.post "/project/:project_id/doc/:doc_id", bodyParser.json(), (req, res, next) => + {project_id, doc_id} = req.params + {lines, version, ranges} = req.body + @docs[project_id] ?= {} + @docs[project_id][doc_id] = {lines, version, ranges} + @docs[project_id][doc_id].rev ?= 0 + @docs[project_id][doc_id].rev += 1 + res.json { + modified: true + rev: @docs[project_id][doc_id].rev + } + + app.get "/project/:project_id/doc", (req, res, next) => + docs = (doc for doc_id, doc of @docs[req.params.project_id]) + res.send JSON.stringify docs + + app.listen 3016, (error) -> + throw error if error? + +MockDocUpdaterApi.run() + diff --git a/services/web/test/acceptance/scripts/full-test.sh b/services/web/test/acceptance/scripts/full-test.sh new file mode 100755 index 0000000000..c8ce75dd4b --- /dev/null +++ b/services/web/test/acceptance/scripts/full-test.sh @@ -0,0 +1,26 @@ +#! /usr/bin/env bash + +# If you're running on OS X, you probably need to manually +# 'rm -r node_modules/bcrypt; npm install bcrypt' inside +# the docker container, before it will start. +# npm rebuild bcrypt + +echo ">> Starting server..." + +grunt --no-color forever:app:start + +echo ">> Server started" + +sleep 5 + +echo ">> Running acceptance tests..." +grunt --no-color mochaTest:acceptance +_test_exit_code=$? + +echo ">> Killing server" + +grunt --no-color forever:app:stop + +echo ">> Done" + +exit $_test_exit_code \ No newline at end of file From ffc35d9d65b5efab278d9c55ee8183cb9e71ac87 Mon Sep 17 00:00:00 2001 From: James Allen Date: Wed, 27 Sep 2017 10:50:34 +0200 Subject: [PATCH 2/3] Include docker command directly because node isn't available in Jenkins --- services/web/Jenkinsfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/web/Jenkinsfile b/services/web/Jenkinsfile index dbc86d99fd..93f0a31008 100644 --- a/services/web/Jenkinsfile +++ b/services/web/Jenkinsfile @@ -115,7 +115,8 @@ pipeline { stage('Acceptance Tests') { steps { - sh './node_modules/.bin/grunt test:acceptance:docker' + sh 'docker pull sharelatex/acceptance-test-runner' + sh 'docker run --rm -v $(pwd):/app --env SHARELATEX_ALLOW_PUBLIC_ACCESS=true sharelatex/acceptance-test-runner' } } From 23bd8407961b0dd12262c273da9245e35e4e08bd Mon Sep 17 00:00:00 2001 From: James Allen Date: Wed, 27 Sep 2017 10:53:00 +0200 Subject: [PATCH 3/3] Fix MockDocStoreApi name --- .../web/test/acceptance/coffee/helpers/MockDocstoreApi.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/web/test/acceptance/coffee/helpers/MockDocstoreApi.coffee b/services/web/test/acceptance/coffee/helpers/MockDocstoreApi.coffee index e7b0e4142c..5caed105b9 100644 --- a/services/web/test/acceptance/coffee/helpers/MockDocstoreApi.coffee +++ b/services/web/test/acceptance/coffee/helpers/MockDocstoreApi.coffee @@ -2,7 +2,7 @@ express = require("express") bodyParser = require "body-parser" app = express() -module.exports = MockDocUpdaterApi = +module.exports = MockDocStoreApi = docs: {} run: () ->