Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

[console] Allow 0 argument logging & Allow seq.foreach(Consoe.log) #297

Merged
merged 3 commits into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
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 @@ -13,6 +13,43 @@ class ConsoleTest extends AnyFunSpec with BeforeAndAfterEach {
if (Fs.existsSync(logFileName)) Fs.unlinkSync(logFileName)
}

it("should accept no-arguments") {
Console.log()
Console.info()
Console.warn()
Console.debug()
Console.error()
Console.trace()
}

it("should accept single arguments") {
Console.log("a")
Console.info("a")
Console.warn("a")
Console.debug("a")
Console.error("a")
Console.trace("")
}

it("should accept multiple arguments") {
Console.log("a", 1)
Console.info("a", 2)
Console.warn("a", 3)
Console.debug("a", 4)
Console.error("a", 5)
Console.trace("", 6)
}

it("should be passed to foreach") {
val s: Seq[js.Any] = Seq("s", true)
s.foreach(Console.log)
s.foreach(Console.info)
s.foreach(Console.warn)
s.foreach(Console.debug)
s.foreach(Console.error)
s.foreach(Console.trace)
}

it("have table added in v10.0.0") {
Console.table(js.Array("x", "y"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ class Console protected () extends js.Object {

/**
* The `console.debug()` function is an alias for `console.log()`.
* @param message
* @param optionalParams
*/
def debug(message: js.Any, optionalParams: Any*): Unit = js.native
def debug(data: js.Any, args: js.Any*): Unit = js.native
def debug(data: js.Any): Unit = js.native
def debug(): Unit = js.native

/**
* Uses [[io.scalajs.nodejs.util.Util.inspect()]] on `obj` and prints the resulting string to `stdout`.
Expand All @@ -104,10 +104,11 @@ class Console protected () extends js.Object {
* is called on each argument and the resulting string values are concatenated. See [[io.scalajs.nodejs.util.Util.format()]]
* for more information.
*
* @param message
* @param optionalParams
* @param args
*/
def error(message: js.Any, optionalParams: Any*): Unit = js.native
def error(data: js.Any, args: js.Any*): Unit = js.native
def error(data: js.Any): Unit = js.native
def error(): Unit = js.native

/**
* Increases indentation of subsequent lines by two spaces.
Expand All @@ -132,14 +133,18 @@ class Console protected () extends js.Object {
/**
* The `console.info()` function is an alias for [[log()]].
*/
def info(message: js.Any, optionalParams: js.Any*): Unit = js.native
def info(data: js.Any, args: js.Any*): Unit = js.native
def info(data: js.Any): Unit = js.native
def info(): Unit = js.native

/**
* Prints to `stdout` with newline.
* Multiple arguments can be passed, with the first used as the primary message and all additional used as
* substitution values similar to `printf(3)` (the arguments are all passed to `util.format()`).
*/
def log(message: js.Any, optionalParams: Any*): Unit = js.native
def log(data: js.Any, args: js.Any*): Unit = js.native
def log(data: js.Any): Unit = js.native
def log(): Unit = js.native

/**
* Try to construct a table with the columns of the properties of `tabularData` (or use `properties`) and
Expand Down Expand Up @@ -176,12 +181,16 @@ class Console protected () extends js.Object {
* Prints to `stderr` the string `'Trace: '`, followed by the [[io.scalajs.nodejs.util.Util.format()]] formatted
* message and stack trace to the current position in the code.
*/
def trace(message: js.Any, optionalParams: js.Any*): Unit = js.native
def trace(data: js.Any, args: js.Any*): Unit = js.native
def trace(data: js.Any): Unit = js.native
def trace(): Unit = js.native

/**
* The `console.warn()` function is an alias for [[error()]
*/
def warn(message: js.Any, optionalParams: js.Any*): Unit = js.native
def warn(data: js.Any, args: js.Any*): Unit = js.native
def warn(data: js.Any): Unit = js.native
def warn(): Unit = js.native

/**
* This method does not display anything unless used in the inspector.
Expand Down