From 8a659456caa35c5b9d69c80fabeaf5a45649cc72 Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Thu, 1 Jun 2017 13:59:11 -0400 Subject: [PATCH] fix spec serving unit test --- .../server/test/unit/saved_state_spec.coffee | 8 +++---- packages/server/test/unit/spec_spec.coffee | 24 +++++++++++-------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/packages/server/test/unit/saved_state_spec.coffee b/packages/server/test/unit/saved_state_spec.coffee index 02530a69f2..b3536791f9 100644 --- a/packages/server/test/unit/saved_state_spec.coffee +++ b/packages/server/test/unit/saved_state_spec.coffee @@ -44,11 +44,11 @@ describe "lib/saved_state", -> expect(statePath).to.equal(expected) it "caches state file instance per path", -> - a = savedState("foo/bar") - b = savedState("foo/bar") + a = savedState("/foo/bar") + b = savedState("/foo/bar") expect(a).to.equal(b) it "returns different state file for different path", -> - a = savedState("foo/bar") - b = savedState("foo/baz") + a = savedState("/foo/bar") + b = savedState("/foo/baz") expect(a).to.not.equal(b) diff --git a/packages/server/test/unit/spec_spec.coffee b/packages/server/test/unit/spec_spec.coffee index 79ad057ed9..10c6ac2021 100644 --- a/packages/server/test/unit/spec_spec.coffee +++ b/packages/server/test/unit/spec_spec.coffee @@ -43,10 +43,13 @@ browserifyFile = (filePath) -> ) describe "lib/controllers/spec", -> + specName = "sample.js" + specSource = ";" + beforeEach -> @config = { projectName: "foo?bar" - projectRoot: "" + projectRoot: "/foobar" integrationFolder: fixturesRoot browserify: { basedir: fixturesRoot @@ -67,14 +70,15 @@ describe "lib/controllers/spec", -> watchBundle: -> Promise.resolve() } - fs.ensureDirSync(appData.path("bundles", "foobar")) - fs.writeFileSync(appData.path("bundles", "foobar", "sample.js"), ';') + samplePath = bundle.outputPath(@config.projectRoot, specName) + fs.ensureDirSync(path.dirname(samplePath)) + fs.writeFileSync(samplePath, ';') @handle = (filePath) => spec.handle filePath, {}, @res, @config, (=>), @watchers, @project it "sets the correct content type", -> - @handle("sample.js") + @handle(specName) expect(@res.type) .to.have.been.calledOnce @@ -83,15 +87,15 @@ describe "lib/controllers/spec", -> describe "headed mode", -> it "sends the file from the bundles path", -> - @handle("sample.js") + @handle(specName) collectResponse(@res).then (result) -> - expect(result).to.equal(";") + expect(result).to.equal(specSource) it "sends the client-side error if there is one", -> @watchers.watchBundle = -> Promise.reject(new Error("Reason request failed")) - @handle("sample.js").then => + @handle(specName).then => expect(@res.send).to.have.been.called expect(@res.send.firstCall.args[0]).to.include("(function") expect(@res.send.firstCall.args[0]).to.include("Reason request failed") @@ -104,10 +108,10 @@ describe "lib/controllers/spec", -> @config.isHeadless = true it "sends the file from the bundles path", -> - @handle("sample.js") + @handle(specName) collectResponse(@res).then (result) -> - expect(result).to.equal(";") + expect(result).to.equal(specSource) it "logs the error and exits if there is one", -> err = new Error("Reason request failed") @@ -117,7 +121,7 @@ describe "lib/controllers/spec", -> }) @log = @sandbox.stub(errors, "log") - @handle("sample.js").then => + @handle(specName).then => expect(@log).to.have.been.called expect(@log.firstCall.args[0].stack).to.include("Oops...we found an error preparing this test file") expect(@project.emit).to.have.been.calledWithMatch("exitEarlyWithErr", "Oops...we found an error preparing this test file")