diff --git a/app/current/src/main/scala/io/scalajs/nodejs/Process.scala b/app/current/src/main/scala/io/scalajs/nodejs/Process.scala index df5264d8c..f227e9d59 100644 --- a/app/current/src/main/scala/io/scalajs/nodejs/Process.scala +++ b/app/current/src/main/scala/io/scalajs/nodejs/Process.scala @@ -144,7 +144,7 @@ trait Process extends IEventEmitter { * v0.8 allowed for longer process title strings by also overwriting the environ memory but that was * potentially insecure/confusing in some (rather obscure) cases. */ - var title: js.Any = js.native + var title: String = js.native /** * A compiled-in property that exposes NODE_VERSION. diff --git a/app/current/src/test/resources/fileA2.txt b/app/current/src/test/resources/fileA2.txt deleted file mode 100644 index 5e1c309da..000000000 --- a/app/current/src/test/resources/fileA2.txt +++ /dev/null @@ -1 +0,0 @@ -Hello World \ No newline at end of file diff --git a/app/current/src/test/scala/nodejs/buffer/BufferTest.scala b/app/current/src/test/scala/io/scalajs/nodejs/buffer/BufferTest.scala similarity index 93% rename from app/current/src/test/scala/nodejs/buffer/BufferTest.scala rename to app/current/src/test/scala/io/scalajs/nodejs/buffer/BufferTest.scala index fa820bc6f..292110d8f 100644 --- a/app/current/src/test/scala/nodejs/buffer/BufferTest.scala +++ b/app/current/src/test/scala/io/scalajs/nodejs/buffer/BufferTest.scala @@ -1,4 +1,4 @@ -package nodejs.buffer +package io.scalajs.nodejs.buffer import io.scalajs.nodejs.buffer.Buffer import org.scalatest.FunSpec diff --git a/app/nodejs-v10/src/test/scala/nodejs/ConsoleTest.scala b/app/nodejs-v10/src/test/scala/io/scalajs/nodejs/ConsoleTest.scala similarity index 97% rename from app/nodejs-v10/src/test/scala/nodejs/ConsoleTest.scala rename to app/nodejs-v10/src/test/scala/io/scalajs/nodejs/ConsoleTest.scala index b58940d3a..1381d6c30 100644 --- a/app/nodejs-v10/src/test/scala/nodejs/ConsoleTest.scala +++ b/app/nodejs-v10/src/test/scala/io/scalajs/nodejs/ConsoleTest.scala @@ -1,4 +1,4 @@ -package nodejs +package io.scalajs.nodejs import io.scalajs.nodejs.console_module.{Console, ConsoleOptions} import io.scalajs.nodejs.fs.Fs diff --git a/app/nodejs-v10/src/test/scala/nodejs/assertion/AssertTest.scala b/app/nodejs-v10/src/test/scala/io/scalajs/nodejs/assertion/AssertTest.scala similarity index 91% rename from app/nodejs-v10/src/test/scala/nodejs/assertion/AssertTest.scala rename to app/nodejs-v10/src/test/scala/io/scalajs/nodejs/assertion/AssertTest.scala index c8d3d0405..783f74f16 100644 --- a/app/nodejs-v10/src/test/scala/nodejs/assertion/AssertTest.scala +++ b/app/nodejs-v10/src/test/scala/io/scalajs/nodejs/assertion/AssertTest.scala @@ -1,4 +1,4 @@ -package nodejs.assertion +package io.scalajs.nodejs.assertion import org.scalatest.FunSpec import io.scalajs.nodejs.{ Assert => NodeAssert } diff --git a/app/nodejs-v10/src/test/scala/nodejs/crypto/CertificateTest.scala b/app/nodejs-v10/src/test/scala/io/scalajs/nodejs/crypto/CertificateTest.scala similarity index 100% rename from app/nodejs-v10/src/test/scala/nodejs/crypto/CertificateTest.scala rename to app/nodejs-v10/src/test/scala/io/scalajs/nodejs/crypto/CertificateTest.scala diff --git a/app/nodejs-v10/src/test/scala/nodejs/crypto/CryptoTest.scala b/app/nodejs-v10/src/test/scala/io/scalajs/nodejs/crypto/CryptoTest.scala similarity index 100% rename from app/nodejs-v10/src/test/scala/nodejs/crypto/CryptoTest.scala rename to app/nodejs-v10/src/test/scala/io/scalajs/nodejs/crypto/CryptoTest.scala diff --git a/app/nodejs-v10/src/test/scala/nodejs/path/PathTest.scala b/app/nodejs-v10/src/test/scala/io/scalajs/nodejs/path/PathTest.scala similarity index 50% rename from app/nodejs-v10/src/test/scala/nodejs/path/PathTest.scala rename to app/nodejs-v10/src/test/scala/io/scalajs/nodejs/path/PathTest.scala index 57697cca9..79a0baf3c 100644 --- a/app/nodejs-v10/src/test/scala/nodejs/path/PathTest.scala +++ b/app/nodejs-v10/src/test/scala/io/scalajs/nodejs/path/PathTest.scala @@ -6,8 +6,8 @@ import org.scalatest.FunSpec class PathTest extends FunSpec { describe("Path") { it("supports join()") { - assert(Path.win32.toNamespacedPath("c:\\foo\\bar") == "\\\\?\\c:\\foo\\bar") - assert(Path.posix.toNamespacedPath("c:\\foo\\bar") == "c:\\foo\\bar") + assert(Path.win32.toNamespacedPath("c:\\foo\\bar") === "\\\\?\\c:\\foo\\bar") + assert(Path.posix.toNamespacedPath("c:\\foo\\bar") === "c:\\foo\\bar") } } } diff --git a/app/nodejs-v10/src/test/scala/nodejs/util/UtilTest.scala b/app/nodejs-v10/src/test/scala/io/scalajs/nodejs/util/UtilTest.scala similarity index 93% rename from app/nodejs-v10/src/test/scala/nodejs/util/UtilTest.scala rename to app/nodejs-v10/src/test/scala/io/scalajs/nodejs/util/UtilTest.scala index 5591c7d62..f749ebbff 100644 --- a/app/nodejs-v10/src/test/scala/nodejs/util/UtilTest.scala +++ b/app/nodejs-v10/src/test/scala/io/scalajs/nodejs/util/UtilTest.scala @@ -21,7 +21,7 @@ class UtilTest extends FunSpec { } it("have inspect.custom added in v10.12.0") { - assert(Util.inspect.custom != null) + assert(Util.inspect.custom !== null) } } diff --git a/app/nodejs-v8/src/test/scala/nodejs/AssertTest.scala b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/AssertTest.scala similarity index 100% rename from app/nodejs-v8/src/test/scala/nodejs/AssertTest.scala rename to app/nodejs-v8/src/test/scala/io/scalajs/nodejs/AssertTest.scala diff --git a/app/nodejs-v8/src/test/scala/nodejs/ConsoleTest.scala b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/ConsoleTest.scala similarity index 97% rename from app/nodejs-v8/src/test/scala/nodejs/ConsoleTest.scala rename to app/nodejs-v8/src/test/scala/io/scalajs/nodejs/ConsoleTest.scala index fd9ec6482..ae93da754 100644 --- a/app/nodejs-v8/src/test/scala/nodejs/ConsoleTest.scala +++ b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/ConsoleTest.scala @@ -1,4 +1,4 @@ -package nodejs +package io.scalajs.nodejs import io.scalajs.nodejs.console_module.Console import io.scalajs.nodejs.fs.Fs diff --git a/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/ProcessTest.scala b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/ProcessTest.scala new file mode 100644 index 000000000..3b12e316e --- /dev/null +++ b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/ProcessTest.scala @@ -0,0 +1,45 @@ +package io.scalajs.nodejs + +import io.scalajs.nodejs.Process.ProcessEnvExtensions +import io.scalajs.nodejs.os.OS +import org.scalatest.FunSpec + +import scala.scalajs.js + +/** + * Process Tests + */ +class ProcessTest extends FunSpec { + + describe("Process") { + val versionPrefix = + if (TestEnvironment.isExecutedInExactNode8) "v8." + else if (TestEnvironment.isExecutedInExactNode10) "v10." + else if (TestEnvironment.isExecutedInExactNode12) "v12." + else "Unknown node.js version" + + it("contains the following properties") { + assert(process.arch.isInstanceOf[String]) + assert(process.argv.length === 1) + assert(process.argv(0).endsWith("node")) + assert(process.config("variables").asInstanceOf[js.Dictionary[String]]("host_arch") === OS.arch()) + assert(process.connected.isEmpty) + assert(process.cwd().nonEmpty) + assert(process.env("PATH").nonEmpty) + assert(process.env.PATH === process.env("PATH")) + assert(process.execArgv.length === 0) + assert(process.execPath.endsWith("node")) + assert(process.features.contains("debug")) + assert(process.moduleLoadList.length > 0) + assert(process.title.isInstanceOf[String]) + assert(process.version.startsWith(versionPrefix)) + assert(process.versions.node.map(v => s"v${v}").getOrElse("").startsWith(versionPrefix)) + + // TODO: actually undefined in test + // assert(process.stdout.isTTY) + // assert(process.stderr.isTTY) + } + + } + +} diff --git a/app/nodejs-v8/src/test/scala/nodejs/StringDecoderTest.scala b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/StringDecoderTest.scala similarity index 60% rename from app/nodejs-v8/src/test/scala/nodejs/StringDecoderTest.scala rename to app/nodejs-v8/src/test/scala/io/scalajs/nodejs/StringDecoderTest.scala index 002bdbf95..73025d9b6 100644 --- a/app/nodejs-v8/src/test/scala/nodejs/StringDecoderTest.scala +++ b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/StringDecoderTest.scala @@ -3,19 +3,15 @@ package io.scalajs.nodejs import io.scalajs.nodejs.buffer.Buffer import org.scalatest.FunSpec -/** - * StringDecoder Tests - */ class StringDecoderTest extends FunSpec { describe("StringDecoder") { it("should decode strings or buffer") { val decoder = new StringDecoder("utf8") - - info(decoder.write(Buffer.from("Hello "))) - info(decoder.write(Buffer.from("World"))) - info(decoder.end(Buffer.from("!"))) + assert(decoder.write(Buffer.from("Hello ")) === "Hello ") + assert(decoder.write(Buffer.from("World")) === "World") + assert(decoder.end(Buffer.from("!")) === "!") } } diff --git a/app/nodejs-v8/src/test/scala/nodejs/TestEnvironment.scala b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/TestEnvironment.scala similarity index 86% rename from app/nodejs-v8/src/test/scala/nodejs/TestEnvironment.scala rename to app/nodejs-v8/src/test/scala/io/scalajs/nodejs/TestEnvironment.scala index 11b991d8d..091cb88fe 100644 --- a/app/nodejs-v8/src/test/scala/nodejs/TestEnvironment.scala +++ b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/TestEnvironment.scala @@ -1,4 +1,5 @@ -package nodejs +package io.scalajs.nodejs + import io.scalajs.nodejs.buffer.Buffer import io.scalajs.nodejs.child_process.ChildProcess @@ -7,6 +8,8 @@ object TestEnvironment { private lazy val nodeMajorVersion: Int = ChildProcess.execSync("node -v").asInstanceOf[Buffer].toString().drop(1).takeWhile(_.isDigit).toInt + def isWindows: Boolean = os.OS.platform().startsWith("win") + def isExecutedInExactNode12: Boolean = nodeMajorVersion == 12 def isExecutedInExactNode10: Boolean = nodeMajorVersion == 10 def isExecutedInExactNode8: Boolean = nodeMajorVersion == 8 diff --git a/app/nodejs-v8/src/test/scala/nodejs/buffer/BufferTest.scala b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/buffer/BufferTest.scala similarity index 65% rename from app/nodejs-v8/src/test/scala/nodejs/buffer/BufferTest.scala rename to app/nodejs-v8/src/test/scala/io/scalajs/nodejs/buffer/BufferTest.scala index 1254acb77..14e16a648 100644 --- a/app/nodejs-v8/src/test/scala/nodejs/buffer/BufferTest.scala +++ b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/buffer/BufferTest.scala @@ -1,16 +1,11 @@ package io.scalajs.nodejs.buffer -import io.scalajs.collection.Iterator.Entry -import io.scalajs.nodejs.buffer -import nodejs.TestEnvironment +import io.scalajs.nodejs.{TestEnvironment, buffer} import org.scalatest.FunSpec import scala.scalajs.js import scala.scalajs.js.typedarray.{ArrayBuffer, DataView, Uint8Array} -/** - * Buffer Tests - */ class BufferTest extends FunSpec { describe("Buffer") { @@ -20,26 +15,26 @@ class BufferTest extends FunSpec { val buf2 = Buffer.from("BCD") val buf3 = Buffer.from("ABCD") - assert(buf1.compare(buf1) == 0) - assert(buf1.compare(buf2) == -1) - assert(buf1.compare(buf3) == -1) - assert(buf2.compare(buf1) == 1) - assert(buf2.compare(buf3) == 1) + assert(buf1.compare(buf1) === 0) + assert(buf1.compare(buf2) === -1) + assert(buf1.compare(buf3) === -1) + assert(buf2.compare(buf1) === 1) + assert(buf2.compare(buf3) === 1) } - it("should support iterating entries [classic]") { - val buf = Buffer.from("Hello!") - val it = buf.entries() - var result: Entry[js.Any] = null - do { - result = it.next() - if (!result.done) info(s"value: ${result.value}") - } while (!result.done) - } - - it("should support iterating entries [Scala]") { + it("should support iterating entries") { val buf = Buffer.from("Hello!") - for (value <- buf.entries()) info(s"value: $value") + val it = buf.entries() + assert( + it.toSeq.map(_.toSeq) === Seq( + Seq(0, 72), + Seq(1, 101), + Seq(2, 108), + Seq(3, 108), + Seq(4, 111), + Seq(5, 33) + ) + ) } it("should support buffer property") { @@ -52,21 +47,21 @@ class BufferTest extends FunSpec { import scala.scalajs.js.typedarray.Int8Array val nodeBuffer = Buffer.from(js.Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)) val typedarray = new Int8Array(nodeBuffer.buffer, nodeBuffer.byteOffset, nodeBuffer.length) - assert(typedarray.mkString == new Int8Array(js.Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)).mkString) + assert(typedarray.mkString === new Int8Array(js.Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)).mkString) } it("should support byteLength for specific types") { - assert(Buffer.byteLength("\u00bd + \u00bc = \u00be") == 12) - assert(Buffer.byteLength("\u00bd + \u00bc = \u00be", "utf8") == 12) - assert(Buffer.byteLength(Buffer.alloc(12)) == 12) - assert(Buffer.byteLength(new Uint8Array(12)) == 12) - assert(Buffer.byteLength(new DataView(new ArrayBuffer(12))) == 12) - assert(Buffer.byteLength(new ArrayBuffer(12)) == 12) + assert(Buffer.byteLength("\u00bd + \u00bc = \u00be") === 12) + assert(Buffer.byteLength("\u00bd + \u00bc = \u00be", "utf8") === 12) + assert(Buffer.byteLength(Buffer.alloc(12)) === 12) + assert(Buffer.byteLength(new Uint8Array(12)) === 12) + assert(Buffer.byteLength(new DataView(new ArrayBuffer(12))) === 12) + assert(Buffer.byteLength(new ArrayBuffer(12)) === 12) } it("should support fill") { val otherBuf = Buffer.from("abcdef") - assert(Buffer.alloc(10).fill(otherBuf).toString() == "abcdefabcd") + assert(Buffer.alloc(10).fill(otherBuf).toString() === "abcdefabcd") } } @@ -77,34 +72,30 @@ class BufferTest extends FunSpec { it("should create buffers from strings") { val bufA = Buffer.from("Hello ") - info(s"bufA => ${bufA.toString()}") val bufB = Buffer.from("World") - info(s"bufB => ${bufB.toString()}") val bufC = bufA + bufB - info(s"bufC => ${bufC.toString()}, length = ${bufC.byteLength()}") - assert(bufA.toString() == "Hello ") - assert(bufB.toString() == "World") - assert(bufC.byteLength() == 11) + assert(bufA.toString() === "Hello ") + assert(bufB.toString() === "World") + assert(bufC.byteLength === 11) } it("should create buffers from buffers") { val buffer = Buffer.from("hello") - assert(Buffer.from(buffer).toString() == "hello") + assert(Buffer.from(buffer).toString() === "hello") - // TODO: when Scala.js added TypedArray.from - // val uints = Uint8Array.from(???) - // assert(Buffer.from(uints).toString() == "worlds") + val uints = Uint8Array.from(js.Array(72, 101, 108, 108, 111)) + assert(Buffer.from(uints).toString() === "Hello") } it("should support concat") { val buffers = js.Array(Buffer.from("abc"), Buffer.from("def"), Buffer.from("ghijk")) - assert(Buffer.compare(Buffer.concat(buffers), Buffer.from("abcdefghijk")) == 0) - assert(Buffer.compare(Buffer.concat(buffers, 5), Buffer.from("abcde")) == 0) + assert(Buffer.compare(Buffer.concat(buffers), Buffer.from("abcdefghijk")) === 0) + assert(Buffer.compare(Buffer.concat(buffers, 5), Buffer.from("abcde")) === 0) val uints: js.Array[Uint8Array] = js.Array(Buffer.from("abc"), Buffer.from("def"), Buffer.from("ghijk")) - assert(Buffer.compare(Buffer.concat(uints), Buffer.from("abcdefghijk")) == 0) - assert(Buffer.compare(Buffer.concat(uints, 5), Buffer.from("abcde")) == 0) + assert(Buffer.compare(Buffer.concat(uints), Buffer.from("abcdefghijk")) === 0) + assert(Buffer.compare(Buffer.concat(uints, 5), Buffer.from("abcde")) === 0) } it("should support isBufrer") { @@ -130,12 +121,12 @@ class BufferTest extends FunSpec { describe("module members") { it("should support transcode") { // package object method - assert(buffer.transcode(Buffer.from("hello"), "utf8", "ascii").toString("ascii") == "hello") - assert(buffer.transcode(Buffer.from("€"), "utf8", "ascii").toString("ascii") == "?") + assert(buffer.transcode(Buffer.from("hello"), "utf8", "ascii").toString("ascii") === "hello") + assert(buffer.transcode(Buffer.from("€"), "utf8", "ascii").toString("ascii") === "?") // extension method - assert(Buffer.transcode(Buffer.from("hello"), "utf8", "ascii").toString("ascii") == "hello") - assert(Buffer.transcode(Buffer.from("€"), "utf8", "ascii").toString("ascii") == "?") + assert(Buffer.transcode(Buffer.from("hello"), "utf8", "ascii").toString("ascii") === "hello") + assert(Buffer.transcode(Buffer.from("€"), "utf8", "ascii").toString("ascii") === "?") } it("should support fields") { diff --git a/app/nodejs-v8/src/test/scala/nodejs/child_process/ChildProcessTest.scala b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/child_process/ChildProcessTest.scala similarity index 57% rename from app/nodejs-v8/src/test/scala/nodejs/child_process/ChildProcessTest.scala rename to app/nodejs-v8/src/test/scala/io/scalajs/nodejs/child_process/ChildProcessTest.scala index 0eee0f2b4..3008a3ddc 100644 --- a/app/nodejs-v8/src/test/scala/nodejs/child_process/ChildProcessTest.scala +++ b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/child_process/ChildProcessTest.scala @@ -1,11 +1,11 @@ package io.scalajs.nodejs package child_process -import io.scalajs.nodejs.Error import io.scalajs.nodejs.buffer.Buffer import io.scalajs.util.ScalaJsHelper._ -import org.scalatest.FunSpec +import org.scalatest.AsyncFunSpec +import scala.concurrent.{ExecutionContext, Promise} import scala.scalajs.js import scala.scalajs.js.| @@ -13,34 +13,57 @@ import scala.scalajs.js.| * ChildProcess Test * */ -class ChildProcessTest extends FunSpec { +class ChildProcessTest extends AsyncFunSpec { + override implicit val executionContext = ExecutionContext.Implicits.global + + describe("Extension") { + it("supports execFuture(...)") { + for { + r <- ChildProcess.execFuture("cat ./package.json | wc -l") + } yield { + assert(r._1.asInstanceOf[Buffer].toString().trim.toInt > 0) + } + } + } describe("ChildProcess") { it("supports exec(...)") { + val promise = Promise[(Output, Output)]() ChildProcess.exec( "cat ./package.json | wc -l", - callback = (error: Error, stdout: Buffer | String, stderr: Buffer | String) => { + callback = (error: Error, stdout: Output, stderr: Output) => { if (isDefined(error)) { - console.error(s"exec error: $error") + promise.failure(error) + } else { + promise.success((stdout, stderr)) } - info(s"stdout: $stdout") - info(s"stderr: $stderr") } ) + promise.future.map { + case (stdout, stderr) => + assert(stdout.toString.trim.toInt === 19) + assert(stderr.toString.trim === "") + } } it("supports execFile(...)") { + val promise = Promise[(Output, Output)]() ChildProcess.execFile( "ls", js.Array("-l"), - callback = (error: Error, stdout: Buffer | String, stderr: Buffer | String) => { + callback = (error: Error, stdout: Output, stderr: Output) => { if (isDefined(error)) { - console.error(s"exec error: $error") + promise.failure(error) + } else { + promise.success((stdout, stderr)) } - info(s"stdout: $stdout") - info(s"stderr: $stderr") } ) + promise.future.map { + case (stdout, stderr) => + assert(stdout.toString.trim.linesIterator.length > 10) + assert(stderr.toString.trim === "") + } } it("supports execSync(...)") { diff --git a/app/nodejs-v8/src/test/scala/nodejs/cluster/ClusterTest.scala b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/cluster/ClusterTest.scala similarity index 87% rename from app/nodejs-v8/src/test/scala/nodejs/cluster/ClusterTest.scala rename to app/nodejs-v8/src/test/scala/io/scalajs/nodejs/cluster/ClusterTest.scala index defe25cbc..a0aab4fcb 100644 --- a/app/nodejs-v8/src/test/scala/nodejs/cluster/ClusterTest.scala +++ b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/cluster/ClusterTest.scala @@ -8,30 +8,23 @@ import org.scalatest.FunSpec import scala.concurrent.duration._ import scala.scalajs.js -/** - * Cluster Tests - */ class ClusterTest extends FunSpec { describe("Cluster") { it("cluster should be master") { - info(s"cluster.isMaster => ${Cluster.isMaster}") assert(Cluster.isMaster) } it("cluster should not be a worker") { - info(s"cluster.isWorker => ${Cluster.isWorker}") assert(!Cluster.isWorker) } it("cluster.schedulingPolicy must be defined") { - info(s"cluster.schedulingPolicy => ${Cluster.schedulingPolicy}") assert(!js.isUndefined(Cluster.schedulingPolicy)) } it("cluster.settings must be defined") { - info(s"cluster.settings => ${JSON.stringify(Cluster.settings)}") assert(!js.isUndefined(Cluster.settings)) } diff --git a/app/nodejs-v8/src/test/scala/nodejs/crypto/CertificateTest.scala b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/crypto/CertificateTest.scala similarity index 100% rename from app/nodejs-v8/src/test/scala/nodejs/crypto/CertificateTest.scala rename to app/nodejs-v8/src/test/scala/io/scalajs/nodejs/crypto/CertificateTest.scala diff --git a/app/nodejs-v8/src/test/scala/nodejs/crypto/CryptoTest.scala b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/crypto/CryptoTest.scala similarity index 93% rename from app/nodejs-v8/src/test/scala/nodejs/crypto/CryptoTest.scala rename to app/nodejs-v8/src/test/scala/io/scalajs/nodejs/crypto/CryptoTest.scala index a8d492b03..9aec1d0d2 100644 --- a/app/nodejs-v8/src/test/scala/nodejs/crypto/CryptoTest.scala +++ b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/crypto/CryptoTest.scala @@ -15,14 +15,14 @@ class CryptoTest extends FunSpec with MustMatchers { val hasher = Crypto.createHash("md5") hasher.update(text) val buffer = hasher.digest() - assert(buffer.toHexString == "b10a8db164e0754105b7a99be72e3fe5") + assert(buffer.toHexString === "b10a8db164e0754105b7a99be72e3fe5") } it("should be able to create a SHA256 hash from a string") { val hasher = Crypto.createHash("sha256") hasher.update(text) val buffer = hasher.digest() - assert(buffer.toHexString == "a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e") + assert(buffer.toHexString === "a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e") } it("should be able to hash passwords with pbkdf2Sync") { diff --git a/app/nodejs-v8/src/test/scala/nodejs/dns/DNSAsyncTest.scala b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/dns/DNSAsyncTest.scala similarity index 55% rename from app/nodejs-v8/src/test/scala/nodejs/dns/DNSAsyncTest.scala rename to app/nodejs-v8/src/test/scala/io/scalajs/nodejs/dns/DNSAsyncTest.scala index 0701af2bf..94705cd6e 100644 --- a/app/nodejs-v8/src/test/scala/nodejs/dns/DNSAsyncTest.scala +++ b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/dns/DNSAsyncTest.scala @@ -3,17 +3,57 @@ package dns import org.scalatest.AsyncFunSpec -import scala.concurrent.ExecutionContext +import scala.concurrent.{ExecutionContext, Promise} import scala.scalajs.js -/** - * DNS Tests - */ class DNSAsyncTest extends AsyncFunSpec { - private val domain = "google.com" override implicit val executionContext = ExecutionContext.Implicits.global + private val domain = "google.com" + describe("DNS") { + + it("supports lookup") { + val promise = Promise[String]() + DNS.lookup(domain, (err, ipAddress) => { + assert(err === null) + promise.success(ipAddress) + }) + promise.future.map { ipAddress => + assert(ipAddress.nonEmpty) + } + } + + it("supports lookupService:SSH") { + val promise = Promise[(String, String)]() + DNS.lookupService("127.0.0.1", 22, (err, hostname, service) => { + assert(err === null) + promise.success((hostname, service)) + }) + promise.future.map { + case (host, service) => + assert(host === "localhost") + assert(service === "ssh") + } + } + + it("supports resolve:NS") { + val promise = Promise[js.Array[String]]() + DNS.resolve( + domain, + "NS", + (err: DnsError, addresses: ResolveResult) => { + assert(err === null) + promise.success(addresses.asInstanceOf[js.Array[String]]) + } + ) + promise.future.map { addresses => + assert(addresses.nonEmpty) + } + } + } + + describe("DNS future extension") { it("supports lookupFuture") { DNS.lookupFuture(domain) map { case (ipAddress, ttl) => diff --git a/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/events/EventEmitterTest.scala b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/events/EventEmitterTest.scala new file mode 100644 index 000000000..63137ceb6 --- /dev/null +++ b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/events/EventEmitterTest.scala @@ -0,0 +1,69 @@ +package io.scalajs.nodejs.events + +import org.scalatest.AsyncFunSpec + +import scala.concurrent.{ExecutionContext, Promise} +import scala.scalajs.js + +class EventEmitterTest extends AsyncFunSpec { + override implicit val executionContext = ExecutionContext.Implicits.global + + describe("EventEmitter") { + + it("should handle custom events with arguments") { + val promise = Promise[js.Array[Int]]() + val myEmitter = new EventEmitter() + myEmitter.on("custom-event", (args: js.Array[Int]) => { + promise.success(args) + }) + myEmitter.emit("custom-event", js.Array(1, 2, 3)) + + promise.future.map { array => + assert(array.mkString(",") === "1,2,3") + } + } + + it("should handle one-time events") { + val promise = Promise[Unit]() + val myEmitter = new EventEmitter() + var n = 0 + myEmitter.once("event", () => { + n += 1 + promise.success(()) + }) + myEmitter.emit("event") + myEmitter.emit("event") + + promise.future.map { _ => + assert(n === 1) + } + } + + it("should handle repeated events") { + val promise = Promise[Unit]() + val myEmitter = new EventEmitter() + var n = 0 + myEmitter + .on("event", () => { + n += 1 + }) + .on("end", () => { + promise.success(()) + }) + myEmitter.emit("event") + myEmitter.emit("event") + myEmitter.emit("end") + + promise.future.map { _ => + assert(n === 2) + } + } + + it("should count the number of fired events") { + val myEmitter = new EventEmitter() + myEmitter.on("event", () => {}) + myEmitter.on("event", () => {}) + assert(myEmitter.listenerCount("event") === 2) + } + } +} diff --git a/app/nodejs-v8/src/test/scala/nodejs/fs/FsAsyncTest.scala b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/fs/FsAsyncTest.scala similarity index 93% rename from app/nodejs-v8/src/test/scala/nodejs/fs/FsAsyncTest.scala rename to app/nodejs-v8/src/test/scala/io/scalajs/nodejs/fs/FsAsyncTest.scala index 4ef9a6522..4366f920c 100644 --- a/app/nodejs-v8/src/test/scala/nodejs/fs/FsAsyncTest.scala +++ b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/fs/FsAsyncTest.scala @@ -26,7 +26,7 @@ class FsAsyncTest extends AsyncFunSpec with BeforeAndAfterEach { existsAfterUnlink <- Fs.existsFuture(file) } yield { assert(exists) - assert(readBuffer.asInstanceOf[Buffer].toString() == "content") + assert(readBuffer.asInstanceOf[Buffer].toString() === "content") assert(!existsAfterUnlink) } } diff --git a/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/fs/FsTest.scala b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/fs/FsTest.scala new file mode 100644 index 000000000..3df110f67 --- /dev/null +++ b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/fs/FsTest.scala @@ -0,0 +1,117 @@ +package io.scalajs.nodejs.fs + +import io.scalajs.nodejs.setImmediate +import io.scalajs.util.ScalaJsHelper._ +import org.scalatest.AsyncFunSpec + +import scala.concurrent.{ExecutionContext, Promise} + +/** + * File System (Fs) Tests + * + */ +class FsTest extends AsyncFunSpec { + override implicit val executionContext = ExecutionContext.Implicits.global + + final val testResources = "./app/current/src/test/resources/" + + describe("Fs") { + + it("supports watching files") { + val promise = Promise[(String, String)]() + val watcher = Fs.watch(s"${testResources}", (eventType, file) => { + if (!promise.isCompleted) { + promise.success((eventType, file)) + } + }) + assert(watcher !== null) + + setImmediate( + () => + Fs.writeFile(s"${testResources}1.txt", "Hello", error => { + if (isDefined(error)) { + promise.failure(error) + } + }) + ) + + promise.future.map { + case (eventType, file) => + assert(eventType === "change") + assert(file === "1.txt") + } + } + + it("should stream data") { + val promise1 = Promise[(Stats, Stats)]() + val promise2 = Promise[Stats]() + val promise3 = Promise[Boolean]() + + val file1 = s"${testResources}fileA1.txt" + val file2 = s"${testResources}fileA2.txt" + val file3 = s"${testResources}fileC2.txt" + + val readable = Fs.createReadStream(file1, new FileInputOptions(encoding = "utf8")) + val writable = Fs.createWriteStream(file2) + readable.onData[String](chunk => { + writable.end(chunk) + }) + Fs.writeFileSync(file1, "Hello World") + + writable.onFinish { () => + promise1.success((Fs.statSync(file1), Fs.statSync(file2))) + + Fs.renameSync(file2, file3) + promise2.success(Fs.statSync(file3)) + + Fs.unlinkSync(file3) + promise3.success(!Fs.existsSync(file3)) + } + + for { + (stat1, stat2) <- promise1.future + stat3 <- promise2.future + deleted <- promise3.future + } yield { + assert(stat1.size === stat2.size) + assert(stat3.isFile()) + assert(deleted) + } + } + + it("should pipe data from a Readable to a Writable") { + val file1 = s"${testResources}fileB1.txt" + val file2 = s"${testResources}fileB2.txt" + + val readable = Fs.createReadStream(file1) + val writable = Fs.createWriteStream(file2) + readable.pipe(writable) + + val promise = Promise[(Stats, Stats)]() + writable.onFinish { () => + promise.success((Fs.statSync(file1), Fs.statSync(file2))) + } + + promise.future.map { + case (stat1, stat2) => + assert(stat1.size === stat2.size) + } + } + + it("support access") { + val promise = Promise[Unit]() + Fs.access("./package.json", err => { + if (isDefined(err)) { + promise.failure(err) + } else { + promise.success(()) + } + }) + promise.future.map { _ => + succeed + } + } + + } + +} diff --git a/app/nodejs-v8/src/test/scala/nodejs/fs/ReadStreamTest.scala b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/fs/ReadStreamTest.scala similarity index 64% rename from app/nodejs-v8/src/test/scala/nodejs/fs/ReadStreamTest.scala rename to app/nodejs-v8/src/test/scala/io/scalajs/nodejs/fs/ReadStreamTest.scala index 619206cc8..c3fadfdaf 100644 --- a/app/nodejs-v8/src/test/scala/nodejs/fs/ReadStreamTest.scala +++ b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/fs/ReadStreamTest.scala @@ -12,17 +12,17 @@ class FsClassesTest extends FunSpec { describe("ReadStream") { it("supports constructor(") { - assert(new ReadStream("package.json") != null) - assert(new ReadStream(Buffer.from("package.json")) != null) - assert(new ReadStream(new URL(s"file:///${dirname}/package.json")) != null) + assert(new ReadStream("package.json") !== null) + assert(new ReadStream(Buffer.from("package.json")) !== null) + assert(new ReadStream(new URL(s"file:///${dirname}/package.json")) !== null) } } describe("WriteStream") { it("supports constructor") { - assert(new WriteStream("package.json") != null) - assert(new WriteStream(Buffer.from("package.json")) != null) - assert(new WriteStream(new URL(s"file:///${dirname}/package.json")) != null) + assert(new WriteStream("package.json") !== null) + assert(new WriteStream(Buffer.from("package.json")) !== null) + assert(new WriteStream(new URL(s"file:///${dirname}/package.json")) !== null) } } diff --git a/app/nodejs-v8/src/test/scala/nodejs/http/HttpTest.scala b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/http/HttpTest.scala similarity index 95% rename from app/nodejs-v8/src/test/scala/nodejs/http/HttpTest.scala rename to app/nodejs-v8/src/test/scala/io/scalajs/nodejs/http/HttpTest.scala index 1678e1c24..1dc7efbd8 100644 --- a/app/nodejs-v8/src/test/scala/nodejs/http/HttpTest.scala +++ b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/http/HttpTest.scala @@ -19,7 +19,7 @@ class HttpTest extends FunSpec { response.write("Hello World") response.end() }) - assert(server != null) + assert(server !== null) // don't listen on a port //server.listen(58888) diff --git a/app/nodejs-v8/src/test/scala/nodejs/net/NetTest.scala b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/net/NetTest.scala similarity index 100% rename from app/nodejs-v8/src/test/scala/nodejs/net/NetTest.scala rename to app/nodejs-v8/src/test/scala/io/scalajs/nodejs/net/NetTest.scala diff --git a/app/nodejs-v8/src/test/scala/nodejs/os/OSTest.scala b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/os/OSTest.scala similarity index 100% rename from app/nodejs-v8/src/test/scala/nodejs/os/OSTest.scala rename to app/nodejs-v8/src/test/scala/io/scalajs/nodejs/os/OSTest.scala diff --git a/app/nodejs-v8/src/test/scala/nodejs/path/PathTest.scala b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/path/PathTest.scala similarity index 63% rename from app/nodejs-v8/src/test/scala/nodejs/path/PathTest.scala rename to app/nodejs-v8/src/test/scala/io/scalajs/nodejs/path/PathTest.scala index 744a46042..baf0cfbd8 100644 --- a/app/nodejs-v8/src/test/scala/nodejs/path/PathTest.scala +++ b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/path/PathTest.scala @@ -10,22 +10,22 @@ class PathTest extends FunSpec { describe("Path") { it("supports basename()") { - assert(Path.basename("/foo/bar/baz/asdf/quux.html") == "quux.html") - assert(Path.basename("/foo/bar/baz/asdf/quux.html", ".html") == "quux") + assert(Path.basename("/foo/bar/baz/asdf/quux.html") === "quux.html") + assert(Path.basename("/foo/bar/baz/asdf/quux.html", ".html") === "quux") } it("supports posix.basename()") { - assert(Path.posix.basename("C:\\temp\\data.txt") == "C:\\temp\\data.txt") - assert(Path.posix.basename("/temp/data.txt") == "data.txt") + assert(Path.posix.basename("C:\\temp\\data.txt") === "C:\\temp\\data.txt") + assert(Path.posix.basename("/temp/data.txt") === "data.txt") } it("supports win32.basename()") { - assert(Path.win32.basename("C:\\temp\\data.txt") == "data.txt") - assert(Path.win32.basename("/temp/data.txt") == "data.txt") + assert(Path.win32.basename("C:\\temp\\data.txt") === "data.txt") + assert(Path.win32.basename("/temp/data.txt") === "data.txt") } it("supports format()") { - assert(Path.format(new PathObject(root = "/", base = "file.txt")) == "/file.txt") + assert(Path.format(new PathObject(root = "/", base = "file.txt")) === "/file.txt") } it("supports isAbsolute()") { @@ -36,7 +36,7 @@ class PathTest extends FunSpec { } it("supports join()") { - assert(Path.join("/foo", "bar", "baz/asdf", "quux", "..") == "/foo/bar/baz/asdf") + assert(Path.join("/foo", "bar", "baz/asdf", "quux", "..") === "/foo/bar/baz/asdf") } } diff --git a/app/nodejs-v8/src/test/scala/nodejs/querystring/QueryStringTest.scala b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/querystring/QueryStringTest.scala similarity index 100% rename from app/nodejs-v8/src/test/scala/nodejs/querystring/QueryStringTest.scala rename to app/nodejs-v8/src/test/scala/io/scalajs/nodejs/querystring/QueryStringTest.scala diff --git a/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/readline/ReadlineTest.scala b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/readline/ReadlineTest.scala new file mode 100644 index 000000000..0a9134b4a --- /dev/null +++ b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/readline/ReadlineTest.scala @@ -0,0 +1,54 @@ +package io.scalajs.nodejs.readline + +import io.scalajs.nodejs.fs.Fs +import io.scalajs.nodejs.process +import org.scalatest.AsyncFunSpec + +import scala.concurrent.{ExecutionContext, Promise} + +/** + * Readline Tests + */ +class ReadlineTest extends AsyncFunSpec { + override implicit val executionContext = ExecutionContext.Implicits.global + + describe("Readline") { + + it("should read/stream files from disk") { + val promise = Promise[Unit]() + var lineNo = 0 + val file = "./package.json" + val reader = Readline.createInterface( + new ReadlineOptions( + input = Fs.createReadStream(file), + output = process.stdout, + terminal = false + ) + ) + + reader.onLine { line => + lineNo += 1 + } + + reader.onClose { () => + promise.success(()) + } + promise.future.map(_ => assert(lineNo === 19)) + } + + it("has REPL-like functionality") { + val promise = Promise[Unit]() + val rl = Readline.createInterface(new ReadlineOptions(input = process.stdin, output = process.stdout)) + rl.setPrompt("OHAI> ") + rl.prompt() + + rl.onClose { () => + promise.success(()) + } + rl.close() + promise.future.map(_ => succeed) + } + + } + +} diff --git a/app/nodejs-v8/src/test/scala/nodejs/tty/TTYTest.scala b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/tty/TTYTest.scala similarity index 100% rename from app/nodejs-v8/src/test/scala/nodejs/tty/TTYTest.scala rename to app/nodejs-v8/src/test/scala/io/scalajs/nodejs/tty/TTYTest.scala diff --git a/app/nodejs-v8/src/test/scala/nodejs/url/URLObjectTest.scala b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/url/URLObjectTest.scala similarity index 62% rename from app/nodejs-v8/src/test/scala/nodejs/url/URLObjectTest.scala rename to app/nodejs-v8/src/test/scala/io/scalajs/nodejs/url/URLObjectTest.scala index e8d173715..d459947b9 100644 --- a/app/nodejs-v8/src/test/scala/nodejs/url/URLObjectTest.scala +++ b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/url/URLObjectTest.scala @@ -17,7 +17,7 @@ class URLObjectTest extends FunSpec { it("should break down URLs into components") { assert( - urlObject.toJson == """{"protocol":"https:","slashes":true,"auth":null,"host":"www.google.com","port":null,"hostname":"www.google.com","hash":"#q=node","search":"?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8","query":"sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8","pathname":"/webhp","path":"/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8","href":"https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=node"}""" + urlObject.toJson === """{"protocol":"https:","slashes":true,"auth":null,"host":"www.google.com","port":null,"hostname":"www.google.com","hash":"#q=node","search":"?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8","query":"sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8","pathname":"/webhp","path":"/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8","href":"https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=node"}""" ) } @@ -30,7 +30,7 @@ class URLObjectTest extends FunSpec { } it("should reconstituted the URL to match the original") { - assert(URL.format(urlObject) == originalUrl) + assert(URL.format(urlObject) === originalUrl) } } diff --git a/app/nodejs-v8/src/test/scala/nodejs/url/URLSearchParamsTest.scala b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/url/URLSearchParamsTest.scala similarity index 61% rename from app/nodejs-v8/src/test/scala/nodejs/url/URLSearchParamsTest.scala rename to app/nodejs-v8/src/test/scala/io/scalajs/nodejs/url/URLSearchParamsTest.scala index 195f3f90f..9614d2d6d 100644 --- a/app/nodejs-v8/src/test/scala/nodejs/url/URLSearchParamsTest.scala +++ b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/url/URLSearchParamsTest.scala @@ -1,24 +1,17 @@ package io.scalajs.nodejs.url -import io.scalajs.nodejs.console import org.scalatest.FunSpec import scala.scalajs.js -/** - * URLSearchParams Tests - */ class URLSearchParamsTest extends FunSpec { describe("URLSearchParams") { it("should parse the string as a query string") { val params = new URLSearchParams("user=abc&query=xyz") - info(params.get("user")) // Prints "abc" - assert(params.get("user") == "abc") - - info(params.toString) // Prints "user=abc&query=xyz" - assert(params.toString == "user=abc&query=xyz") + assert(params.get("user") === "abc") + assert(params.toString === "user=abc&query=xyz") } it("should parse the dictionary/object as a query string") { @@ -28,15 +21,18 @@ class URLSearchParamsTest extends FunSpec { "query" -> js.Array("first", "second") ) ) - info(params.getAll("query").mkString(", ")) // Prints [ "first,second" ] - assert(params.getAll("query").toSeq == Seq("first,second")) + assert(params.getAll("query").toSeq === Seq("first,second")) } it("should iterates over each name-value pair in the query and invokes the given function") { val myURL = new URL("https://example.org/?a=b&c=d") + val array = js.Array[String]() myURL.searchParams.forEach((value, name, searchParams) => { - console.log(name, value, myURL.searchParams === searchParams) + array.push(s"${name}=${value}") + assert(myURL.searchParams === searchParams) }) + assert(array(0) === "a=b") + assert(array(1) === "c=d") } } diff --git a/app/nodejs-v8/src/test/scala/nodejs/url/URLTest.scala b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/url/URLTest.scala similarity index 73% rename from app/nodejs-v8/src/test/scala/nodejs/url/URLTest.scala rename to app/nodejs-v8/src/test/scala/io/scalajs/nodejs/url/URLTest.scala index 8e7cf0c29..58b643753 100644 --- a/app/nodejs-v8/src/test/scala/nodejs/url/URLTest.scala +++ b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/url/URLTest.scala @@ -3,19 +3,16 @@ package url import org.scalatest._ -/** - * URL Tests - */ class URLTest extends FunSpec { describe("URL") { it("Gets and sets the serialized query portion of the URL") { val myURL = new URL("https://example.org/abc?123") - info(myURL.search) // Prints ?123 + assert(myURL.search === "?123") myURL.search = "abc=xyz" - info(myURL.href) + assert(myURL.href === "https://example.org/abc?abc=xyz") } } diff --git a/app/nodejs-v8/src/test/scala/nodejs/util/UtilTest.scala b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/util/UtilTest.scala similarity index 70% rename from app/nodejs-v8/src/test/scala/nodejs/util/UtilTest.scala rename to app/nodejs-v8/src/test/scala/io/scalajs/nodejs/util/UtilTest.scala index afee3aa72..840b0de80 100644 --- a/app/nodejs-v8/src/test/scala/nodejs/util/UtilTest.scala +++ b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/util/UtilTest.scala @@ -5,13 +5,13 @@ import org.scalatest.FunSpec class UtilTest extends FunSpec { it("have inspect object") { - assert(Util.inspect != null) - assert(Util.inspect.defaultOptions != null) - assert(Util.inspect.styles != null) + assert(Util.inspect !== null) + assert(Util.inspect.defaultOptions !== null) + assert(Util.inspect.styles !== null) } it("have promisify") { - assert(Util.promisify.custom != null) + assert(Util.promisify.custom !== null) } it("have TextEncoder/TextDecoder") { diff --git a/app/nodejs-v8/src/test/scala/nodejs/vm/VMTest.scala b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/vm/VMTest.scala similarity index 90% rename from app/nodejs-v8/src/test/scala/nodejs/vm/VMTest.scala rename to app/nodejs-v8/src/test/scala/io/scalajs/nodejs/vm/VMTest.scala index 6dd86b567..c49286877 100644 --- a/app/nodejs-v8/src/test/scala/nodejs/vm/VMTest.scala +++ b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/vm/VMTest.scala @@ -32,14 +32,14 @@ class VMTest extends FunSpec { expectedSet foreach { case ExpectedData(animal, count, name) => script.runInContext(context) - assert(sandbox.animal == animal && sandbox.count == count && sandbox.name == name) + assert(sandbox.animal === animal && sandbox.count === count && sandbox.name === name) } } it("should compile and execute JavaScript code in a custom context") { val sandbox = new Sandbox(animal = "cat", count = 2, name = "kitty") VM.runInNewContext("""count += 1; name = "kitty"""", sandbox) - assert(sandbox.animal == "cat" && sandbox.count == 3 && sandbox.name == "kitty") + assert(sandbox.animal === "cat" && sandbox.count === 3 && sandbox.name === "kitty") } } diff --git a/app/nodejs-v8/src/test/scala/nodejs/zlib/ZlibTest.scala b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/zlib/ZlibTest.scala similarity index 73% rename from app/nodejs-v8/src/test/scala/nodejs/zlib/ZlibTest.scala rename to app/nodejs-v8/src/test/scala/io/scalajs/nodejs/zlib/ZlibTest.scala index 95baa64b6..b9fc8c4d3 100644 --- a/app/nodejs-v8/src/test/scala/nodejs/zlib/ZlibTest.scala +++ b/app/nodejs-v8/src/test/scala/io/scalajs/nodejs/zlib/ZlibTest.scala @@ -5,9 +5,6 @@ import org.scalatest.FunSpec import scala.scalajs.concurrent.JSExecutionContext.Implicits.queue -/** - * Zlib Tests - */ class ZlibTest extends FunSpec { describe("Zlib") { @@ -19,9 +16,7 @@ class ZlibTest extends FunSpec { compressed <- Zlib.deflateFuture(original) uncompressed <- Zlib.unzipFuture(compressed, new CompressionOptions(finishFlush = Zlib.Z_SYNC_FLUSH)) } { - info(s"compressed => ${compressed.toString()}") - info(s"uncompressed => ${uncompressed.toString()}") - assert(original.compare(uncompressed) == 0) + assert(original.compare(uncompressed) === 0) } } } diff --git a/app/nodejs-v8/src/test/scala/nodejs/ProcessTest.scala b/app/nodejs-v8/src/test/scala/nodejs/ProcessTest.scala deleted file mode 100644 index 7c98f8561..000000000 --- a/app/nodejs-v8/src/test/scala/nodejs/ProcessTest.scala +++ /dev/null @@ -1,41 +0,0 @@ -package io.scalajs.nodejs - -import io.scalajs.JSON -import io.scalajs.nodejs.Process.ProcessEnvExtensions -import org.scalatest.FunSpec - -import scala.scalajs.js - -/** - * Process Tests - */ -class ProcessTest extends FunSpec { - - describe("Process") { - - it("contains the following properties") { - show("process.arch", process.arch) - show("process.argv", process.argv) - show("process.config", process.config) - show("process.connected", process.connected) - show("process.cwd()", process.cwd()) - show("process.domain", process.domain) - show("process.env", process.env) - show("process.env.NODE_ENV", process.env.NODE_ENV) - show("process.env.PATH", process.env.PATH) - show("process.execArgv", process.execArgv) - show("process.execPath", process.execPath) - show("process.features", process.features) - show("process.moduleLoadList", process.moduleLoadList) - show("process.title", process.title) - show("process.version", process.version) - show("process.versions", JSON.stringify(process.versions)) - //show("process.stdout.isTTY", process.stdout.isTTY) - //show("process.stderr.isTTY", process.stderr.isTTY) - } - - } - - private def show(label: String, value: js.Any) = info(s"$label: $value") - -} diff --git a/app/nodejs-v8/src/test/scala/nodejs/child_process/ChildProcessAsyncTest.scala b/app/nodejs-v8/src/test/scala/nodejs/child_process/ChildProcessAsyncTest.scala deleted file mode 100644 index 33184f600..000000000 --- a/app/nodejs-v8/src/test/scala/nodejs/child_process/ChildProcessAsyncTest.scala +++ /dev/null @@ -1,21 +0,0 @@ -package io.scalajs.nodejs.child_process - -import io.scalajs.nodejs.buffer.Buffer -import org.scalatest.AsyncFunSpec - -import scala.concurrent.ExecutionContext - -class ChildProcessAsyncTest extends AsyncFunSpec { - override implicit val executionContext = ExecutionContext.Implicits.global - - describe("ChildProcess") { - it("supports execFuture(...)") { - for { - r <- ChildProcess.execFuture("cat ./package.json | wc -l") - } yield { - assert(r._1.asInstanceOf[Buffer].toString().trim.toInt > 0) - } - } - } - -} diff --git a/app/nodejs-v8/src/test/scala/nodejs/dns/DNSTest.scala b/app/nodejs-v8/src/test/scala/nodejs/dns/DNSTest.scala deleted file mode 100644 index 77a29b2c9..000000000 --- a/app/nodejs-v8/src/test/scala/nodejs/dns/DNSTest.scala +++ /dev/null @@ -1,42 +0,0 @@ -package io.scalajs.nodejs -package dns - -import org.scalatest.FunSpec - -import scala.scalajs.js - -/** - * DNS Tests - */ -class DNSTest extends FunSpec { - private val domain = "google.com" - - describe("DNS") { - - it("supports lookup") { - DNS.lookup(domain, (err, ipAddress) => { - assert(err === null) - info(s"lookup - ipAddress: $ipAddress") - }) - } - - it("supports lookupService:SSH") { - DNS.lookupService("127.0.0.1", 22, (err, hostname, service) => { - assert(err === null) - assert(hostname.nonEmpty) - assert(service.nonEmpty) - }) - } - - it("supports resolve:NS") { - DNS.resolve( - domain, - "NS", - (err: DnsError, addresses: ResolveResult) => { - assert(err === null) - assert(addresses.asInstanceOf[js.Array[String]].nonEmpty) - } - ) - } - } -} diff --git a/app/nodejs-v8/src/test/scala/nodejs/events/EventEmitterTest.scala b/app/nodejs-v8/src/test/scala/nodejs/events/EventEmitterTest.scala deleted file mode 100644 index 845d2946e..000000000 --- a/app/nodejs-v8/src/test/scala/nodejs/events/EventEmitterTest.scala +++ /dev/null @@ -1,58 +0,0 @@ -package io.scalajs.nodejs.events - -import io.scalajs.JSON -import org.scalatest.FunSpec - -import scala.scalajs.js - -/** - * EventEmitter Tests - */ -class EventEmitterTest extends FunSpec { - - describe("EventEmitter") { - - it("should handle events with arguments") { - val myEmitter = new EventEmitter() - myEmitter.on("event", (args: js.Array[Int]) => { - info(s"a custom event was fired with args: ${JSON.stringify(args)}") - }) - myEmitter.emit("event", js.Array(1, 2, 3)) - } - - it("should handle one-time events") { - val myEmitter = new EventEmitter() - var n = 0 - myEmitter.once("event", () => { - n += 1 - info(s"n = $n") - }) - myEmitter.emit("event") - // Prints: 1 - myEmitter.emit("event") - // Ignored - } - - it("should handle repeated events") { - val myEmitter = new EventEmitter() - var n = 0 - myEmitter.on("event", () => { - n += 1 - info(s"n = $n") - }) - myEmitter.emit("event") - // Prints: 1 - myEmitter.emit("event") - // Prints: 2 - } - - it("should count the number of fired events") { - val myEmitter = new EventEmitter() - myEmitter.on("event", () => {}) - myEmitter.on("event", () => {}) - assert(myEmitter.listenerCount("event") == 2) - } - - } - -} diff --git a/app/nodejs-v8/src/test/scala/nodejs/fs/FsTest.scala b/app/nodejs-v8/src/test/scala/nodejs/fs/FsTest.scala deleted file mode 100644 index 70563702b..000000000 --- a/app/nodejs-v8/src/test/scala/nodejs/fs/FsTest.scala +++ /dev/null @@ -1,85 +0,0 @@ -package io.scalajs.nodejs.fs - -import io.scalajs.JSON -import io.scalajs.nodejs.setImmediate -import io.scalajs.nodejs.util.Util -import io.scalajs.util.ScalaJsHelper._ -import org.scalatest.FunSpec - -/** - * File System (Fs) Tests - * - */ -class FsTest extends FunSpec { - - final val testResources = "./app/current/src/test/resources/" - - describe("Fs") { - - it("supports watching files") { - val watcher = Fs.watch(s"${testResources}", (eventType, file) => { - info(s"watcher: eventType = '$eventType' file = '$file'") - }) - info(s"watcher: ${Util.inspect(watcher)}") - - setImmediate( - () => - Fs.writeFile(s"${testResources}1.txt", "Hello", error => { - if (isDefined(error)) { - alert(s"error: ${JSON.stringify(error)}") - } - }) - ) - } - - it("should stream data") { - val file1 = s"${testResources}fileA1.txt" - val file2 = s"${testResources}fileA2.txt" - val file3 = s"${testResources}fileC2.txt" - - val readable = Fs.createReadStream(file1) - val writable = Fs.createWriteStream(file2) - readable.setEncoding("utf8") - readable.onData[String](chunk => writable.write(chunk)) - writable.onFinish { () => - info("Comparing file sizes:") - info(s"$file1 is ${Fs.statSync(file1).size} bytes") - info(s"$file2 is ${Fs.statSync(file2).size} bytes") - assert(Fs.statSync(file1).size == Fs.statSync(file2).size) - - info("should rename the file") - Fs.renameSync(file2, file3) - assert(Fs.statSync(file2).isFile()) - - info("should delete the file") - Fs.unlinkSync(file3) - val deleted = !Fs.existsSync(file3) - info(s"deleted? $deleted") - assert(deleted) - } - } - - it("should pipe data from a Readable to a Writable") { - val file1 = s"${testResources}fileB1.txt" - val file2 = s"${testResources}fileB2.txt" - - val readable = Fs.createReadStream(file1) - val writable = Fs.createWriteStream(file2) - readable.pipe(writable) - writable.onFinish { () => - info("Comparing file sizes:") - info(s"$file1 is ${Fs.statSync(file1).size} bytes") - info(s"$file2 is ${Fs.statSync(file2).size} bytes") - assert(Fs.statSync(file1).size == Fs.statSync(file2).size) - } - } - - it("support access") { - Fs.access("./package.json", err => { - assert(err == null) - }) - } - - } - -} diff --git a/app/nodejs-v8/src/test/scala/nodejs/readline/ReadlineTest.scala b/app/nodejs-v8/src/test/scala/nodejs/readline/ReadlineTest.scala deleted file mode 100644 index 18de282b9..000000000 --- a/app/nodejs-v8/src/test/scala/nodejs/readline/ReadlineTest.scala +++ /dev/null @@ -1,57 +0,0 @@ -package io.scalajs.nodejs.readline - -import io.scalajs.nodejs.fs.Fs -import io.scalajs.nodejs.{console, process} -import org.scalatest.FunSpec - -/** - * Readline Tests - */ -class ReadlineTest extends FunSpec { - - describe("Readline") { - - it("should read/stream files from disk") { - var lineNo = 0 - val file = "./package.json" - val reader = Readline.createInterface( - new ReadlineOptions( - input = Fs.createReadStream(file), - output = process.stdout, - terminal = false - ) - ) - - reader.onLine { line => - lineNo += 1 - info(f"[$lineNo%02d] $line") - } - - reader.onClose { () => - info("# stream closed.") - } - } - - it("has REPL-like functionality") { - val rl = Readline.createInterface(new ReadlineOptions(input = process.stdin, output = process.stdout)) - rl.setPrompt("OHAI> ") - rl.prompt() - - rl.onLine { line => - line.trim() match { - case "hello" => - console.log("world!") - case _ => - console.log(s"Say what? I might have heard `${line.trim()}`") - } - rl.prompt() - - } onClose { () => - console.log("Have a great day!") - //process.exit(0) - } - } - - } - -}