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

Commit 17f1a06

Browse files
author
TATSUNO Yasuhiro
authored
Merge pull request #30 from exoego/test-all-node
Test all node
2 parents ce835a2 + 303c3e4 commit 17f1a06

30 files changed

+288
-222
lines changed

.travis.yml

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,37 @@ scala:
55
- 2.12.9
66
- 2.13.0
77

8-
env:
9-
- TRAVIS_NODE_VERSION="12.5.0"
10-
118
jdk:
129
- openjdk8
1310
- openjdk11
1411

12+
env:
13+
- TRAVIS_NODE_VERSION="12.9.1" JOB_NAME="test"
14+
15+
script:
16+
- sbt ++$TRAVIS_SCALA_VERSION nodejs_v8/test nodejs_v10/test current/test
17+
18+
matrix:
19+
include:
20+
- scala: 2.13.0
21+
jdk: openjdk11
22+
env: TRAVIS_NODE_VERSION="12.9.1" JOB_NAME="format and doc"
23+
script: sbt ++$TRAVIS_SCALA_VERSION scalafmtSbtCheck scalafmtCheck test:scalafmtCheck current/doc core/doc
24+
- scala: 2.13.0
25+
jdk: openjdk11
26+
env: TRAVIS_NODE_VERSION="8.16.1" JOB_NAME="test"
27+
script: sbt ++$TRAVIS_SCALA_VERSION nodejs_v8/test
28+
- scala: 2.13.0
29+
jdk: openjdk11
30+
env: TRAVIS_NODE_VERSION="10.16.3" JOB_NAME="test"
31+
script: sbt ++$TRAVIS_SCALA_VERSION nodejs_v8/test nodejs_v10/test
32+
1533
install:
1634
- rm -rf ~/.nvm &&
1735
git clone https://github.com/nvm-sh/nvm.git ~/.nvm &&
1836
(cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`) &&
1937
source ~/.nvm/nvm.sh && nvm install $TRAVIS_NODE_VERSION
2038

21-
script:
22-
- sbt ++$TRAVIS_SCALA_VERSION scalafmtSbtCheck scalafmtCheck test:scalafmtCheck clean current/doc core/doc test
23-
2439
before_cache:
2540
- rm -fv $HOME/.ivy2/.sbt.ivy.lock
2641
- find $HOME/.ivy2/cache -name "ivydata-*.properties" -print -delete

app/current/src/test/scala/nodejs/ConsoleTest.scala

Lines changed: 0 additions & 63 deletions
This file was deleted.
Lines changed: 7 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -1,164 +1,18 @@
1-
package io.scalajs.nodejs.buffer
1+
package nodejs.buffer
22

3-
import io.scalajs.collection.Iterator.Entry
4-
import io.scalajs.nodejs.buffer
3+
import io.scalajs.nodejs.buffer.Buffer
54
import org.scalatest.FunSpec
65

76
import scala.scalajs.js
8-
import scala.scalajs.js.typedarray.{ArrayBuffer, DataView, Uint8Array}
97

108
/**
119
* Buffer Tests
1210
*/
1311
class BufferTest extends FunSpec {
14-
15-
describe("Buffer") {
16-
describe("instance members") {
17-
it("should sort buffers") {
18-
val buf1 = Buffer.from("ABC")
19-
val buf2 = Buffer.from("BCD")
20-
val buf3 = Buffer.from("ABCD")
21-
22-
assert(buf1.compare(buf1) == 0)
23-
assert(buf1.compare(buf2) == -1)
24-
assert(buf1.compare(buf3) == -1)
25-
assert(buf2.compare(buf1) == 1)
26-
assert(buf2.compare(buf3) == 1)
27-
}
28-
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]") {
40-
val buf = Buffer.from("Hello!")
41-
for (value <- buf.entries()) info(s"value: $value")
42-
}
43-
44-
it("should support buffer property") {
45-
val arrayBuffer = new ArrayBuffer(16)
46-
val buf = Buffer.from(arrayBuffer)
47-
assert(buf.buffer === arrayBuffer)
48-
}
49-
50-
it("should support byteOffset property") {
51-
import scala.scalajs.js.typedarray.Int8Array
52-
val nodeBuffer = Buffer.from(js.Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9))
53-
val typedarray = new Int8Array(nodeBuffer.buffer, nodeBuffer.byteOffset, nodeBuffer.length)
54-
assert(typedarray.mkString == new Int8Array(js.Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)).mkString)
55-
}
56-
57-
it("should support byteLength for specific types") {
58-
assert(Buffer.byteLength("\u00bd + \u00bc = \u00be") == 12)
59-
assert(Buffer.byteLength("\u00bd + \u00bc = \u00be", "utf8") == 12)
60-
assert(Buffer.byteLength(Buffer.alloc(12)) == 12)
61-
assert(Buffer.byteLength(new Uint8Array(12)) == 12)
62-
assert(Buffer.byteLength(new DataView(new ArrayBuffer(12))) == 12)
63-
assert(Buffer.byteLength(new ArrayBuffer(12)) == 12)
64-
}
65-
66-
it("should support fill") {
67-
val otherBuf = Buffer.from("abcdef")
68-
assert(Buffer.alloc(10).fill(otherBuf).toString() == "abcdefabcd")
69-
}
70-
}
71-
72-
describe("class members") {
73-
it("should support fields") {
74-
assert(Buffer.poolSize > 0)
75-
}
76-
77-
it("should create buffers from strings") {
78-
val bufA = Buffer.from("Hello ")
79-
info(s"bufA => ${bufA.toString()}")
80-
val bufB = Buffer.from("World")
81-
info(s"bufB => ${bufB.toString()}")
82-
val bufC = bufA + bufB
83-
info(s"bufC => ${bufC.toString()}, length = ${bufC.byteLength()}")
84-
85-
assert(bufA.toString() == "Hello ")
86-
assert(bufB.toString() == "World")
87-
assert(bufC.byteLength() == 11)
88-
}
89-
90-
it("should create buffers from buffers") {
91-
val buffer = Buffer.from("hello")
92-
assert(Buffer.from(buffer).toString() == "hello")
93-
94-
// TODO: when Scala.js added TypedArray.from
95-
// val uints = Uint8Array.from(???)
96-
// assert(Buffer.from(uints).toString() == "worlds")
97-
}
98-
99-
it("should support concat") {
100-
val buffers = js.Array(Buffer.from("abc"), Buffer.from("def"), Buffer.from("ghijk"))
101-
assert(Buffer.compare(Buffer.concat(buffers), Buffer.from("abcdefghijk")) == 0)
102-
assert(Buffer.compare(Buffer.concat(buffers, 5), Buffer.from("abcde")) == 0)
103-
104-
val uints: js.Array[Uint8Array] = js.Array(Buffer.from("abc"), Buffer.from("def"), Buffer.from("ghijk"))
105-
assert(Buffer.compare(Buffer.concat(uints), Buffer.from("abcdefghijk")) == 0)
106-
assert(Buffer.compare(Buffer.concat(uints, 5), Buffer.from("abcde")) == 0)
107-
}
108-
109-
it("should support isBufrer") {
110-
assert(!Buffer.isBuffer(null))
111-
assert(!Buffer.isBuffer(js.Object()))
112-
assert(!Buffer.isBuffer(js.Array(1, 2, 3)))
113-
assert(Buffer.isBuffer(Buffer.from("hello")))
114-
}
115-
116-
it("should support isEncoding") {
117-
assert(!Buffer.isEncoding(null))
118-
assert(!Buffer.isEncoding(""))
119-
assert(Buffer.isEncoding("utf8"))
120-
assert(Buffer.isEncoding("UTF-8"))
121-
}
122-
123-
it("should support writeBigInt64BE, writeBigInt64LE, writeBigInt64BE and writeBigInt64BE") {
124-
val buf = Buffer.allocUnsafe(8)
125-
val v = js.Dynamic.global.BigInt("0x0102030405060708")
126-
buf.writeBigInt64BE(v, 0);
127-
assert(Buffer.compare(buf, Buffer.from(js.Array(1, 2, 3, 4, 5, 6, 7, 8))) === 0)
128-
}
129-
}
130-
131-
describe("module members") {
132-
it("should support transcode") {
133-
// package object method
134-
assert(buffer.transcode(Buffer.from("hello"), "utf8", "ascii").toString("ascii") == "hello")
135-
assert(buffer.transcode(Buffer.from(""), "utf8", "ascii").toString("ascii") == "?")
136-
137-
// extension method
138-
assert(Buffer.transcode(Buffer.from("hello"), "utf8", "ascii").toString("ascii") == "hello")
139-
assert(Buffer.transcode(Buffer.from(""), "utf8", "ascii").toString("ascii") == "?")
140-
}
141-
142-
it("should support fields") {
143-
// package object method
144-
assert(buffer.INSPECT_MAX_BYTES > 0)
145-
assert(buffer.kMaxLength > 0)
146-
147-
// extension method
148-
assert(Buffer.INSPECT_MAX_BYTES > 0)
149-
assert(Buffer.kMaxLength > 0)
150-
}
151-
152-
it("should support constants") {
153-
// package object method
154-
assert(buffer.constants.MAX_LENGTH > 0)
155-
assert(buffer.constants.MAX_STRING_LENGTH > 0)
156-
157-
// extension method
158-
assert(Buffer.constants.MAX_LENGTH > 0)
159-
assert(Buffer.constants.MAX_STRING_LENGTH > 0)
160-
}
161-
}
12+
it("should support writeBigInt64BE, writeBigInt64LE, writeBigInt64BE and writeBigInt64BE") {
13+
val buf = Buffer.allocUnsafe(8)
14+
val v = js.Dynamic.global.BigInt("0x0102030405060708")
15+
buf.writeBigInt64BE(v, 0);
16+
assert(Buffer.compare(buf, Buffer.from(js.Array(1, 2, 3, 4, 5, 6, 7, 8))) === 0)
16217
}
163-
16418
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package nodejs
2+
3+
import io.scalajs.nodejs.console_module.{Console, ConsoleOptions}
4+
import io.scalajs.nodejs.fs.Fs
5+
import org.scalatest.{BeforeAndAfterEach, FunSpec}
6+
7+
import scala.scalajs.js
8+
9+
class ConsoleTest extends FunSpec with BeforeAndAfterEach {
10+
11+
private val logFileName = "x.nodejs10.ConsoleTest"
12+
13+
override def afterEach(): Unit = {
14+
if (Fs.existsSync(logFileName)) Fs.unlinkSync(logFileName)
15+
}
16+
17+
it("have table added in v10.0.0") {
18+
Console.table(js.Array("x", "y"))
19+
}
20+
21+
it("have timeLog added in v10.7.0") {
22+
val label = "yay"
23+
Console.time(label)
24+
Console.timeLog(label)
25+
Console.timeEnd(label)
26+
}
27+
28+
it("have constructor(options) added in v10.0.0") {
29+
val console = new Console(
30+
new ConsoleOptions(
31+
stdout = io.scalajs.nodejs.process.stdout
32+
)
33+
)
34+
35+
val label = "yay"
36+
console.time(label)
37+
console.timeEnd(label)
38+
}
39+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package nodejs
2+
3+
import io.scalajs.nodejs.console_module.Console
4+
import io.scalajs.nodejs.fs.Fs
5+
import org.scalatest.{BeforeAndAfterEach, FunSpec}
6+
7+
import scala.scalajs.js.JavaScriptException
8+
9+
class ConsoleTest extends FunSpec with BeforeAndAfterEach {
10+
11+
private val logFileName = "x.nodejs8.ConsoleTest"
12+
13+
override def afterEach(): Unit = {
14+
if (Fs.existsSync(logFileName)) Fs.unlinkSync(logFileName)
15+
}
16+
17+
private val failingWritable = Fs.createWriteStream(logFileName)
18+
failingWritable.close(_ => {})
19+
20+
it("have constructor(stdout, stderr, ignoreErrors) added in v8.0.0") {
21+
val looseConsole = new Console(
22+
stdout = failingWritable,
23+
stderr = failingWritable,
24+
ignoreErrors = true
25+
)
26+
looseConsole.log("ok")
27+
}
28+
29+
it("should support ignoreErrors") {
30+
assume(TestEnvironment.isExecutedInNode10OrNewer)
31+
val strictConsole = new Console(
32+
stdout = failingWritable,
33+
stderr = failingWritable,
34+
ignoreErrors = false
35+
)
36+
37+
val ex = intercept[JavaScriptException] {
38+
strictConsole.log("ok")
39+
}
40+
assert(ex.getMessage().contains("write after end"))
41+
}
42+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package nodejs
2+
import io.scalajs.nodejs.buffer.Buffer
3+
import io.scalajs.nodejs.child_process.ChildProcess
4+
5+
object TestEnvironment {
6+
7+
private lazy val nodeMajorVersion: Int =
8+
ChildProcess.execSync("node -v").asInstanceOf[Buffer].toString().drop(1).takeWhile(_.isDigit).toInt
9+
10+
def isExecutedInExactNode12: Boolean = nodeMajorVersion == 12
11+
def isExecutedInExactNode10: Boolean = nodeMajorVersion == 10
12+
def isExecutedInExactNode8: Boolean = nodeMajorVersion == 8
13+
14+
def isExecutedInNode12OrNewer: Boolean = nodeMajorVersion >= 12
15+
def isExecutedInNode10OrNewer: Boolean = nodeMajorVersion >= 10
16+
}

0 commit comments

Comments
 (0)