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..93f0a31008 100644 --- a/services/web/Jenkinsfile +++ b/services/web/Jenkinsfile @@ -113,6 +113,13 @@ pipeline { } } + stage('Acceptance Tests') { + steps { + sh 'docker pull sharelatex/acceptance-test-runner' + sh 'docker run --rm -v $(pwd):/app --env SHARELATEX_ALLOW_PUBLIC_ACCESS=true sharelatex/acceptance-test-runner' + } + } + 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..5caed105b9 --- /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 = MockDocStoreApi = + 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