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

Commit f42c207

Browse files
author
exoego
committed
Use assertion instead of info
1 parent f2e8b29 commit f42c207

File tree

16 files changed

+236
-222
lines changed

16 files changed

+236
-222
lines changed

app/current/src/test/resources/fileA2.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.scalajs.nodejs
22

3-
import io.scalajs.JSON
43
import io.scalajs.nodejs.Process.ProcessEnvExtensions
4+
import io.scalajs.nodejs.os.OS
55
import org.scalatest.FunSpec
66

77
import scala.scalajs.js
@@ -12,30 +12,34 @@ import scala.scalajs.js
1212
class ProcessTest extends FunSpec {
1313

1414
describe("Process") {
15+
val versionPrefix =
16+
if (TestEnvironment.isExecutedInExactNode8) "v8."
17+
else if (TestEnvironment.isExecutedInExactNode10) "v10."
18+
else if (TestEnvironment.isExecutedInExactNode12) "v12."
19+
else "Unknown node.js version"
1520

1621
it("contains the following properties") {
17-
show("process.arch", process.arch)
18-
show("process.argv", process.argv)
19-
show("process.config", process.config)
20-
show("process.connected", process.connected)
21-
show("process.cwd()", process.cwd())
22-
show("process.domain", process.domain)
23-
show("process.env", process.env)
24-
show("process.env.NODE_ENV", process.env.NODE_ENV)
25-
show("process.env.PATH", process.env.PATH)
26-
show("process.execArgv", process.execArgv)
27-
show("process.execPath", process.execPath)
28-
show("process.features", process.features)
29-
show("process.moduleLoadList", process.moduleLoadList)
30-
show("process.title", process.title)
31-
show("process.version", process.version)
32-
show("process.versions", JSON.stringify(process.versions))
33-
//show("process.stdout.isTTY", process.stdout.isTTY)
34-
//show("process.stderr.isTTY", process.stderr.isTTY)
22+
assert(process.arch.isInstanceOf[String])
23+
assert(process.argv.length === 1)
24+
assert(process.argv(0).endsWith("node"))
25+
assert(process.config("variables").asInstanceOf[js.Dictionary[String]]("host_arch") === OS.arch())
26+
assert(process.connected.isEmpty)
27+
assert(process.cwd().nonEmpty)
28+
assert(process.env("PATH").nonEmpty)
29+
assert(process.env.PATH === process.env("PATH"))
30+
assert(process.execArgv.length === 0)
31+
assert(process.execPath.endsWith("node"))
32+
assert(process.features.contains("debug"))
33+
assert(process.moduleLoadList.length > 0)
34+
assert(process.title.isInstanceOf[String])
35+
assert(process.version.startsWith(versionPrefix))
36+
assert(process.versions.node.map(v => s"v${v}").getOrElse("").startsWith(versionPrefix))
37+
38+
// TODO: actually undefined in test
39+
// assert(process.stdout.isTTY)
40+
// assert(process.stderr.isTTY)
3541
}
3642

3743
}
3844

39-
private def show(label: String, value: js.Any) = info(s"$label: $value")
40-
4145
}

app/nodejs-v8/src/test/scala/io/scalajs/nodejs/StringDecoderTest.scala

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,15 @@ package io.scalajs.nodejs
33
import io.scalajs.nodejs.buffer.Buffer
44
import org.scalatest.FunSpec
55

6-
/**
7-
* StringDecoder Tests
8-
*/
96
class StringDecoderTest extends FunSpec {
107

118
describe("StringDecoder") {
129

1310
it("should decode strings or buffer") {
1411
val decoder = new StringDecoder("utf8")
15-
16-
info(decoder.write(Buffer.from("Hello ")))
17-
info(decoder.write(Buffer.from("World")))
18-
info(decoder.end(Buffer.from("!")))
12+
assert(decoder.write(Buffer.from("Hello ")) === "Hello ")
13+
assert(decoder.write(Buffer.from("World")) === "World")
14+
assert(decoder.end(Buffer.from("!")) === "!")
1915
}
2016

2117
}

app/nodejs-v8/src/test/scala/io/scalajs/nodejs/TestEnvironment.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ object TestEnvironment {
88
private lazy val nodeMajorVersion: Int =
99
ChildProcess.execSync("node -v").asInstanceOf[Buffer].toString().drop(1).takeWhile(_.isDigit).toInt
1010

11+
def isWindows: Boolean = os.OS.platform().startsWith("win")
12+
1113
def isExecutedInExactNode12: Boolean = nodeMajorVersion == 12
1214
def isExecutedInExactNode10: Boolean = nodeMajorVersion == 10
1315
def isExecutedInExactNode8: Boolean = nodeMajorVersion == 8

app/nodejs-v8/src/test/scala/io/scalajs/nodejs/buffer/BufferTest.scala

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
package io.scalajs.nodejs.buffer
22

3-
import io.scalajs.collection.Iterator.Entry
43
import io.scalajs.nodejs.{TestEnvironment, buffer}
54
import org.scalatest.FunSpec
65

76
import scala.scalajs.js
87
import scala.scalajs.js.typedarray.{ArrayBuffer, DataView, Uint8Array}
98

10-
/**
11-
* Buffer Tests
12-
*/
139
class BufferTest extends FunSpec {
1410

1511
describe("Buffer") {
@@ -26,19 +22,19 @@ class BufferTest extends FunSpec {
2622
assert(buf2.compare(buf3) === 1)
2723
}
2824

29-
it("should support iterating entries [classic]") {
30-
val buf = Buffer.from("Hello!")
31-
val it = buf.entries()
32-
var result: Entry[js.Any] = null
33-
do {
34-
result = it.next()
35-
if (!result.done) info(s"value: ${result.value}")
36-
} while (!result.done)
37-
}
38-
39-
it("should support iterating entries [Scala]") {
25+
it("should support iterating entries") {
4026
val buf = Buffer.from("Hello!")
41-
for (value <- buf.entries()) info(s"value: $value")
27+
val it = buf.entries()
28+
assert(
29+
it.toSeq.map(_.toSeq) === Seq(
30+
Seq(0, 72),
31+
Seq(1, 101),
32+
Seq(2, 108),
33+
Seq(3, 108),
34+
Seq(4, 111),
35+
Seq(5, 33)
36+
)
37+
)
4238
}
4339

4440
it("should support buffer property") {
@@ -76,24 +72,20 @@ class BufferTest extends FunSpec {
7672

7773
it("should create buffers from strings") {
7874
val bufA = Buffer.from("Hello ")
79-
info(s"bufA => ${bufA.toString()}")
8075
val bufB = Buffer.from("World")
81-
info(s"bufB => ${bufB.toString()}")
8276
val bufC = bufA + bufB
83-
info(s"bufC => ${bufC.toString()}, length = ${bufC.byteLength()}")
8477

8578
assert(bufA.toString() === "Hello ")
8679
assert(bufB.toString() === "World")
87-
assert(bufC.byteLength() === 11)
80+
assert(bufC.byteLength === 11)
8881
}
8982

9083
it("should create buffers from buffers") {
9184
val buffer = Buffer.from("hello")
9285
assert(Buffer.from(buffer).toString() === "hello")
9386

94-
// TODO: when Scala.js added TypedArray.from
95-
// val uints = Uint8Array.from(???)
96-
// assert(Buffer.from(uints).toString() ==="worlds")
87+
val uints = Uint8Array.from(js.Array(72, 101, 108, 108, 111))
88+
assert(Buffer.from(uints).toString() === "Hello")
9789
}
9890

9991
it("should support concat") {

app/nodejs-v8/src/test/scala/io/scalajs/nodejs/child_process/ChildProcessAsyncTest.scala

Lines changed: 0 additions & 21 deletions
This file was deleted.

app/nodejs-v8/src/test/scala/io/scalajs/nodejs/child_process/ChildProcessTest.scala

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,69 @@
11
package io.scalajs.nodejs
22
package child_process
33

4-
import io.scalajs.nodejs.Error
54
import io.scalajs.nodejs.buffer.Buffer
65
import io.scalajs.util.ScalaJsHelper._
7-
import org.scalatest.FunSpec
6+
import org.scalatest.AsyncFunSpec
87

8+
import scala.concurrent.{ExecutionContext, Promise}
99
import scala.scalajs.js
1010
import scala.scalajs.js.|
1111

1212
/**
1313
* ChildProcess Test
1414
*
1515
*/
16-
class ChildProcessTest extends FunSpec {
16+
class ChildProcessTest extends AsyncFunSpec {
17+
override implicit val executionContext = ExecutionContext.Implicits.global
18+
19+
describe("Extension") {
20+
it("supports execFuture(...)") {
21+
for {
22+
r <- ChildProcess.execFuture("cat ./package.json | wc -l")
23+
} yield {
24+
assert(r._1.asInstanceOf[Buffer].toString().trim.toInt > 0)
25+
}
26+
}
27+
}
1728

1829
describe("ChildProcess") {
1930
it("supports exec(...)") {
31+
val promise = Promise[(Output, Output)]()
2032
ChildProcess.exec(
2133
"cat ./package.json | wc -l",
22-
callback = (error: Error, stdout: Buffer | String, stderr: Buffer | String) => {
34+
callback = (error: Error, stdout: Output, stderr: Output) => {
2335
if (isDefined(error)) {
24-
console.error(s"exec error: $error")
36+
promise.failure(error)
37+
} else {
38+
promise.success((stdout, stderr))
2539
}
26-
info(s"stdout: $stdout")
27-
info(s"stderr: $stderr")
2840
}
2941
)
42+
promise.future.map {
43+
case (stdout, stderr) =>
44+
assert(stdout.toString.trim.toInt === 19)
45+
assert(stderr.toString.trim === "")
46+
}
3047
}
3148

3249
it("supports execFile(...)") {
50+
val promise = Promise[(Output, Output)]()
3351
ChildProcess.execFile(
3452
"ls",
3553
js.Array("-l"),
36-
callback = (error: Error, stdout: Buffer | String, stderr: Buffer | String) => {
54+
callback = (error: Error, stdout: Output, stderr: Output) => {
3755
if (isDefined(error)) {
38-
console.error(s"exec error: $error")
56+
promise.failure(error)
57+
} else {
58+
promise.success((stdout, stderr))
3959
}
40-
info(s"stdout: $stdout")
41-
info(s"stderr: $stderr")
4260
}
4361
)
62+
promise.future.map {
63+
case (stdout, stderr) =>
64+
assert(stdout.toString.trim.linesIterator.length > 10)
65+
assert(stderr.toString.trim === "")
66+
}
4467
}
4568

4669
it("supports execSync(...)") {

app/nodejs-v8/src/test/scala/io/scalajs/nodejs/cluster/ClusterTest.scala

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,23 @@ import org.scalatest.FunSpec
88
import scala.concurrent.duration._
99
import scala.scalajs.js
1010

11-
/**
12-
* Cluster Tests
13-
*/
1411
class ClusterTest extends FunSpec {
1512

1613
describe("Cluster") {
1714

1815
it("cluster should be master") {
19-
info(s"cluster.isMaster => ${Cluster.isMaster}")
2016
assert(Cluster.isMaster)
2117
}
2218

2319
it("cluster should not be a worker") {
24-
info(s"cluster.isWorker => ${Cluster.isWorker}")
2520
assert(!Cluster.isWorker)
2621
}
2722

2823
it("cluster.schedulingPolicy must be defined") {
29-
info(s"cluster.schedulingPolicy => ${Cluster.schedulingPolicy}")
3024
assert(!js.isUndefined(Cluster.schedulingPolicy))
3125
}
3226

3327
it("cluster.settings must be defined") {
34-
info(s"cluster.settings => ${JSON.stringify(Cluster.settings)}")
3528
assert(!js.isUndefined(Cluster.settings))
3629
}
3730

app/nodejs-v8/src/test/scala/io/scalajs/nodejs/dns/DNSAsyncTest.scala

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,57 @@ package dns
33

44
import org.scalatest.AsyncFunSpec
55

6-
import scala.concurrent.ExecutionContext
6+
import scala.concurrent.{ExecutionContext, Promise}
77
import scala.scalajs.js
88

9-
/**
10-
* DNS Tests
11-
*/
129
class DNSAsyncTest extends AsyncFunSpec {
13-
private val domain = "google.com"
1410
override implicit val executionContext = ExecutionContext.Implicits.global
1511

12+
private val domain = "google.com"
13+
1614
describe("DNS") {
15+
16+
it("supports lookup") {
17+
val promise = Promise[String]()
18+
DNS.lookup(domain, (err, ipAddress) => {
19+
assert(err === null)
20+
promise.success(ipAddress)
21+
})
22+
promise.future.map { ipAddress =>
23+
assert(ipAddress.nonEmpty)
24+
}
25+
}
26+
27+
it("supports lookupService:SSH") {
28+
val promise = Promise[(String, String)]()
29+
DNS.lookupService("127.0.0.1", 22, (err, hostname, service) => {
30+
assert(err === null)
31+
promise.success((hostname, service))
32+
})
33+
promise.future.map {
34+
case (host, service) =>
35+
assert(host === "localhost")
36+
assert(service === "ssh")
37+
}
38+
}
39+
40+
it("supports resolve:NS") {
41+
val promise = Promise[js.Array[String]]()
42+
DNS.resolve(
43+
domain,
44+
"NS",
45+
(err: DnsError, addresses: ResolveResult) => {
46+
assert(err === null)
47+
promise.success(addresses.asInstanceOf[js.Array[String]])
48+
}
49+
)
50+
promise.future.map { addresses =>
51+
assert(addresses.nonEmpty)
52+
}
53+
}
54+
}
55+
56+
describe("DNS future extension") {
1757
it("supports lookupFuture") {
1858
DNS.lookupFuture(domain) map {
1959
case (ipAddress, ttl) =>

0 commit comments

Comments
 (0)