diff --git a/.travis.yml b/.travis.yml index 47684a085..21d2215cb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,10 +5,19 @@ scala: - 2.12.8 - 2.13.0 +env: + - TRAVIS_NODE_VERSION="12.5.0" + jdk: - openjdk8 - openjdk11 +install: + - rm -rf ~/.nvm && + git clone https://github.com/nvm-sh/nvm.git ~/.nvm && + (cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`) && + source ~/.nvm/nvm.sh && nvm install $TRAVIS_NODE_VERSION + script: - sbt ++$TRAVIS_SCALA_VERSION scalafmtSbtCheck scalafmtCheck test:scalafmtCheck test diff --git a/README.md b/README.md index 3130f1a4c..6fdd54e86 100644 --- a/README.md +++ b/README.md @@ -27,34 +27,35 @@ libraryDependencies += "net.exoego" %%% "scala-js-nodejs-v8" % "0.8.0" ### Supported Modules -The following core Node.js modules (v8.7.0) have been implemented: - -| Node Module | Description | -| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| assert | Provides a simple set of assertion tests that can be used to test invariants. | -| buffer | The Buffer class was introduced as part of the Node.js API to make it possible to interact with octet streams in the context of things like TCP streams and file system operations. | -| child_process | The child_process module provides the ability to spawn child processes. | -| cluster | The cluster module allows you to easily create child processes that all share server ports. | -| crypto | The crypto module provides cryptographic functionality that includes a set of wrappers for OpenSSL's hash, HMAC, cipher, decipher, sign and verify functions. | -| dns | Support for DNS queries. | -| events | Node.js Events Interface | -| fs | File I/O is provided by simple wrappers around standard POSIX functions. | -| http | Node.js HTTP Interface | -| https | Node.js HTTPS Interface | -| net | The net module provides you with an asynchronous network wrapper. | -| os | Provides a few basic operating-system related utility functions. | -| path | This module contains utilities for handling and transforming file paths. | -| querystring | The querystring module provides utilities for parsing and formatting URL query strings. | -| readline | Readline allows reading of a stream on a line-by-line basis. | -| repl | The REPL provides a way to interactively run JavaScript and see the results. | -| stream | A stream is an abstract interface implemented by various objects in Node.js. | -| string-decoder | The string_decoder module provides an API for decoding Buffer objects into strings in a manner that preserves encoded multi-byte UTF-8 and UTF-16 characters. | -| timers | The timer module exposes a global API for scheduling functions to be called at some future period of time. | -| tty | The tty module provides the tty.ReadStream and tty.WriteStream classes. | -| url | The url module provides utilities for URL resolution and parsing. | -| util | The util module is primarily designed to support the needs of Node.js's internal APIs. | -| vm | The vm module provides APIs for compiling and running code within V8 Virtual Machine contexts. | -| zlib | This provides bindings to Gzip/Gunzip, Deflate/Inflate, and DeflateRaw/InflateRaw classes. | +The following core Node.js modules (v8.7.0+) have been implemented: + +| Node Module | Description | v10 & v12 support | +| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------- | +| assert | Provides a simple set of assertion tests that can be used to test invariants. | | +| buffer | The Buffer class was introduced as part of the Node.js API to make it possible to interact with octet streams in the context of things like TCP streams and file system operations. | | +| child_process | The child_process module provides the ability to spawn child processes. | | +| cluster | The cluster module allows you to easily create child processes that all share server ports. | | +| console | The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. | :heavy_check_mark: | +| crypto | The crypto module provides cryptographic functionality that includes a set of wrappers for OpenSSL's hash, HMAC, cipher, decipher, sign and verify functions. | | +| dns | Support for DNS queries. | | +| events | Node.js Events Interface | | +| fs | File I/O is provided by simple wrappers around standard POSIX functions. | | +| http | Node.js HTTP Interface | | +| https | Node.js HTTPS Interface | | +| net | The net module provides you with an asynchronous network wrapper. | | +| os | Provides a few basic operating-system related utility functions. | | +| path | This module contains utilities for handling and transforming file paths. | | +| querystring | The querystring module provides utilities for parsing and formatting URL query strings. | | +| readline | Readline allows reading of a stream on a line-by-line basis. | | +| repl | The REPL provides a way to interactively run JavaScript and see the results. | | +| stream | A stream is an abstract interface implemented by various objects in Node.js. | | +| string-decoder | The string_decoder module provides an API for decoding Buffer objects into strings in a manner that preserves encoded multi-byte UTF-8 and UTF-16 characters. | | +| timers | The timer module exposes a global API for scheduling functions to be called at some future period of time. | | +| tty | The tty module provides the tty.ReadStream and tty.WriteStream classes. | | +| url | The url module provides utilities for URL resolution and parsing. | | +| util | The util module is primarily designed to support the needs of Node.js's internal APIs. | | +| vm | The vm module provides APIs for compiling and running code within V8 Virtual Machine contexts. | | +| zlib | This provides bindings to Gzip/Gunzip, Deflate/Inflate, and DeflateRaw/InflateRaw classes. | | ## Example of code diff --git a/app/current/src/main/scala/io/scalajs/nodejs/Console.scala b/app/current/src/main/scala/io/scalajs/nodejs/Console.scala deleted file mode 100644 index 0715533cf..000000000 --- a/app/current/src/main/scala/io/scalajs/nodejs/Console.scala +++ /dev/null @@ -1,156 +0,0 @@ -package io.scalajs.nodejs - -import io.scalajs.nodejs.stream.Writable - -import scala.scalajs.js -import scala.scalajs.js.annotation.JSImport - -/** - * The console module provides a simple debugging console that is similar to the JavaScript console mechanism - * provided by web browsers. - * - * The module exports two specific components: - * - * @see https://nodejs.org/dist/latest-v8.x/docs/api/console.html - */ -@js.native -@JSImport("console", "Console") -class Console(stdout: Writable, stderr: Writable = js.native) extends js.Object { - - /** - * A simple assertion test that verifies whether value is truthy. If it is not, an AssertionError is thrown. - * If provided, the error message is formatted using util.format() and used as the error message. - * @example console.assert(value[, message][, ...]) - */ - def assert(value: js.Any, message: String, args: Any*): Unit = js.native - - /** - * A simple assertion test that verifies whether value is truthy. If it is not, an AssertionError is thrown. - * If provided, the error message is formatted using util.format() and used as the error message. - * @example console.assert(value[, message][, ...]) - */ - def assert(value: js.Any, args: Any*): Unit = js.native - - /** - * When stdout is a TTY, calling console.clear() will attempt to clear the TTY. When stdout is not a TTY, - * this method does nothing. - * - * Note: The specific operation of console.clear() can vary across operating systems and terminal types. - * For most Linux operating systems, console.clear() operates similarly to the clear shell command. - * On Windows, console.clear() will clear only the output in the current terminal viewport for the Node.js binary. - */ - def clear(): Unit = js.native - - /** - * Maintains an internal counter specific to label and outputs to stdout the number of times console.count() has been called with the given label. - * @param label the display label for the counter. Defaults to 'default'. - */ - def count(label: String = js.native): Unit = js.native - - /** - * Resets the internal counter specific to label. - * @param label the display label for the counter. Defaults to 'default'. - */ - def countReset(label: String = js.native): Unit = js.native - - /** - * Uses util.inspect() on obj and prints the resulting string to stdout. - * This function bypasses any custom inspect() function defined on obj - * @example console.dir(obj[, options]) - */ - def dir(obj: js.Any, options: ConsoleDirOptions): Unit = js.native - - /** - * Uses util.inspect() on obj and prints the resulting string to stdout. - * This function bypasses any custom inspect() function defined on obj - * @example console.dir(obj[, options]) - */ - def dir(obj: js.Any): Unit = js.native - - /** - * Prints to stderr 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()). - * @param data the given data arguments - * @example console.error([data][, ...]) - */ - def error(data: js.Any, args: Any*): Unit = js.native - - /** - * Increases indentation of subsequent lines by two spaces. - * If one or more labels are provided, those are printed first without the additional indentation. - * @param label the labels - */ - def group(label: js.Any*): Unit = js.native - - /** - * An alias for console.group(). - */ - def groupCollapsed(): Unit = js.native - - /** - * Decreases indentation of subsequent lines by two spaces. - */ - def groupEnd(): Unit = js.native - - /** - * The console.info() function is an alias for console.log(). - * @example console.info([data][, ...]) - */ - def info(data: js.Any, args: Any*): 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()). - * @param data the given data arguments - * @example console.log([data][, ...]) - */ - def log(data: js.Any, args: Any*): Unit = js.native - - /** - * Starts a timer that can be used to compute the duration of an operation. Timers are identified by a unique label. - * Use the same label when you call console.timeEnd() to stop the timer and output the elapsed time in milliseconds - * to stdout. Timer durations are accurate to the sub-millisecond. - * @example console.time(label) - */ - def time(label: String): Unit = js.native - - /** - * Stops a timer that was previously started by calling console.time() and prints the result to stdout - * @example console.timeEnd(label) - */ - def timeEnd(label: String): Unit = js.native - - /** - * Prints to stderr the string 'Trace :', followed by the util.format() formatted message and stack trace to the - * current position in the code. - * @example console.trace(message[, ...]) - */ - def trace(message: String, args: Any*): 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()). - * @param data the given data arguments - * @example console.log([data][, ...]) - */ - def warn(data: js.Any, args: Any*): Unit = js.native - -} - -/** - * Console Dir Options - * @param showHidden if true then the object's non-enumerable and symbol properties will be shown too. Defaults to false. - * @param depth tells util.inspect() how many times to recurse while formatting the object. This is useful for - * inspecting large complicated objects. Defaults to 2. To make it recurse indefinitely, pass null. - * @param colors if true, then the output will be styled with ANSI color codes. Defaults to false. Colors are customizable; - * see customizing util.inspect() colors. - */ -class ConsoleDirOptions(var showHidden: js.UndefOr[Boolean] = js.undefined, - var depth: js.UndefOr[Int] = js.undefined, - var colors: js.UndefOr[Boolean] = js.undefined) - extends js.Object diff --git a/app/current/src/main/scala/io/scalajs/nodejs/Global.scala b/app/current/src/main/scala/io/scalajs/nodejs/Global.scala index feeab6d3e..6aeb486e4 100644 --- a/app/current/src/main/scala/io/scalajs/nodejs/Global.scala +++ b/app/current/src/main/scala/io/scalajs/nodejs/Global.scala @@ -70,7 +70,7 @@ trait Global extends js.Object { def clearTimeout: ClearTimeout = js.native - def console: Console = js.native + def console: console_module.Console = js.native def process: Process = js.native diff --git a/app/current/src/main/scala/io/scalajs/nodejs/console_module/Console.scala b/app/current/src/main/scala/io/scalajs/nodejs/console_module/Console.scala new file mode 100644 index 000000000..97a9169c1 --- /dev/null +++ b/app/current/src/main/scala/io/scalajs/nodejs/console_module/Console.scala @@ -0,0 +1,233 @@ +package io.scalajs.nodejs.console_module + +import com.thoughtworks.enableIf +import io.scalajs.nodejs.stream.Writable + +import scala.scalajs.js +import scala.scalajs.js.annotation.{JSGlobal, JSImport} + +/** + * The console module provides a simple debugging console that is similar to the JavaScript console mechanism + * provided by web browsers. + * + * The module exports two specific components: + * + * + * Warning: The global console object's methods are neither consistently synchronous like the browser APIs + * they resemble, nor are they consistently asynchronous like all other Node.js streams. + * See the note on process I/O for more information. + * + * @see https://nodejs.org/api/console.html + */ +@js.native +@JSImport("console", "Console") +class Console protected () extends js.Object { + + def this(stdout: Writable, stderr: Writable = js.native, ignoreErrors: Boolean = true) = this() + + def this(options: ConsoleOptions) = this() + + /** + * A simple assertion test that verifies whether `value` is truthy. + * If it is not, an `AssertionError` is thrown. + * If provided, the error `message` is formatted using `util.format()` and used as the error message. + * @param value The value tested for being truthy + * @param message The error message + * @param optionalParams The arguments passed to `message` + */ + def assert(value: js.Any, message: String, optionalParams: Any*): Unit = js.native + + /** + * A simple assertion test that verifies whether `value` is truthy. + * If it is not, an `AssertionError` is thrown. + * If provided, the error `message` is formatted using `util.format()` and used as the error message. + * @value The value tested for being truthy + * @param optionalParams The arguments passed to the error message + */ + def assert(value: js.Any, optionalParams: Any*): Unit = js.native + + /** + * When `stdout` is a TTY, calling `console.clear()` will attempt to clear the TTY. + * When `stdout` is not a TTY, this method does nothing. + * + * The specific operation of `console.clear()` can vary across operating systems and terminal types. + * For most Linux operating systems, `console.clear()` operates similarly to the clear shell command. + * On Windows, `console.clear()` will clear only the output in the current terminal viewport for the Node.js binary. + */ + def clear(): Unit = js.native + + /** + * Maintains an internal counter specific to `label` and outputs to `stdout` the number of times `console.count()` has been called with the given `label`. + * @param label The display label for the counter. Default: 'default'. + */ + def count(label: String = js.native): Unit = js.native + + /** + * Resets the internal counter specific to `label`. + * @param label The display label for the counter. Default: 'default'. + */ + def countReset(label: String = js.native): Unit = js.native + + /** + * The `console.debug()` function is an alias for `console.log()`. + * @param message + * @param optionalParams + */ + def debug(message: js.Any, optionalParams: Any*): Unit = js.native + + /** + * Uses [[io.scalajs.nodejs.util.Util.inspect()]] on `obj` and prints the resulting string to `stdout`. + * This function bypasses any custom `inspect()` function defined on `obj`. + */ + def dir(obj: js.Any, options: ConsoleDirOptions = js.native): Unit = js.native + + /** + * This method calls[[log()]] passing it the arguments received. + * Please note that this method does not produce any XML formatting + */ + def dirxml(data: js.Any*): Unit = js.native + + /** + * Prints to `stderr` 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 [[io.scalajs.nodejs.util.Util.format()]]. + * + * If formatting elements (e.g. `%d`) are not found in the first string then[[io.scalajs.nodejs.util.Util.inspect()]] + * 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 + */ + def error(message: js.Any, optionalParams: Any*): Unit = js.native + + /** + * Increases indentation of subsequent lines by two spaces. + * + * If one or more `label`s are provided, those are printed first without the additional indentation. + * + * @param label + */ + def group(label: Any*): Unit = js.native + + /** + * An alias for [[group()]] + * @param label + */ + def groupCollapsed(label: js.Any*): Unit = js.native + + /** + * Decreases indentation of subsequent lines by two spaces. + */ + def groupEnd(): Unit = js.native + + /** + * The `console.info()` function is an alias for [[log()]]. + */ + def info(message: js.Any, optionalParams: js.Any*): 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 + + /** + * Try to construct a table with the columns of the properties of `tabularData` (or use `properties`) and + * rows of `tabularData` and log it. + * Falls back to just logging the argument if it can’t be parsed as tabular. + * @param tabularData + * @param properties Alternate properties for constructing the table. + */ + @enableIf(io.scalajs.nodejs.CompilerSwitches.gteNodeJs10) + def table(tabularData: js.Any, properties: js.Array[String] = js.native): Unit = js.native + + /** + * Starts a timer that can be used to compute the duration of an operation. + * Timers are identified by a unique `label`. + * Use the same `label` when calling [[timeEnd()]] to stop the timer and output the elapsed time in milliseconds to + * `stdout`. + * Timer durations are accurate to the sub-millisecond. + */ + def time(label: String = js.native): Unit = js.native + + /** + * Stops a timer that was previously started by calling [[time()]] and prints the result to `stdout`. + */ + def timeEnd(label: String = js.native): Unit = js.native + + /** + * Stops a timer that was previously started by calling [[time()]] and prints the result to `.stdout`.` + */ + @enableIf(io.scalajs.nodejs.CompilerSwitches.gteNodeJs10) + def timeLog(label: String, data: js.Any*): Unit = js.native + + /** + * 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 + + /** + * The `console.warn()` function is an alias for [[error()] + */ + def warn(message: js.Any, optionalParams: js.Any*): Unit = js.native + + /** + * This method does not display anything unless used in the inspector. + * + * The `console.markTimeline()` method is the deprecated form of [[timeStamp()]]. + * @param label + */ + @deprecated("Use timeStamp instead", "NodeJS 8.0.0") + def markTimeline(label: String = js.native): Unit = js.native + + /** + * This method does not display anything unless used in the inspector. + * The `console.profile()` method starts a JavaScript CPU profile with an optional label until [[profileEnd()]] is called. + * The profile is then added to the **Profile** panel of the inspector. + */ + def profile(label: String = js.native): Unit = js.native + + /** + * This method does not display anything unless used in the inspector. + * Stops the current JavaScript CPU profiling session if one has been started and prints the report to the **Profiles** panel of the inspector. + * See [[profile()]] for an example. + * + * If this method is called without a label, the most recently started profile is stopped. + */ + def profileEnd(label: String = js.native): Unit = js.native + + /** + * This method does not display anything unless used in the inspector. + * The `console.timeStamp()` method adds an event with the label `'label'` to the **Timeline** panel of the inspector. + */ + def timeStamp(label: String = js.native): Unit = js.native + + /** + * This method does not display anything unless used in the inspector. + * The `console.timeline()` method is the deprecated form of [[time()]]. + */ + @deprecated("Use time instead", "NodeJS 8.0.0") + def timeline(label: String = js.native): Unit = js.native + + /** + * This method does not display anything unless used in the inspector. + * The `console.timelineEnd()` method is the deprecated form of [[timeEnd()]]. + */ + @deprecated("Use time instead", "NodeJS 8.0.0") + def timelineEnd(label: String = js.native): Unit = js.native +} + +/** + * A global `Console` instance configured to write to [[io.scalajs.nodejs.process.stdout]] and [[io.scalajs.nodejs.process.stderr]]. + */ +@js.native +@JSGlobal("console") +object Console extends Console diff --git a/app/current/src/main/scala/io/scalajs/nodejs/console_module/ConsoleDirOptions.scala b/app/current/src/main/scala/io/scalajs/nodejs/console_module/ConsoleDirOptions.scala new file mode 100644 index 000000000..a2542a323 --- /dev/null +++ b/app/current/src/main/scala/io/scalajs/nodejs/console_module/ConsoleDirOptions.scala @@ -0,0 +1,17 @@ +package io.scalajs.nodejs.console_module + +import scala.scalajs.js + +/** + * Console Dir Options + * + * @param showHidden if true then the object's non-enumerable and symbol properties will be shown too. Defaults to `false`. + * @param depth tells util.inspect() how many times to recurse while formatting the object. This is useful for + * inspecting large complicated objects. Defaults to `2`. To make it recurse indefinitely, pass null. + * @param colors if true, then the output will be styled with ANSI color codes. Defaults to `false`. Colors are customizable; + * see customizing util.inspect() colors. + */ +class ConsoleDirOptions(var showHidden: js.UndefOr[Boolean] = js.undefined, + var depth: js.UndefOr[Int] = js.undefined, + var colors: js.UndefOr[Boolean] = js.undefined) + extends js.Object diff --git a/app/current/src/main/scala/io/scalajs/nodejs/console_module/ConsoleOptions.scala b/app/current/src/main/scala/io/scalajs/nodejs/console_module/ConsoleOptions.scala new file mode 100644 index 000000000..5d5c8760c --- /dev/null +++ b/app/current/src/main/scala/io/scalajs/nodejs/console_module/ConsoleOptions.scala @@ -0,0 +1,28 @@ +package io.scalajs.nodejs.console_module + +import io.scalajs.nodejs.stream.Writable +import io.scalajs.nodejs.util.InspectOptions + +import scala.scalajs.js +import scala.scalajs.js.| + +/** + * + * @param stdout + * @param stderr + * @param ignoreErrors Ignore errors when writing to the underlying streams. Defaults to `true`. + * @param colorMode Set color support for this `Console` instance. + * Setting to `true` enables coloring while inspecting values, + * setting to `'auto'` will make color support depend on the value of the `isTTY` property and the value returned by `getColorDepth()` on the respective stream. + * This option can not be used, if `inspectOptions.colors` is set as well. Defaults to `'auto'`. + * @param inspectOptions Specifies options that are passed along to [[io.scalajs.nodejs.util.Util.inspect()]]. + * + * **Node:** This is available after Node.js v11.7.0. + */ +class ConsoleOptions( + var stdout: Writable, + var stderr: js.UndefOr[Writable] = js.undefined, + var ignoreErrors: Boolean = true, + var colorMode: Boolean | String = "auto", + var inspectOptions: js.UndefOr[InspectOptions] = js.undefined +) extends js.Object diff --git a/app/current/src/main/scala/io/scalajs/nodejs/console_module/package.scala b/app/current/src/main/scala/io/scalajs/nodejs/console_module/package.scala new file mode 100644 index 000000000..7e6c91617 --- /dev/null +++ b/app/current/src/main/scala/io/scalajs/nodejs/console_module/package.scala @@ -0,0 +1,8 @@ +package nodejs + +/** + * The `console` module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers. + * + * Note: To avoid name conflict with the object [[io.scalajs.nodejs.console]], this package is named `console_module`. + */ +package object console_module {} diff --git a/app/current/src/main/scala/io/scalajs/nodejs/package.scala b/app/current/src/main/scala/io/scalajs/nodejs/package.scala index ffde90678..2957ddadc 100644 --- a/app/current/src/main/scala/io/scalajs/nodejs/package.scala +++ b/app/current/src/main/scala/io/scalajs/nodejs/package.scala @@ -48,13 +48,14 @@ package object nodejs { ///////////////////////////////////////////////////////////////////////////////// // Built-in Properties ///////////////////////////////////////////////////////////////////////////////// + @deprecated("Use console_module.Console. Every module stays each own package.", "0.9.0") + type Console = console_module.Console - /** - * Used to print to stdout and stderr. See the console section. - */ - @js.native - @JSGlobal("console") - object console extends Console(null) + @deprecated("Use console_module.Console. Every module stays each own package.", "0.9.0") + type ConsoleDirOptions = console_module.ConsoleDirOptions + + @deprecated("Use console_module.Console. Every module stays each own package.", "0.9.0") + val console = console_module.Console /** * The directory name of the current module. This the same as the path.dirname() of the [[__filename]]. diff --git a/app/current/src/test/scala/nodejs/ConsoleTest.scala b/app/current/src/test/scala/nodejs/ConsoleTest.scala new file mode 100644 index 000000000..a94714ed8 --- /dev/null +++ b/app/current/src/test/scala/nodejs/ConsoleTest.scala @@ -0,0 +1,63 @@ +package nodejs + +import io.scalajs.nodejs.console_module.{Console, ConsoleOptions} +import io.scalajs.nodejs.fs.Fs +import org.scalatest.{BeforeAndAfterEach, FunSpec} + +import scala.scalajs.js +import scala.scalajs.js.JavaScriptException + +class ConsoleTest extends FunSpec with BeforeAndAfterEach { + + private val logFileName = "x.nodejs8.ConsoleTest" + + override def afterEach(): Unit = { + if (Fs.existsSync(logFileName)) Fs.unlinkSync(logFileName) + } + + describe("NodeJS v10") { + it("have constructor(stdout, stderr, ignoreErrors) added in v8.0.0") { + val failingWritable = Fs.createWriteStream(logFileName) + failingWritable.close(_ => {}) + val looseConsole = new Console( + stdout = failingWritable, + stderr = failingWritable, + ignoreErrors = true + ) + looseConsole.log("ok") + + val strictConsole = new Console( + stdout = failingWritable, + stderr = failingWritable, + ignoreErrors = false + ) + val ex = intercept[JavaScriptException] { + strictConsole.log("ok") + } + assert(ex.getMessage().contains("write after end")) + } + + it("have table added in v10.0.0") { + Console.table(js.Array("x", "y")) + } + + it("have timeLog added in v10.7.0") { + val label = "yay" + Console.time(label) + Console.timeLog(label) + Console.timeEnd(label) + } + + it("have constructor(options) added in v10.0.0") { + val console = new Console( + new ConsoleOptions( + stdout = io.scalajs.nodejs.process.stdout + ) + ) + + val label = "yay" + console.time(label) + console.timeEnd(label) + } + } +} diff --git a/app/current/src/test/scala/nodejs/cluster/ClusterTest.scala b/app/current/src/test/scala/nodejs/cluster/ClusterTest.scala index 567565095..defe25cbc 100644 --- a/app/current/src/test/scala/nodejs/cluster/ClusterTest.scala +++ b/app/current/src/test/scala/nodejs/cluster/ClusterTest.scala @@ -35,7 +35,20 @@ class ClusterTest extends FunSpec { assert(!js.isUndefined(Cluster.settings)) } - it("cluster support fork() new workers") { + // TODO: Update test + // Cluster.fork() behavior changed somewhere between Node v10 and v12. + // TypeError [ERR_INVALID_ARG_TYPE]: The "modulePath" argument must be of type string. Received type undefined + // at validateString (internal/validators.js:107:11) + // at fork (child_process.js:55:3) + // at createWorkerProcess (internal/cluster/master.js:130:10) + // at EventEmitter.cluster.fork (internal/cluster/master.js:164:25) + // at repl:1:9 + // at Script.runInThisContext (vm.js:123:20) + // at REPLServer.defaultEval (repl.js:384:29) + // at bound (domain.js:415:14) + // at REPLServer.runBound [as eval] (domain.js:428:12) + // at REPLServer.onLine (repl.js:700:10) + ignore("cluster support fork() new workers") { if (Cluster.isMaster) { // Fork the workers (1 to 2) map { n =>