Revert "Upgrade to mocha 5.0.1"

This commit is contained in:
Alasdair Smith 2018-02-27 12:25:42 +00:00 committed by GitHub
parent 4524b3c9f6
commit 315587605c
20 changed files with 117 additions and 233 deletions

View file

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/bash
set -e; set -e;
MOCHA="node_modules/.bin/mocha --exit --recursive --reporter spec --timeout 15000" MOCHA="node_modules/.bin/mocha --recursive --reporter spec --timeout 15000"
$MOCHA "$@" $MOCHA "$@"

View file

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
set -e; set -e;
MOCHA="node_modules/.bin/mocha --exit --recursive --reporter spec" MOCHA="node_modules/.bin/mocha --recursive --reporter spec"
$MOCHA "$@" test/unit/js $MOCHA "$@" test/unit/js

View file

@ -1160,11 +1160,6 @@
} }
} }
}, },
"browser-stdout": {
"version": "1.3.0",
"from": "browser-stdout@1.3.0",
"resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.0.tgz"
},
"browserify": { "browserify": {
"version": "14.5.0", "version": "14.5.0",
"from": "browserify@>=14.5.0 <15.0.0", "from": "browserify@>=14.5.0 <15.0.0",
@ -5086,59 +5081,7 @@
"version": "0.9.0", "version": "0.9.0",
"from": "grunt-mocha-test@0.9.0", "from": "grunt-mocha-test@0.9.0",
"resolved": "https://registry.npmjs.org/grunt-mocha-test/-/grunt-mocha-test-0.9.0.tgz", "resolved": "https://registry.npmjs.org/grunt-mocha-test/-/grunt-mocha-test-0.9.0.tgz",
"dev": true, "dev": true
"dependencies": {
"commander": {
"version": "2.0.0",
"from": "commander@2.0.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.0.0.tgz",
"dev": true
},
"glob": {
"version": "3.2.3",
"from": "glob@3.2.3",
"resolved": "https://registry.npmjs.org/glob/-/glob-3.2.3.tgz",
"dev": true
},
"graceful-fs": {
"version": "2.0.3",
"from": "graceful-fs@>=2.0.0 <2.1.0",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-2.0.3.tgz",
"dev": true
},
"jade": {
"version": "0.26.3",
"from": "jade@0.26.3",
"resolved": "https://registry.npmjs.org/jade/-/jade-0.26.3.tgz",
"dev": true,
"dependencies": {
"commander": {
"version": "0.6.1",
"from": "commander@0.6.1",
"resolved": "https://registry.npmjs.org/commander/-/commander-0.6.1.tgz",
"dev": true
},
"mkdirp": {
"version": "0.3.0",
"from": "mkdirp@0.3.0",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.0.tgz",
"dev": true
}
}
},
"mkdirp": {
"version": "0.3.5",
"from": "mkdirp@0.3.5",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.5.tgz",
"dev": true
},
"mocha": {
"version": "1.17.1",
"from": "mocha@>=1.17.1 <1.18.0",
"resolved": "https://registry.npmjs.org/mocha/-/mocha-1.17.1.tgz",
"dev": true
}
}
}, },
"grunt-newer": { "grunt-newer": {
"version": "1.3.0", "version": "1.3.0",
@ -5318,11 +5261,6 @@
"from": "hawk@>=6.0.2 <6.1.0", "from": "hawk@>=6.0.2 <6.1.0",
"resolved": "https://registry.npmjs.org/hawk/-/hawk-6.0.2.tgz" "resolved": "https://registry.npmjs.org/hawk/-/hawk-6.0.2.tgz"
}, },
"he": {
"version": "1.1.1",
"from": "he@1.1.1",
"resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz"
},
"heapdump": { "heapdump": {
"version": "0.3.9", "version": "0.3.9",
"from": "heapdump@>=0.3.7 <0.4.0", "from": "heapdump@>=0.3.7 <0.4.0",
@ -8060,49 +7998,46 @@
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz" "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz"
}, },
"mocha": { "mocha": {
"version": "5.0.1", "version": "1.17.1",
"from": "mocha@5.0.1", "from": "https://registry.npmjs.org/mocha/-/mocha-1.17.1.tgz",
"resolved": "https://registry.npmjs.org/mocha/-/mocha-5.0.1.tgz", "resolved": "https://registry.npmjs.org/mocha/-/mocha-1.17.1.tgz",
"dependencies": { "dependencies": {
"commander": { "commander": {
"version": "2.11.0", "version": "2.0.0",
"from": "commander@2.11.0", "from": "commander@2.0.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.11.0.tgz" "resolved": "https://registry.npmjs.org/commander/-/commander-2.0.0.tgz"
},
"debug": {
"version": "3.1.0",
"from": "debug@3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz"
},
"diff": {
"version": "3.3.1",
"from": "diff@3.3.1",
"resolved": "https://registry.npmjs.org/diff/-/diff-3.3.1.tgz"
}, },
"glob": { "glob": {
"version": "7.1.2", "version": "3.2.3",
"from": "glob@7.1.2", "from": "glob@3.2.3",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz" "resolved": "https://registry.npmjs.org/glob/-/glob-3.2.3.tgz"
}, },
"growl": { "graceful-fs": {
"version": "1.10.3", "version": "2.0.3",
"from": "growl@1.10.3", "from": "graceful-fs@>=2.0.0 <2.1.0",
"resolved": "https://registry.npmjs.org/growl/-/growl-1.10.3.tgz" "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-2.0.3.tgz"
}, },
"has-flag": { "jade": {
"version": "2.0.0", "version": "0.26.3",
"from": "has-flag@>=2.0.0 <3.0.0", "from": "jade@0.26.3",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-2.0.0.tgz" "resolved": "https://registry.npmjs.org/jade/-/jade-0.26.3.tgz",
"dependencies": {
"commander": {
"version": "0.6.1",
"from": "commander@0.6.1",
"resolved": "https://registry.npmjs.org/commander/-/commander-0.6.1.tgz"
},
"mkdirp": {
"version": "0.3.0",
"from": "mkdirp@0.3.0",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.0.tgz"
}
}
}, },
"minimatch": { "mkdirp": {
"version": "3.0.4", "version": "0.3.5",
"from": "minimatch@>=3.0.4 <4.0.0", "from": "mkdirp@0.3.5",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz" "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.5.tgz"
},
"supports-color": {
"version": "4.4.0",
"from": "supports-color@4.4.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.4.0.tgz"
} }
} }
}, },

View file

@ -54,7 +54,7 @@
"method-override": "^2.3.3", "method-override": "^2.3.3",
"metrics-sharelatex": "git+https://github.com/sharelatex/metrics-sharelatex.git#v1.7.1", "metrics-sharelatex": "git+https://github.com/sharelatex/metrics-sharelatex.git#v1.7.1",
"mimelib": "0.2.14", "mimelib": "0.2.14",
"mocha": "^5.0.1", "mocha": "1.17.1",
"mongojs": "2.4.0", "mongojs": "2.4.0",
"mongoose": "4.11.4", "mongoose": "4.11.4",
"multer": "^0.1.8", "multer": "^0.1.8",

View file

@ -34,7 +34,6 @@ describe "ProjectStructureMongoLock", ->
namespace = ProjectEntityMongoUpdateHandler.LOCK_NAMESPACE namespace = ProjectEntityMongoUpdateHandler.LOCK_NAMESPACE
@lock_key = "lock:web:#{namespace}:#{project._id}" @lock_key = "lock:web:#{namespace}:#{project._id}"
LockManager._getLock @lock_key, namespace, done LockManager._getLock @lock_key, namespace, done
return
after (done) -> after (done) ->
LockManager._releaseLock @lock_key, done LockManager._releaseLock @lock_key, done

View file

@ -16,12 +16,6 @@ request = require "./helpers/request"
User = require "./helpers/User" User = require "./helpers/User"
describe "ProjectStructureChanges", -> describe "ProjectStructureChanges", ->
example_project_id = null
example_doc_id = null
example_file_id = null
example_folder_id_1 = null
example_folder_id_2 = null
before (done) -> before (done) ->
@owner = new User() @owner = new User()
@owner.login done @owner.login done
@ -31,11 +25,11 @@ describe "ProjectStructureChanges", ->
MockDocUpdaterApi.clearProjectStructureUpdates() MockDocUpdaterApi.clearProjectStructureUpdates()
@owner.createProject "example-project", {template: "example"}, (error, project_id) => @owner.createProject "example-project", {template: "example"}, (error, project_id) =>
throw error if error? throw error if error?
example_project_id = project_id @example_project_id = project_id
done() done()
it "should version creating a doc", -> it "should version creating a doc", ->
updates = MockDocUpdaterApi.getProjectStructureUpdates(example_project_id).docUpdates updates = MockDocUpdaterApi.getProjectStructureUpdates(@example_project_id).docUpdates
expect(updates.length).to.equal(2) expect(updates.length).to.equal(2)
_.each updates, (update) => _.each updates, (update) =>
expect(update.userId).to.equal(@owner._id) expect(update.userId).to.equal(@owner._id)
@ -44,7 +38,7 @@ describe "ProjectStructureChanges", ->
expect(_.where(updates, pathname: "/references.bib").length).to.equal 1 expect(_.where(updates, pathname: "/references.bib").length).to.equal 1
it "should version creating a file", -> it "should version creating a file", ->
updates = MockDocUpdaterApi.getProjectStructureUpdates(example_project_id).fileUpdates updates = MockDocUpdaterApi.getProjectStructureUpdates(@example_project_id).fileUpdates
expect(updates.length).to.equal(1) expect(updates.length).to.equal(1)
update = updates[0] update = updates[0]
expect(update.userId).to.equal(@owner._id) expect(update.userId).to.equal(@owner._id)
@ -54,9 +48,8 @@ describe "ProjectStructureChanges", ->
describe "duplicating a project", -> describe "duplicating a project", ->
before (done) -> before (done) ->
MockDocUpdaterApi.clearProjectStructureUpdates() MockDocUpdaterApi.clearProjectStructureUpdates()
console.log(example_project_id)
@owner.request.post { @owner.request.post {
uri: "/Project/#{example_project_id}/clone", uri: "/Project/#{@example_project_id}/clone",
json: json:
projectName: 'new.tex' projectName: 'new.tex'
}, (error, res, body) => }, (error, res, body) =>
@ -87,10 +80,10 @@ describe "ProjectStructureChanges", ->
before (done) -> before (done) ->
MockDocUpdaterApi.clearProjectStructureUpdates() MockDocUpdaterApi.clearProjectStructureUpdates()
ProjectGetter.getProject example_project_id, (error, project) => ProjectGetter.getProject @example_project_id, (error, project) =>
throw error if error? throw error if error?
@owner.request.post { @owner.request.post {
uri: "project/#{example_project_id}/doc", uri: "project/#{@example_project_id}/doc",
json: json:
name: 'new.tex' name: 'new.tex'
parent_folder_id: project.rootFolder[0]._id parent_folder_id: project.rootFolder[0]._id
@ -98,11 +91,11 @@ describe "ProjectStructureChanges", ->
throw error if error? throw error if error?
if res.statusCode < 200 || res.statusCode >= 300 if res.statusCode < 200 || res.statusCode >= 300
throw new Error("failed to add doc #{res.statusCode}") throw new Error("failed to add doc #{res.statusCode}")
example_doc_id = body._id @example_doc_id = body._id
done() done()
it "should version the doc added", -> it "should version the doc added", ->
updates = MockDocUpdaterApi.getProjectStructureUpdates(example_project_id).docUpdates updates = MockDocUpdaterApi.getProjectStructureUpdates(@example_project_id).docUpdates
expect(updates.length).to.equal(1) expect(updates.length).to.equal(1)
update = updates[0] update = updates[0]
expect(update.userId).to.equal(@owner._id) expect(update.userId).to.equal(@owner._id)
@ -144,7 +137,7 @@ describe "ProjectStructureChanges", ->
describe "uploading a file", -> describe "uploading a file", ->
before (done) -> before (done) ->
ProjectGetter.getProject example_project_id, (error, project) => ProjectGetter.getProject @example_project_id, (error, project) =>
throw error if error? throw error if error?
@root_folder_id = project.rootFolder[0]._id.toString() @root_folder_id = project.rootFolder[0]._id.toString()
done() done()
@ -156,7 +149,7 @@ describe "ProjectStructureChanges", ->
image_file = fs.createReadStream(Path.resolve(__dirname + '/../files/1pixel.png')) image_file = fs.createReadStream(Path.resolve(__dirname + '/../files/1pixel.png'))
req = @owner.request.post { req = @owner.request.post {
uri: "project/#{example_project_id}/upload", uri: "project/#{@example_project_id}/upload",
qs: qs:
folder_id: @root_folder_id folder_id: @root_folder_id
formData: formData:
@ -170,9 +163,9 @@ describe "ProjectStructureChanges", ->
if res.statusCode < 200 || res.statusCode >= 300 if res.statusCode < 200 || res.statusCode >= 300
throw new Error("failed to upload file #{res.statusCode}") throw new Error("failed to upload file #{res.statusCode}")
example_file_id = JSON.parse(body).entity_id @example_file_id = JSON.parse(body).entity_id
updates = MockDocUpdaterApi.getProjectStructureUpdates(example_project_id).fileUpdates updates = MockDocUpdaterApi.getProjectStructureUpdates(@example_project_id).fileUpdates
expect(updates.length).to.equal(1) expect(updates.length).to.equal(1)
update = updates[0] update = updates[0]
expect(update.userId).to.equal(@owner._id) expect(update.userId).to.equal(@owner._id)
@ -186,7 +179,7 @@ describe "ProjectStructureChanges", ->
image_file = fs.createReadStream(Path.resolve(__dirname + '/../files/2pixel.png')) image_file = fs.createReadStream(Path.resolve(__dirname + '/../files/2pixel.png'))
req = @owner.request.post { req = @owner.request.post {
uri: "project/#{example_project_id}/upload", uri: "project/#{@example_project_id}/upload",
qs: qs:
folder_id: @root_folder_id folder_id: @root_folder_id
formData: formData:
@ -200,7 +193,7 @@ describe "ProjectStructureChanges", ->
if res.statusCode < 200 || res.statusCode >= 300 if res.statusCode < 200 || res.statusCode >= 300
throw new Error("failed to upload file #{res.statusCode}") throw new Error("failed to upload file #{res.statusCode}")
updates = MockDocUpdaterApi.getProjectStructureUpdates(example_project_id).fileUpdates updates = MockDocUpdaterApi.getProjectStructureUpdates(@example_project_id).fileUpdates
expect(updates.length).to.equal(1) expect(updates.length).to.equal(1)
update = updates[0] update = updates[0]
expect(update.userId).to.equal(@owner._id) expect(update.userId).to.equal(@owner._id)
@ -212,12 +205,12 @@ describe "ProjectStructureChanges", ->
describe "moving entities", -> describe "moving entities", ->
before (done) -> before (done) ->
@owner.request.post { @owner.request.post {
uri: "project/#{example_project_id}/folder", uri: "project/#{@example_project_id}/folder",
formData: formData:
name: 'foo' name: 'foo'
}, (error, res, body) => }, (error, res, body) =>
throw error if error? throw error if error?
example_folder_id_1 = JSON.parse(body)._id @example_folder_id_1 = JSON.parse(body)._id
done() done()
beforeEach () -> beforeEach () ->
@ -225,15 +218,15 @@ describe "ProjectStructureChanges", ->
it "should version moving a doc", (done) -> it "should version moving a doc", (done) ->
@owner.request.post { @owner.request.post {
uri: "project/#{example_project_id}/Doc/#{example_doc_id}/move", uri: "project/#{@example_project_id}/Doc/#{@example_doc_id}/move",
json: json:
folder_id: example_folder_id_1 folder_id: @example_folder_id_1
}, (error, res, body) => }, (error, res, body) =>
throw error if error? throw error if error?
if res.statusCode < 200 || res.statusCode >= 300 if res.statusCode < 200 || res.statusCode >= 300
throw new Error("failed to move doc #{res.statusCode}") throw new Error("failed to move doc #{res.statusCode}")
updates = MockDocUpdaterApi.getProjectStructureUpdates(example_project_id).docUpdates updates = MockDocUpdaterApi.getProjectStructureUpdates(@example_project_id).docUpdates
expect(updates.length).to.equal(1) expect(updates.length).to.equal(1)
update = updates[0] update = updates[0]
expect(update.userId).to.equal(@owner._id) expect(update.userId).to.equal(@owner._id)
@ -244,15 +237,15 @@ describe "ProjectStructureChanges", ->
it "should version moving a file", (done) -> it "should version moving a file", (done) ->
@owner.request.post { @owner.request.post {
uri: "project/#{example_project_id}/File/#{example_file_id}/move", uri: "project/#{@example_project_id}/File/#{@example_file_id}/move",
json: json:
folder_id: example_folder_id_1 folder_id: @example_folder_id_1
}, (error, res, body) => }, (error, res, body) =>
throw error if error? throw error if error?
if res.statusCode < 200 || res.statusCode >= 300 if res.statusCode < 200 || res.statusCode >= 300
throw new Error("failed to move file #{res.statusCode}") throw new Error("failed to move file #{res.statusCode}")
updates = MockDocUpdaterApi.getProjectStructureUpdates(example_project_id).fileUpdates updates = MockDocUpdaterApi.getProjectStructureUpdates(@example_project_id).fileUpdates
expect(updates.length).to.equal(1) expect(updates.length).to.equal(1)
update = updates[0] update = updates[0]
expect(update.userId).to.equal(@owner._id) expect(update.userId).to.equal(@owner._id)
@ -263,30 +256,30 @@ describe "ProjectStructureChanges", ->
it "should version moving a folder", (done) -> it "should version moving a folder", (done) ->
@owner.request.post { @owner.request.post {
uri: "project/#{example_project_id}/folder", uri: "project/#{@example_project_id}/folder",
formData: formData:
name: 'bar' name: 'bar'
}, (error, res, body) => }, (error, res, body) =>
throw error if error? throw error if error?
example_folder_id_2 = JSON.parse(body)._id @example_folder_id_2 = JSON.parse(body)._id
@owner.request.post { @owner.request.post {
uri: "project/#{example_project_id}/Folder/#{example_folder_id_1}/move", uri: "project/#{@example_project_id}/Folder/#{@example_folder_id_1}/move",
json: json:
folder_id: example_folder_id_2 folder_id: @example_folder_id_2
}, (error, res, body) => }, (error, res, body) =>
throw error if error? throw error if error?
if res.statusCode < 200 || res.statusCode >= 300 if res.statusCode < 200 || res.statusCode >= 300
throw new Error("failed to move folder #{res.statusCode}") throw new Error("failed to move folder #{res.statusCode}")
updates = MockDocUpdaterApi.getProjectStructureUpdates(example_project_id).docUpdates updates = MockDocUpdaterApi.getProjectStructureUpdates(@example_project_id).docUpdates
expect(updates.length).to.equal(1) expect(updates.length).to.equal(1)
update = updates[0] update = updates[0]
expect(update.userId).to.equal(@owner._id) expect(update.userId).to.equal(@owner._id)
expect(update.pathname).to.equal("/foo/new.tex") expect(update.pathname).to.equal("/foo/new.tex")
expect(update.newPathname).to.equal("/bar/foo/new.tex") expect(update.newPathname).to.equal("/bar/foo/new.tex")
updates = MockDocUpdaterApi.getProjectStructureUpdates(example_project_id).fileUpdates updates = MockDocUpdaterApi.getProjectStructureUpdates(@example_project_id).fileUpdates
expect(updates.length).to.equal(1) expect(updates.length).to.equal(1)
update = updates[0] update = updates[0]
expect(update.userId).to.equal(@owner._id) expect(update.userId).to.equal(@owner._id)
@ -301,7 +294,7 @@ describe "ProjectStructureChanges", ->
it "should version renaming a doc", (done) -> it "should version renaming a doc", (done) ->
@owner.request.post { @owner.request.post {
uri: "project/#{example_project_id}/Doc/#{example_doc_id}/rename", uri: "project/#{@example_project_id}/Doc/#{@example_doc_id}/rename",
json: json:
name: 'new_renamed.tex' name: 'new_renamed.tex'
}, (error, res, body) => }, (error, res, body) =>
@ -309,7 +302,7 @@ describe "ProjectStructureChanges", ->
if res.statusCode < 200 || res.statusCode >= 300 if res.statusCode < 200 || res.statusCode >= 300
throw new Error("failed to move doc #{res.statusCode}") throw new Error("failed to move doc #{res.statusCode}")
updates = MockDocUpdaterApi.getProjectStructureUpdates(example_project_id).docUpdates updates = MockDocUpdaterApi.getProjectStructureUpdates(@example_project_id).docUpdates
expect(updates.length).to.equal(1) expect(updates.length).to.equal(1)
update = updates[0] update = updates[0]
expect(update.userId).to.equal(@owner._id) expect(update.userId).to.equal(@owner._id)
@ -320,7 +313,7 @@ describe "ProjectStructureChanges", ->
it "should version renaming a file", (done) -> it "should version renaming a file", (done) ->
@owner.request.post { @owner.request.post {
uri: "project/#{example_project_id}/File/#{example_file_id}/rename", uri: "project/#{@example_project_id}/File/#{@example_file_id}/rename",
json: json:
name: '1pixel_renamed.png' name: '1pixel_renamed.png'
}, (error, res, body) => }, (error, res, body) =>
@ -328,7 +321,7 @@ describe "ProjectStructureChanges", ->
if res.statusCode < 200 || res.statusCode >= 300 if res.statusCode < 200 || res.statusCode >= 300
throw new Error("failed to move file #{res.statusCode}") throw new Error("failed to move file #{res.statusCode}")
updates = MockDocUpdaterApi.getProjectStructureUpdates(example_project_id).fileUpdates updates = MockDocUpdaterApi.getProjectStructureUpdates(@example_project_id).fileUpdates
expect(updates.length).to.equal(1) expect(updates.length).to.equal(1)
update = updates[0] update = updates[0]
expect(update.userId).to.equal(@owner._id) expect(update.userId).to.equal(@owner._id)
@ -339,7 +332,7 @@ describe "ProjectStructureChanges", ->
it "should version renaming a folder", (done) -> it "should version renaming a folder", (done) ->
@owner.request.post { @owner.request.post {
uri: "project/#{example_project_id}/Folder/#{example_folder_id_1}/rename", uri: "project/#{@example_project_id}/Folder/#{@example_folder_id_1}/rename",
json: json:
name: 'foo_renamed' name: 'foo_renamed'
}, (error, res, body) => }, (error, res, body) =>
@ -347,14 +340,14 @@ describe "ProjectStructureChanges", ->
if res.statusCode < 200 || res.statusCode >= 300 if res.statusCode < 200 || res.statusCode >= 300
throw new Error("failed to move folder #{res.statusCode}") throw new Error("failed to move folder #{res.statusCode}")
updates = MockDocUpdaterApi.getProjectStructureUpdates(example_project_id).docUpdates updates = MockDocUpdaterApi.getProjectStructureUpdates(@example_project_id).docUpdates
expect(updates.length).to.equal(1) expect(updates.length).to.equal(1)
update = updates[0] update = updates[0]
expect(update.userId).to.equal(@owner._id) expect(update.userId).to.equal(@owner._id)
expect(update.pathname).to.equal("/bar/foo/new_renamed.tex") expect(update.pathname).to.equal("/bar/foo/new_renamed.tex")
expect(update.newPathname).to.equal("/bar/foo_renamed/new_renamed.tex") expect(update.newPathname).to.equal("/bar/foo_renamed/new_renamed.tex")
updates = MockDocUpdaterApi.getProjectStructureUpdates(example_project_id).fileUpdates updates = MockDocUpdaterApi.getProjectStructureUpdates(@example_project_id).fileUpdates
expect(updates.length).to.equal(1) expect(updates.length).to.equal(1)
update = updates[0] update = updates[0]
expect(update.userId).to.equal(@owner._id) expect(update.userId).to.equal(@owner._id)
@ -369,20 +362,20 @@ describe "ProjectStructureChanges", ->
it "should version deleting a folder", (done) -> it "should version deleting a folder", (done) ->
@owner.request.delete { @owner.request.delete {
uri: "project/#{example_project_id}/Folder/#{example_folder_id_2}", uri: "project/#{@example_project_id}/Folder/#{@example_folder_id_2}",
}, (error, res, body) => }, (error, res, body) =>
throw error if error? throw error if error?
if res.statusCode < 200 || res.statusCode >= 300 if res.statusCode < 200 || res.statusCode >= 300
throw new Error("failed to delete folder #{res.statusCode}") throw new Error("failed to delete folder #{res.statusCode}")
updates = MockDocUpdaterApi.getProjectStructureUpdates(example_project_id).docUpdates updates = MockDocUpdaterApi.getProjectStructureUpdates(@example_project_id).docUpdates
expect(updates.length).to.equal(1) expect(updates.length).to.equal(1)
update = updates[0] update = updates[0]
expect(update.userId).to.equal(@owner._id) expect(update.userId).to.equal(@owner._id)
expect(update.pathname).to.equal("/bar/foo_renamed/new_renamed.tex") expect(update.pathname).to.equal("/bar/foo_renamed/new_renamed.tex")
expect(update.newPathname).to.equal("") expect(update.newPathname).to.equal("")
updates = MockDocUpdaterApi.getProjectStructureUpdates(example_project_id).fileUpdates updates = MockDocUpdaterApi.getProjectStructureUpdates(@example_project_id).fileUpdates
expect(updates.length).to.equal(1) expect(updates.length).to.equal(1)
update = updates[0] update = updates[0]
expect(update.userId).to.equal(@owner._id) expect(update.userId).to.equal(@owner._id)

View file

@ -99,7 +99,6 @@ describe "AuthenticationController", ->
@req.session.save = sinon.stub().callsArgWith(0, null) @req.session.save = sinon.stub().callsArgWith(0, null)
@req.sessionStore = {generate: sinon.stub()} @req.sessionStore = {generate: sinon.stub()}
@passport.authenticate.callsArgWith(1, null, @user, @info) @passport.authenticate.callsArgWith(1, null, @user, @info)
@err = new Error('woops')
it 'should call passport.authenticate', () -> it 'should call passport.authenticate', () ->
@AuthenticationController.passportLogin @req, @res, @next @AuthenticationController.passportLogin @req, @res, @next
@ -108,6 +107,7 @@ describe "AuthenticationController", ->
describe 'when authenticate produces an error', -> describe 'when authenticate produces an error', ->
beforeEach -> beforeEach ->
@err = new Error('woops')
@passport.authenticate.callsArgWith(1, @err) @passport.authenticate.callsArgWith(1, @err)
it 'should return next with an error', () -> it 'should return next with an error', () ->

View file

@ -108,7 +108,6 @@ describe "CollaboratorsInviteController", ->
} }
@LimitationsManager.canAddXCollaborators = sinon.stub().callsArgWith(2, null, true) @LimitationsManager.canAddXCollaborators = sinon.stub().callsArgWith(2, null, true)
@CollaboratorsInviteHandler.inviteToProject = sinon.stub().callsArgWith(4, null, @invite) @CollaboratorsInviteHandler.inviteToProject = sinon.stub().callsArgWith(4, null, @invite)
@err = new Error('woops')
@callback = sinon.stub() @callback = sinon.stub()
@next = sinon.stub() @next = sinon.stub()
@ -164,6 +163,7 @@ describe "CollaboratorsInviteController", ->
beforeEach -> beforeEach ->
@CollaboratorsInviteController._checkShouldInviteEmail = sinon.stub().callsArgWith(1, null, true) @CollaboratorsInviteController._checkShouldInviteEmail = sinon.stub().callsArgWith(1, null, true)
@CollaboratorsInviteController._checkRateLimit = sinon.stub().yields(null, true) @CollaboratorsInviteController._checkRateLimit = sinon.stub().yields(null, true)
@err = new Error('woops')
@LimitationsManager.canAddXCollaborators = sinon.stub().callsArgWith(2, @err) @LimitationsManager.canAddXCollaborators = sinon.stub().callsArgWith(2, @err)
@CollaboratorsInviteController.inviteToProject @req, @res, @next @CollaboratorsInviteController.inviteToProject @req, @res, @next

View file

@ -74,10 +74,11 @@ describe "FileStoreController", ->
describe "with a '#{extension}' file extension", -> describe "with a '#{extension}' file extension", ->
beforeEach -> beforeEach ->
@user_agent = 'A generic browser'
@file.name = "bad#{extension}" @file.name = "bad#{extension}"
@req.get = (key) => @req.get = (key) =>
if key == 'User-Agent' if key == 'User-Agent'
return 'A generic browser' @user_agent
describe "from a non-ios browser", -> describe "from a non-ios browser", ->
@ -90,9 +91,7 @@ describe "FileStoreController", ->
describe "from an iPhone", -> describe "from an iPhone", ->
beforeEach -> beforeEach ->
@req.get = (key) => @user_agent = "An iPhone browser"
if key == 'User-Agent'
return "An iPhone browser"
it "should set Content-Type to 'text/plain'", (done) -> it "should set Content-Type to 'text/plain'", (done) ->
@stream.pipe = (des) => @stream.pipe = (des) =>
@ -103,9 +102,7 @@ describe "FileStoreController", ->
describe "from an iPad", -> describe "from an iPad", ->
beforeEach -> beforeEach ->
@req.get = (key) => @user_agent = "An iPad browser"
if key == 'User-Agent'
return "An iPad browser"
it "should set Content-Type to 'text/plain'", (done) -> it "should set Content-Type to 'text/plain'", (done) ->
@stream.pipe = (des) => @stream.pipe = (des) =>

View file

@ -11,7 +11,7 @@ describe "FileStoreHandler", ->
@fs = @fs =
createReadStream : sinon.stub() createReadStream : sinon.stub()
lstat: sinon.stub().callsArgWith(1, null, { lstat: sinon.stub().callsArgWith(1, null, {
isFile:=> true isFile:=> @isSafeOnFileSystem
isDirectory:-> return false isDirectory:-> return false
}) })
@writeStream = @writeStream =
@ -35,6 +35,7 @@ describe "FileStoreHandler", ->
describe "uploadFileFromDisk", -> describe "uploadFileFromDisk", ->
beforeEach -> beforeEach ->
@request.returns(@writeStream) @request.returns(@writeStream)
@isSafeOnFileSystem = true
it "should create read stream", (done)-> it "should create read stream", (done)->
@fs.createReadStream.returns @fs.createReadStream.returns
@ -90,13 +91,8 @@ describe "FileStoreHandler", ->
done() done()
describe "symlink", -> describe "symlink", ->
beforeEach ->
@fs.lstat = sinon.stub().callsArgWith(1, null, {
isFile:=> false
isDirectory:-> return false
})
it "should not read file if it is symlink", (done)-> it "should not read file if it is symlink", (done)->
@isSafeOnFileSystem = false
@handler.uploadFileFromDisk @project_id, @file_id, @fsPath, => @handler.uploadFileFromDisk @project_id, @file_id, @fsPath, =>
@fs.createReadStream.called.should.equal false @fs.createReadStream.called.should.equal false
done() done()

View file

@ -296,7 +296,7 @@ describe 'ProjectLocator', ->
it "should not crash with a null", (done)-> it "should not crash with a null", (done)->
path = "/other.tex" path = "/other.tex"
@locator.findElementByPath {project_id: project._id, path}, (err, element)-> @locator.findElementByPath {project_id: @project._id, path}, (err, element)->
expect(err).to.exist expect(err).to.exist
done() done()

View file

@ -142,15 +142,13 @@ describe "ReferencesController", ->
describe 'index', -> describe 'index', ->
beforeEach ->
@call = (callback) =>
@controller.index @req, @res
callback()
describe 'with docIds as an array and shouldBroadcast as false', -> describe 'with docIds as an array and shouldBroadcast as false', ->
beforeEach -> beforeEach ->
@ReferencesHandler.index.callsArgWith(2, null, @fakeResponseData) @ReferencesHandler.index.callsArgWith(2, null, @fakeResponseData)
@call = (callback) =>
@controller.index @req, @res
callback()
it 'should call ReferencesHandler.index', (done) -> it 'should call ReferencesHandler.index', (done) ->
@call () => @call () =>

View file

@ -78,16 +78,19 @@ describe "LimitationsManager", ->
@callback.calledWith(null, @user.features.collaborators).should.equal true @callback.calledWith(null, @user.features.collaborators).should.equal true
describe "canAddXCollaborators", -> describe "canAddXCollaborators", ->
beforeEach ->
@CollaboratorsHandler.getInvitedCollaboratorCount = (project_id, callback) => callback(null, @current_number)
@CollaboratorsInviteHandler.getInviteCount = (project_id, callback) => callback(null, @invite_count)
sinon.stub @LimitationsManager,
"allowedNumberOfCollaboratorsInProject",
(project_id, callback) => callback(null, @allowed_number)
@callback = sinon.stub()
describe "when the project has fewer collaborators than allowed", -> describe "when the project has fewer collaborators than allowed", ->
beforeEach -> beforeEach ->
@current_number = 1 @current_number = 1
@allowed_number = 2 @allowed_number = 2
@invite_count = 0 @invite_count = 0
@CollaboratorsHandler.getInvitedCollaboratorCount = (project_id, callback) => callback(null, @current_number)
@CollaboratorsInviteHandler.getInviteCount = (project_id, callback) => callback(null, @invite_count)
sinon.stub @LimitationsManager, "allowedNumberOfCollaboratorsInProject", (project_id, callback) =>
callback(null, @allowed_number)
@callback = sinon.stub()
@LimitationsManager.canAddXCollaborators(@project_id, 1, @callback) @LimitationsManager.canAddXCollaborators(@project_id, 1, @callback)
it "should return true", -> it "should return true", ->
@ -98,11 +101,6 @@ describe "LimitationsManager", ->
@current_number = 1 @current_number = 1
@allowed_number = 4 @allowed_number = 4
@invite_count = 1 @invite_count = 1
@CollaboratorsHandler.getInvitedCollaboratorCount = (project_id, callback) => callback(null, @current_number)
@CollaboratorsInviteHandler.getInviteCount = (project_id, callback) => callback(null, @invite_count)
sinon.stub @LimitationsManager, "allowedNumberOfCollaboratorsInProject", (project_id, callback) =>
callback(null, @allowed_number)
@callback = sinon.stub()
@LimitationsManager.canAddXCollaborators(@project_id, 1, @callback) @LimitationsManager.canAddXCollaborators(@project_id, 1, @callback)
it "should return true", -> it "should return true", ->
@ -113,11 +111,6 @@ describe "LimitationsManager", ->
@current_number = 1 @current_number = 1
@allowed_number = 2 @allowed_number = 2
@invite_count = 0 @invite_count = 0
@CollaboratorsHandler.getInvitedCollaboratorCount = (project_id, callback) => callback(null, @current_number)
@CollaboratorsInviteHandler.getInviteCount = (project_id, callback) => callback(null, @invite_count)
sinon.stub @LimitationsManager, "allowedNumberOfCollaboratorsInProject", (project_id, callback) =>
callback(null, @allowed_number)
@callback = sinon.stub()
@LimitationsManager.canAddXCollaborators(@project_id, 2, @callback) @LimitationsManager.canAddXCollaborators(@project_id, 2, @callback)
it "should return false", -> it "should return false", ->
@ -128,11 +121,6 @@ describe "LimitationsManager", ->
@current_number = 3 @current_number = 3
@allowed_number = 2 @allowed_number = 2
@invite_count = 0 @invite_count = 0
@CollaboratorsHandler.getInvitedCollaboratorCount = (project_id, callback) => callback(null, @current_number)
@CollaboratorsInviteHandler.getInviteCount = (project_id, callback) => callback(null, @invite_count)
sinon.stub @LimitationsManager, "allowedNumberOfCollaboratorsInProject", (project_id, callback) =>
callback(null, @allowed_number)
@callback = sinon.stub()
@LimitationsManager.canAddXCollaborators(@project_id, 1, @callback) @LimitationsManager.canAddXCollaborators(@project_id, 1, @callback)
it "should return false", -> it "should return false", ->
@ -143,11 +131,6 @@ describe "LimitationsManager", ->
@current_number = 100 @current_number = 100
@allowed_number = -1 @allowed_number = -1
@invite_count = 0 @invite_count = 0
@CollaboratorsHandler.getInvitedCollaboratorCount = (project_id, callback) => callback(null, @current_number)
@CollaboratorsInviteHandler.getInviteCount = (project_id, callback) => callback(null, @invite_count)
sinon.stub @LimitationsManager, "allowedNumberOfCollaboratorsInProject", (project_id, callback) =>
callback(null, @allowed_number)
@callback = sinon.stub()
@LimitationsManager.canAddXCollaborators(@project_id, 1, @callback) @LimitationsManager.canAddXCollaborators(@project_id, 1, @callback)
it "should return true", -> it "should return true", ->
@ -158,11 +141,6 @@ describe "LimitationsManager", ->
@current_number = 0 @current_number = 0
@allowed_number = 2 @allowed_number = 2
@invite_count = 2 @invite_count = 2
@CollaboratorsHandler.getInvitedCollaboratorCount = (project_id, callback) => callback(null, @current_number)
@CollaboratorsInviteHandler.getInviteCount = (project_id, callback) => callback(null, @invite_count)
sinon.stub @LimitationsManager, "allowedNumberOfCollaboratorsInProject", (project_id, callback) =>
callback(null, @allowed_number)
@callback = sinon.stub()
@LimitationsManager.canAddXCollaborators(@project_id, 1, @callback) @LimitationsManager.canAddXCollaborators(@project_id, 1, @callback)
it "should return false", -> it "should return false", ->
@ -173,11 +151,6 @@ describe "LimitationsManager", ->
@current_number = 1 @current_number = 1
@allowed_number = 2 @allowed_number = 2
@invite_count = 1 @invite_count = 1
@CollaboratorsHandler.getInvitedCollaboratorCount = (project_id, callback) => callback(null, @current_number)
@CollaboratorsInviteHandler.getInviteCount = (project_id, callback) => callback(null, @invite_count)
sinon.stub @LimitationsManager, "allowedNumberOfCollaboratorsInProject", (project_id, callback) =>
callback(null, @allowed_number)
@callback = sinon.stub()
@LimitationsManager.canAddXCollaborators(@project_id, 1, @callback) @LimitationsManager.canAddXCollaborators(@project_id, 1, @callback)
it "should return false", -> it "should return false", ->

View file

@ -38,8 +38,8 @@ describe 'SubscriptionViewModelBuilder', ->
@builder = SandboxedModule.require modulePath, requires: @builder = SandboxedModule.require modulePath, requires:
"settings-sharelatex": { apis: { recurly: { subdomain: "example.com" }}} "settings-sharelatex": { apis: { recurly: { subdomain: "example.com" }}}
"./RecurlyWrapper": @RecurlyWrapper "./RecurlyWrapper": @RecurlyWrapper
"./PlansLocator": @PlansLocator = {} "./PlansLocator": @PlansLocator
"./SubscriptionLocator": @SubscriptionLocator = {} "./SubscriptionLocator": @SubscriptionLocator
"./SubscriptionFormatters": @SubscriptionFormatters "./SubscriptionFormatters": @SubscriptionFormatters
"./LimitationsManager": {} "./LimitationsManager": {}
"logger-sharelatex": "logger-sharelatex":

View file

@ -105,12 +105,6 @@ describe 'SudoModeMiddlewear', ->
describe 'when external auth is being used', -> describe 'when external auth is being used', ->
beforeEach -> beforeEach ->
@externalAuth = true @externalAuth = true
@call = (cb) =>
@req = {externalAuthenticationSystemUsed: sinon.stub().returns(@externalAuth)}
@res = {redirect: sinon.stub()}
@next = sinon.stub()
@SudoModeMiddlewear.protectPage @req, @res, @next
cb()
it 'should immediately return next with no args', (done) -> it 'should immediately return next with no args', (done) ->
@call () => @call () =>

View file

@ -26,12 +26,12 @@ describe "ArchiveManager", ->
"metrics-sharelatex": @metrics "metrics-sharelatex": @metrics
"fs": @fs = {} "fs": @fs = {}
"fs-extra": @fse = {} "fs-extra": @fse = {}
@callback = sinon.stub()
describe "extractZipArchive", -> describe "extractZipArchive", ->
beforeEach -> beforeEach ->
@source = "/path/to/zip/source.zip" @source = "/path/to/zip/source.zip"
@destination = "/path/to/zip/destination" @destination = "/path/to/zip/destination"
@callback = sinon.stub()
@ArchiveManager._isZipTooLarge = sinon.stub().callsArgWith(1, null, false) @ArchiveManager._isZipTooLarge = sinon.stub().callsArgWith(1, null, false)
describe "successfully", -> describe "successfully", ->

View file

@ -102,7 +102,7 @@ describe "ProjectUploadController", ->
@project_id = "project-id-123" @project_id = "project-id-123"
@folder_id = "folder-id-123" @folder_id = "folder-id-123"
@path = "/path/to/file/on/disk.png" @path = "/path/to/file/on/disk.png"
@name = "filename.png" @filename = "filename.png"
@req.files = @req.files =
qqfile: qqfile:
path: @path path: @path

View file

@ -24,16 +24,21 @@ describe "RateLimiter", ->
@RedisWrapper = @RedisWrapper =
client: sinon.stub().returns(@rclient) client: sinon.stub().returns(@rclient)
@limiterFn = sinon.stub()
@RollingRateLimiter = (opts) =>
return @limiterFn
@limiter = SandboxedModule.require modulePath, requires:
"rolling-rate-limiter": @RollingRateLimiter
"settings-sharelatex":@settings
"logger-sharelatex" : @logger = {log:sinon.stub(), err:sinon.stub()}
"./RedisWrapper": @RedisWrapper
@endpointName = "compiles" @endpointName = "compiles"
@subject = "some-project-id" @subject = "some-project-id"
@timeInterval = 20 @timeInterval = 20
@throttleLimit = 5 @throttleLimit = 5
@requires =
"settings-sharelatex":@settings
"logger-sharelatex" : @logger = {log:sinon.stub(), err:sinon.stub()}
"./RedisWrapper": @RedisWrapper
@details = @details =
endpointName: @endpointName endpointName: @endpointName
subjectName: @subject subjectName: @subject
@ -47,9 +52,7 @@ describe "RateLimiter", ->
describe 'when action is permitted', -> describe 'when action is permitted', ->
beforeEach -> beforeEach ->
@requires["rolling-rate-limiter"] = (opts) => @limiterFn = sinon.stub().callsArgWith(1, null, 0, 22)
return sinon.stub().callsArgWith(1, null, 0, 22)
@limiter = SandboxedModule.require modulePath, requires: @requires
it 'should not produce and error', (done) -> it 'should not produce and error', (done) ->
@limiter.addCount {}, (err, should) -> @limiter.addCount {}, (err, should) ->
@ -64,9 +67,7 @@ describe "RateLimiter", ->
describe 'when action is not permitted', -> describe 'when action is not permitted', ->
beforeEach -> beforeEach ->
@requires["rolling-rate-limiter"] = (opts) => @limiterFn = sinon.stub().callsArgWith(1, null, 4000, 0)
return sinon.stub().callsArgWith(1, null, 4000, 0)
@limiter = SandboxedModule.require modulePath, requires: @requires
it 'should not produce and error', (done) -> it 'should not produce and error', (done) ->
@limiter.addCount {}, (err, should) -> @limiter.addCount {}, (err, should) ->
@ -81,9 +82,7 @@ describe "RateLimiter", ->
describe 'when limiter produces an error', -> describe 'when limiter produces an error', ->
beforeEach -> beforeEach ->
@requires["rolling-rate-limiter"] = (opts) => @limiterFn = sinon.stub().callsArgWith(1, new Error('woops'))
return sinon.stub().callsArgWith(1, new Error('woops'))
@limiter = SandboxedModule.require modulePath, requires: @requires
it 'should produce and error', (done) -> it 'should produce and error', (done) ->
@limiter.addCount {}, (err, should) -> @limiter.addCount {}, (err, should) ->

View file

@ -13,12 +13,12 @@ define ['ide/editor/directives/cmEditor'], () ->
} }
it 'inits Rich Text', () -> it 'inits Rich Text', () ->
inject ($compile, $rootScope) => inject ($compile, $rootScope) ->
$compile('<div cm-editor></div>')($rootScope) $compile('<div cm-editor></div>')($rootScope)
expect(@richTextInit).to.have.been.called expect(@richTextInit).to.have.been.called
it 'attaches to CM', () -> it 'attaches to CM', () ->
inject ($compile, $rootScope, $browser) => inject ($compile, $rootScope, $browser) ->
getSnapshot = sinon.stub() getSnapshot = sinon.stub()
detachFromCM = sinon.stub() detachFromCM = sinon.stub()
attachToCM = sinon.stub() attachToCM = sinon.stub()
@ -40,7 +40,7 @@ define ['ide/editor/directives/cmEditor'], () ->
expect(attachToCM).to.have.been.called expect(attachToCM).to.have.been.called
it 'detaches from CM when destroyed', () -> it 'detaches from CM when destroyed', () ->
inject ($compile, $rootScope) => inject ($compile, $rootScope) ->
@richTextInit.returns({ setValue: sinon.stub() }) @richTextInit.returns({ setValue: sinon.stub() })
detachFromCM = sinon.stub() detachFromCM = sinon.stub()
$rootScope.sharejsDoc = { $rootScope.sharejsDoc = {

View file

@ -3,7 +3,7 @@
tests = [] tests = []
for file of window.__karma__.files for file of window.__karma__.files
if window.__karma__.files.hasOwnProperty(file) if window.__karma__.files.hasOwnProperty(file)
if /test\/unit_frontend\/js.+Tests.js$/.test(file) if /Tests\.js$/.test(file)
tests.push(file) tests.push(file)
requirejs.config requirejs.config