Skip to content

Commit

Permalink
Additional test class clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
ldaniels528 committed Feb 3, 2017
1 parent 1e70e9f commit 3b19308
Show file tree
Hide file tree
Showing 17 changed files with 199 additions and 158 deletions.
2 changes: 2 additions & 0 deletions core/src/main/scala/io/scalajs/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import scala.scalajs.js.|
*/
package object scalajs {

type JsAnything = js.Any | js.Object | JsNumber | String | Boolean

type JsNumber = Byte | Double | Float | Int | Long | Short | java.lang.Number

type RawOptions = js.Dictionary[_] | js.Object
Expand Down
45 changes: 23 additions & 22 deletions nodejs/src/main/scala/io/scalajs/nodejs/Assert.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.scalajs.nodejs

import io.scalajs.JsAnything
import io.scalajs.nodejs.events.IEventEmitter

import scala.scalajs.js
Expand All @@ -12,15 +13,7 @@ import scala.scalajs.js.annotation.JSImport
*
* The API for the assert module is Locked. This means that there will be no additions or changes to any of the
* methods implemented and exposed by the module.
* @version 6.2.1
* @author [email protected]
*/
@js.native
@JSImport("assert", JSImport.Namespace)
object Assert extends Assert

/**
* Assert Type Definition
* @version 7.4.0
* @author [email protected]
*/
@js.native
Expand All @@ -31,7 +24,7 @@ trait Assert extends IEventEmitter {
* @param expression the expression to evaluate
* @example assert(value[, message])
*/
def apply(expression: js.Any, message: String = null): Unit = js.native
def apply(expression: JsAnything, message: String = js.native): Unit = js.native

/**
* Tests for deep equality between the actual and expected parameters. Primitive values are compared with the equal
Expand All @@ -40,14 +33,14 @@ trait Assert extends IEventEmitter {
* surprising results.
* @example assert.deepEqual(actual, expected[, message])
*/
def deepEqual(actual: js.Any, expected: js.Any, message: String = null): Unit = js.native
def deepEqual(actual: JsAnything, expected: JsAnything, message: String = js.native): Unit = js.native

/**
* Generally identical to assert.deepEqual() with two exceptions. First, primitive values are compared using the
* strict equality operator ( === ). Second, object comparisons include a strict equality check of their prototypes.
* @example assert.deepStrictEqual(actual, expected[, message])
*/
def deepStrictEqual(actual: js.Any, expected: js.Any, message: String): Unit = js.native
def deepStrictEqual(actual: JsAnything, expected: JsAnything, message: String): Unit = js.native

/**
* Asserts that the function block does not throw an error. See assert.throws() for more details.
Expand All @@ -74,20 +67,20 @@ trait Assert extends IEventEmitter {
* error is of a different type, or if the error parameter is undefined, the error is propagated back to the caller.
* @example assert.doesNotThrow(block[, error][, message])
*/
def doesNotThrow(block: js.Function, error: js.Any = null): Unit = js.native
def doesNotThrow(block: js.Function, error: js.Any = js.native): Unit = js.native

/**
* Tests shallow, coercive equality between the actual and expected parameters using the equal comparison operator ( == ).
* @example assert.equal(actual, expected[, message])
*/
def equal(actual: js.Any, expected: js.Any, message: String = null): Unit = js.native
def equal(actual: JsAnything, expected: JsAnything, message: String = js.native): Unit = js.native

/**
* Throws an AssertionError. If message is falsy, the error message is set as the values of actual and expected
* separated by the provided operator. Otherwise, the error message is the value of message.
* @example assert.fail(actual, expected, message, operator)
*/
def fail(actual: js.Any, expected: js.Any, message: String, operator: String): Unit = js.native
def fail(actual: JsAnything, expected: JsAnything, message: String, operator: String): Unit = js.native

/**
* Throws value if value is truthy. This is useful when testing the error argument in callbacks.
Expand All @@ -99,44 +92,52 @@ trait Assert extends IEventEmitter {
* Tests for any deep inequality. Opposite of assert.deepEqual().
* @example assert.notDeepEqual(actual, expected[, message])
*/
def notDeepEqual(actual: js.Any, expected: js.Any, message: String = null): Unit = js.native
def notDeepEqual(actual: JsAnything, expected: JsAnything, message: String = js.native): Unit = js.native

/**
* Tests for deep strict inequality. Opposite of assert.deepStrictEqual().
* @example assert.notDeepStrictEqual(actual, expected[, message])
*/
def notDeepStrictEqual(actual: js.Any, expected: js.Any, message: String = null): Unit = js.native
def notDeepStrictEqual(actual: JsAnything, expected: JsAnything, message: String = js.native): Unit = js.native

/**
* Tests shallow, coercive inequality with the not equal comparison operator ( != ).
* @example assert.notEqual(actual, expected[, message])
*/
def notEqual(actual: js.Any, expected: js.Any, message: String = null): Unit = js.native
def notEqual(actual: JsAnything, expected: JsAnything, message: String = js.native): Unit = js.native

/**
* Tests strict inequality as determined by the strict not equal operator ( !== ).
* @example assert.notStrictEqual(actual, expected[, message])
*/
def notStrictEqual(actual: js.Any, expected: js.Any, message: String = null): Unit = js.native
def notStrictEqual(actual: JsAnything, expected: JsAnything, message: String = js.native): Unit = js.native

/**
* Tests if value is truthy. It is equivalent to assert.equal(!!value, true, message). If value is not truthy,
* an AssertionError is thrown with a message property set equal to the value of the message parameter. If the
* message parameter is undefined, a default error message is assigned.
*/
def ok(value: js.Any, message: String = null): Unit = js.native
def ok(value: JsAnything, message: String = js.native): Unit = js.native

/**
* Tests strict equality as determined by the strict equality operator ( === ).
* @example assert.strictEqual(actual, expected[, message])
*/
def strictEqual(actual: js.Any, expected: js.Any, message: String = null): Unit = js.native
def strictEqual(actual: JsAnything, expected: JsAnything, message: String = js.native): Unit = js.native

/**
* If the values are not strictly equal, an AssertionError is thrown with a message property set equal to the value
* of the message parameter. If the message parameter is undefined, a default error message is assigned.
* @example assert.throws(block[, error][, message])
*/
def throws(block: js.Function, error: js.Any, message: String = null): Unit = js.native
def throws(block: js.Function, error: js.Any, message: String = js.native): Unit = js.native

}

/**
* Assert Singleton
* @author [email protected]
*/
@js.native
@JSImport("assert", JSImport.Namespace)
object Assert extends Assert
15 changes: 7 additions & 8 deletions npm/async/src/test/scala/io/scalajs/npm/async/AsyncTest.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package io.scalajs.npm.async

import io.scalajs.JSON
import io.scalajs.nodejs
import io.scalajs.nodejs.fs.Fs
import io.scalajs.nodejs.{Error, console, errors}
import io.scalajs.nodejs.{Error, console}
import io.scalajs.npm.async.AsyncTest._
import io.scalajs.util.ScalaJsHelper._
import org.scalatest.FunSpec
Expand Down Expand Up @@ -96,7 +95,7 @@ class AsyncTest extends FunSpec {
}

it("supports forEachOf via callbacks") {
val obj = js.Dictionary("dev" -> "/dev.json", "test" -> "/test.json", "prod" -> "/prod.json")
val obj = js.Dictionary("dev" -> "/dev.json", "test" -> "/test.json", "prod" -> "/prod.json")
val configs = js.Dictionary[js.Any]()

Async.forEachOf(
Expand Down Expand Up @@ -129,7 +128,7 @@ class AsyncTest extends FunSpec {

it("supports forEachOf via promises (1)") {
val envFiles = js.Dictionary("dev" -> "/dev.json", "test" -> "/test.json", "prod" -> "/prod.json")
val configs = js.Dictionary[js.Any]()
val configs = js.Dictionary[js.Any]()

Async.forEachOfFuture(envFiles) { (value: String, key: String, callback: js.Function1[Error, Any]) =>
Fs.readFile(
Expand All @@ -142,7 +141,7 @@ class AsyncTest extends FunSpec {
configs(key) = JSON.parse(data)
} match {
case Success(_) => callback(null)
case Failure(e) => callback(nodejs.Error(e.getMessage))
case Failure(e) => callback(new Error(e.getMessage))
}
}
console.log("Done B")
Expand All @@ -152,8 +151,8 @@ class AsyncTest extends FunSpec {
}

it("supports forEachOf via promises (2)") {
val envs = js.Array("dev", "test", "prod")
val files = js.Array("/dev.json", "/test.json", "/prod.json")
val envs = js.Array("dev", "test", "prod")
val files = js.Array("/dev.json", "/test.json", "/prod.json")
val configs = js.Dictionary[js.Any]()

Async.forEachOfFuture(files) { (value: String, index: Int, callback: js.Function1[Error, Any]) =>
Expand All @@ -167,7 +166,7 @@ class AsyncTest extends FunSpec {
configs(envs(index)) = JSON.parse(data)
} match {
case Success(_) => callback(null)
case Failure(e) => callback(nodejs.Error(e.getMessage))
case Failure(e) => callback(new Error(e.getMessage))
}
}
console.log("Done C")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class CassandraDriverTest extends FunSpec {
}

it("supports CRUD operations") {
// TODO use mock or embedded server
/*
val client = new Client(new ClientOptions(contactPoints = js.Array("localhost"), keyspace = "classroom"))
val students = Seq(
js.Array("123456", "Larry Sanders", "Operating Systems")
Expand All @@ -48,10 +50,12 @@ class CassandraDriverTest extends FunSpec {
client.execute("INSERT INTO students (id, name, course) VALUES (?, ?, ?)", params, (err, student) => {
console.log("student =>", student)
})
}
}*/
}

it("supports streaming results via readOption") {
// TODO use mock or embedded server
/*
val client = new Client(new ClientOptions(contactPoints = js.Array("localhost"), keyspace = "servo"))
val readable = client.stream("select * from feed_types limit 1")
readable
Expand All @@ -68,10 +72,12 @@ class CassandraDriverTest extends FunSpec {
}
)
.on("end", () => {})
.on("error", (err: Error) => console.error(err))
.on("error", (err: Error) => console.error(err))*/
}

it("supports streaming results via iterator") {
// TODO use mock or embedded server
/*
val client = new Client(new ClientOptions(contactPoints = js.Array("localhost"), keyspace = "servo"))
val readable = client.stream("select * from feed_types limit 1")
readable
Expand All @@ -81,12 +87,14 @@ class CassandraDriverTest extends FunSpec {
}
})
.on("end", () => {})
.on("error", (err: Error) => console.error(err))
.on("error", (err: Error) => console.error(err))*/
}

}

it("supports queries") {
// TODO use mock or embedded server
/*
val client = new Client(
new ClientOptions(policies =
new LoadBalancingPolicyOptions(loadBalancing = new DCAwareRoundRobinPolicy("US_EAST")),
Expand All @@ -99,10 +107,12 @@ class CassandraDriverTest extends FunSpec {
client.execute(query, params, (err, result) => {
Assert.ifError(err)
console.log("got user profile with email " + result.get("email").orUndefined)
})
})*/
}

it("supports batch operations") {
// TODO use mock or embedded server
/*
val client = new Client(new ClientOptions(contactPoints = js.Array("localhost"), keyspace = "ks1"))
val emailAddress = "[email protected]"
Expand All @@ -116,7 +126,7 @@ class CassandraDriverTest extends FunSpec {
client.batch(queries, queryOptions, (err: js.Error) => {
Assert.ifError(err)
console.log("Data updated on cluster")
})
})*/
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@ trait CsvParse extends IEventEmitter {
// Streaming
/////////////////////////////////////////////////////////////////////////////////

def apply(text: String, options: ParserOptions | RawOptions = js.native): Parser = js.native
def apply(text: String): Parser = js.native

def apply(options: ParserOptions | RawOptions): Parser = js.native

def apply(text: String, options: ParserOptions | RawOptions): Parser = js.native

/////////////////////////////////////////////////////////////////////////////////
// Asynchronous
/////////////////////////////////////////////////////////////////////////////////

def apply(text: String, options: ParserOptions | RawOptions, callback: js.Function2[String, CsvResults, Any]): Unit =
js.native
def apply(options: ParserOptions | RawOptions, callback: js.Function2[String, CsvResults, Any]): Unit = js.native

def apply(text: String, options: ParserOptions | RawOptions, callback: js.Function2[String, CsvResults, Any]): Unit = js.native

def apply(text: String, callback: js.Function2[String, CsvResults, Any]): Unit = js.native

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import scala.scalajs.js.|
* the first line and returning the column names, or true if autodiscovered in the first
* CSV line. Defaults to null. Affects the result data set in the sense that records will
* be objects instead of arrays.
* @param comment Treat all the characters after this one as a comment. Defaults to '' (disabled).
* @param comment Treat all the characters after this one as a comment. Defaults to "" (disabled).
* @param objname Name of header-record title to name objects by.
* @param relax Preserve quotes inside unquoted field.
* @param relax_column_count Discard inconsistent columns count. Default to false.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MulterTest extends FunSpec {

it("handles simple file uploads") {
val app = Express()
val upload = Multer()
val upload = Multer(new MulterOptions(dest = "uploads/"))
app.post("/profile", upload.array(), (req: Request, res: Response, next: js.Function) => {
// req.body contains the text fields
})
Expand Down
8 changes: 4 additions & 4 deletions npm/jsdom/src/test/scala/io/scalajs/npm/jsdom/JsDomTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class JsDomTest extends FunSpec {
describe("JsDom") {

it("should parse an HTML snippet into a DOM instance") {
val doc = JsDom.jsdom("""<p id="p1"><a class="the-link" href="https://github.com/tmpvar/jsdom">jsdom!</a></p>""")
val doc = JsDom.jsdom("""<p id="p1"><a class="the-link" href="https://github.com/tmpvar/jsdom">jsdom!</a></p>""")
val elem = doc.getElementsByClassName("the-link").headOption.orNull
assert(elem != null)

Expand All @@ -33,7 +33,7 @@ class JsDomTest extends FunSpec {
assert(err == null)

import window.$
assert($("a").nonEmpty)
assert($("a") != null)
}
)
}
Expand Down Expand Up @@ -62,7 +62,7 @@ class JsDomTest extends FunSpec {
assert(err == null)

import window.$
assert($("td.title:not(:last) a").nonEmpty)
assert($("td.title:not(:last) a") != null)
}
))
}
Expand All @@ -79,7 +79,7 @@ class JsDomTest extends FunSpec {
assert(err == null)

import window.$
assert($("td.title:not(:last) a").nonEmpty)
assert($("td.title:not(:last) a") != null)
}
))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.scalajs.npm.kafkarest
import java.util.UUID

import io.scalajs.nodejs.{console, process}
import io.scalajs.npm.kafkarest.KafkaRestTests.UserInfo
import io.scalajs.npm.kafkarest.KafkaRestTest.UserInfo
import io.scalajs.util.OptionHelper._
import io.scalajs.util.ScalaJsHelper._
import org.scalatest.FunSpec
Expand All @@ -18,10 +18,11 @@ import scala.scalajs.js.annotation.ScalaJSDefined
* KafkaRest Tests
* @author [email protected]
*/
class KafkaRestTests extends FunSpec {
class KafkaRestTest extends FunSpec {

describe("KafkaRest") {

// TODO use mock or embedded server
/*
val kafka = new KafkaRest(new KafkaRestOptions(url = "http://localhost:8082"))
it("should be able to list topics") {
Expand Down Expand Up @@ -49,7 +50,7 @@ class KafkaRestTests extends FunSpec {
entertainers foreach { entertainer =>
topic.produce(userInfoSchema, new KeyedMessage(key = UUID.randomUUID().toString, value = entertainer))
}
}
}*/

}

Expand Down Expand Up @@ -84,7 +85,7 @@ class KafkaRestTests extends FunSpec {
* KafkaRest Tests Companion
* @author [email protected]
*/
object KafkaRestTests {
object KafkaRestTest {

@ScalaJSDefined
class UserInfo(val id: Int, val name: String) extends js.Object
Expand Down
Loading

0 comments on commit 3b19308

Please sign in to comment.