From 2973302e73828492e5d57fb23ab21fd53a6c9793 Mon Sep 17 00:00:00 2001 From: Simon Detheridge Date: Wed, 5 Dec 2018 13:23:16 +0000 Subject: [PATCH] Merge pull request #1230 from sharelatex/spd-fix-projectrootdocmanager-tests Fix tests in ProjectRootDocManager GitOrigin-RevId: b68c4b597f24a009c35a0f83f4573fdf84959cd7 --- .../Project/ProjectRootDocManagerTests.coffee | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/services/web/test/unit/coffee/Project/ProjectRootDocManagerTests.coffee b/services/web/test/unit/coffee/Project/ProjectRootDocManagerTests.coffee index 0de8dce9c4..0e42445a76 100644 --- a/services/web/test/unit/coffee/Project/ProjectRootDocManagerTests.coffee +++ b/services/web/test/unit/coffee/Project/ProjectRootDocManagerTests.coffee @@ -15,8 +15,9 @@ describe 'ProjectRootDocManager', -> "doc-id-4": "/nested/chapter1b.tex" @sl_req_id = "sl-req-id-123" @callback = sinon.stub() - @globby = sinon.stub().returns(new Promise (resolve) -> - resolve(['a.tex', 'b.tex', 'main.tex']) + @globbyFiles = ['a.tex', 'b.tex', 'main.tex'] + @globby = sinon.stub().returns(new Promise (resolve) => + resolve(@globbyFiles) ) @fs = readFile: sinon.stub().callsArgWith(2, new Error('file not found')) @@ -100,14 +101,14 @@ describe 'ProjectRootDocManager', -> @documentclassContent = "% test\n\\documentclass\n\% test" describe "when there is a file in a subfolder", -> - @globby = sinon.stub().returns(new Promise (resolve) -> - resolve(['c.tex', 'a.tex', 'a/a.tex', 'b.tex']) - ) + beforeEach -> + # have to splice globbyFiles weirdly because of the way the stubbed globby method handles references + @globbyFiles.splice(0, @globbyFiles.length, 'c.tex', 'a.tex', 'a/a.tex', 'b.tex') - it "processes the root folder files first, and then the subfolder, in alphabetical order", -> - @ProjectRootDocManager.findRootDocFileFromDirectory '/foo', => + it "processes the root folder files first, and then the subfolder, in alphabetical order", (done) -> + @ProjectRootDocManager.findRootDocFileFromDirectory '/foo', (error, path) => expect(error).not.to.exist - expect(path).to.equal null + expect(path).not.to.exist sinon.assert.callOrder( @fs.readFile.withArgs('/foo/a.tex') @fs.readFile.withArgs('/foo/b.tex') @@ -116,11 +117,11 @@ describe 'ProjectRootDocManager', -> ) done() - it "processes smaller files first", -> + it "processes smaller files first", (done) -> @fs.stat.withArgs('/foo/c.tex').callsArgWith(1, null, {size: 1}) - @ProjectRootDocManager.findRootDocFileFromDirectory '/foo', => + @ProjectRootDocManager.findRootDocFileFromDirectory '/foo',(error, path) => expect(error).not.to.exist - expect(path).to.equal null + expect(path).not.to.exist sinon.assert.callOrder( @fs.readFile.withArgs('/foo/c.tex') @fs.readFile.withArgs('/foo/a.tex')