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

Commit 2a38924

Browse files
authored
Merge pull request #297 from exoego/console
[console] Allow 0 argument logging & Allow seq.foreach(Consoe.log)
2 parents e675c7a + ea91666 commit 2a38924

File tree

2 files changed

+56
-10
lines changed

2 files changed

+56
-10
lines changed

app/nodejs-v10/src/test/scala/io/scalajs/nodejs/console_module/ConsoleTest.scala

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,43 @@ class ConsoleTest extends AnyFunSpec with BeforeAndAfterEach {
1313
if (Fs.existsSync(logFileName)) Fs.unlinkSync(logFileName)
1414
}
1515

16+
it("should accept no-arguments") {
17+
Console.log()
18+
Console.info()
19+
Console.warn()
20+
Console.debug()
21+
Console.error()
22+
Console.trace()
23+
}
24+
25+
it("should accept single arguments") {
26+
Console.log("a")
27+
Console.info("a")
28+
Console.warn("a")
29+
Console.debug("a")
30+
Console.error("a")
31+
Console.trace("")
32+
}
33+
34+
it("should accept multiple arguments") {
35+
Console.log("a", 1)
36+
Console.info("a", 2)
37+
Console.warn("a", 3)
38+
Console.debug("a", 4)
39+
Console.error("a", 5)
40+
Console.trace("", 6)
41+
}
42+
43+
it("should be passed to foreach") {
44+
val s: Seq[js.Any] = Seq("s", true)
45+
s.foreach(Console.log)
46+
s.foreach(Console.info)
47+
s.foreach(Console.warn)
48+
s.foreach(Console.debug)
49+
s.foreach(Console.error)
50+
s.foreach(Console.trace)
51+
}
52+
1653
it("have table added in v10.0.0") {
1754
Console.table(js.Array("x", "y"))
1855
}

app/nodejs-v14/src/main/scala/io/scalajs/nodejs/console_module/Console.scala

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ class Console protected () extends js.Object {
7777

7878
/**
7979
* The `console.debug()` function is an alias for `console.log()`.
80-
* @param message
81-
* @param optionalParams
8280
*/
83-
def debug(message: js.Any, optionalParams: Any*): Unit = js.native
81+
def debug(data: js.Any, args: js.Any*): Unit = js.native
82+
def debug(data: js.Any): Unit = js.native
83+
def debug(): Unit = js.native
8484

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

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

137140
/**
138141
* Prints to `stdout` with newline.
139142
* Multiple arguments can be passed, with the first used as the primary message and all additional used as
140143
* substitution values similar to `printf(3)` (the arguments are all passed to `util.format()`).
141144
*/
142-
def log(message: js.Any, optionalParams: Any*): Unit = js.native
145+
def log(data: js.Any, args: js.Any*): Unit = js.native
146+
def log(data: js.Any): Unit = js.native
147+
def log(): Unit = js.native
143148

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

181188
/**
182189
* The `console.warn()` function is an alias for [[error()]
183190
*/
184-
def warn(message: js.Any, optionalParams: js.Any*): Unit = js.native
191+
def warn(data: js.Any, args: js.Any*): Unit = js.native
192+
def warn(data: js.Any): Unit = js.native
193+
def warn(): Unit = js.native
185194

186195
/**
187196
* This method does not display anything unless used in the inspector.

0 commit comments

Comments
 (0)