Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cats-effect JS tests flakiness #209

Merged
merged 1 commit into from
Jun 15, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ import org.scalatest.{Assertion, AsyncFunSuite, Matchers}
import fr.hmil.roshttp.response.SimpleHttpResponse
import github4s.GithubResponses.GHResponse
import github4s.free.domain.User
import org.scalactic.source.Position

import scala.concurrent.{ExecutionContext, ExecutionContextExecutor, Future, Promise}
import scala.util.Try
import scala.concurrent.{ExecutionContext, ExecutionContextExecutor}
import scala.scalajs.js

class CatsEffectJSSpec extends AsyncFunSuite with Matchers {

implicit override def executionContext: ExecutionContextExecutor = ExecutionContext.global

val accessToken = sys.env.get("GITHUB4S_ACCESS_TOKEN")
val accessToken =
js.Dynamic.global.process.env.GITHUB4S_ACCESS_TOKEN.asInstanceOf[js.UndefOr[String]].toOption
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😮 👍

val headerUserAgent = Map("user-agent" -> "github4s")
val validUsername = "rafaparadela"
val invalidUsername = "GHInvalidUserName"
Expand All @@ -44,20 +44,24 @@ class CatsEffectJSSpec extends AsyncFunSuite with Matchers {
.get(validUsername)
.exec[IO, SimpleHttpResponse](headerUserAgent)

response.unsafeToFuture().map { r: GHResponse[User] =>
r.isRight shouldBe true
r.right.map(_.statusCode) shouldBe Right(okStatusCode)
}
response
.unsafeToFuture()
.map { r: GHResponse[User] =>
r.isRight shouldBe true
r.right.map(_.statusCode) shouldBe Right(okStatusCode)
}
}

test("return a failed result for an invalid call") {
val response = Github(accessToken).users
.get(invalidUsername)
.exec[IO, SimpleHttpResponse](headerUserAgent)

response.unsafeToFuture().map { r: GHResponse[User] =>
r.isLeft shouldBe true
}
response
.unsafeToFuture()
.map { r: GHResponse[User] =>
r.isLeft shouldBe true
}
}

// only here for the 80% coverage, to remove once JS makes use of Captures
Expand Down