summaryrefslogtreecommitdiff
path: root/ws/test.ts
diff options
context:
space:
mode:
authorVincent LE GOFF <g_n_s@hotmail.fr>2019-03-06 22:39:50 +0100
committerRyan Dahl <ry@tinyclouds.org>2019-03-06 16:39:50 -0500
commite36edfdb3fd4709358a5f499f13cfe3d53c2b4f7 (patch)
tree1baef3f876a5e75288c3ec9056cdb93dd6b5787f /ws/test.ts
parentd29957ad17956016c35a04f5f1f98565e58e8a2e (diff)
Testing refactor (denoland/deno_std#240)
Original: https://github.com/denoland/deno_std/commit/e1d5c00279132aa639030c6c6d9b4e308bd4775e
Diffstat (limited to 'ws/test.ts')
-rw-r--r--ws/test.ts63
1 files changed, 32 insertions, 31 deletions
diff --git a/ws/test.ts b/ws/test.ts
index 79add1740..4bc6a1203 100644
--- a/ws/test.ts
+++ b/ws/test.ts
@@ -3,7 +3,8 @@ import "./sha1_test.ts";
const { Buffer } = Deno;
import { BufReader } from "../io/bufio.ts";
-import { test, assert } from "../testing/mod.ts";
+import { assert, assertEq } from "../testing/asserts.ts";
+import { test } from "../testing/mod.ts";
import {
acceptable,
createSecAccept,
@@ -18,10 +19,10 @@ test(async function testReadUnmaskedTextFrame() {
new Buffer(new Uint8Array([0x81, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f]))
);
const frame = await readFrame(buf);
- assert.equal(frame.opcode, OpCode.TextFrame);
- assert.equal(frame.mask, undefined);
- assert.equal(new Buffer(frame.payload).toString(), "Hello");
- assert.equal(frame.isLastFrame, true);
+ assertEq(frame.opcode, OpCode.TextFrame);
+ assertEq(frame.mask, undefined);
+ assertEq(new Buffer(frame.payload).toString(), "Hello");
+ assertEq(frame.isLastFrame, true);
});
test(async function testReadMakedTextFrame() {
@@ -45,10 +46,10 @@ test(async function testReadMakedTextFrame() {
);
const frame = await readFrame(buf);
console.dir(frame);
- assert.equal(frame.opcode, OpCode.TextFrame);
+ assertEq(frame.opcode, OpCode.TextFrame);
unmask(frame.payload, frame.mask);
- assert.equal(new Buffer(frame.payload).toString(), "Hello");
- assert.equal(frame.isLastFrame, true);
+ assertEq(new Buffer(frame.payload).toString(), "Hello");
+ assertEq(frame.isLastFrame, true);
});
test(async function testReadUnmaskedSplittedTextFrames() {
@@ -59,15 +60,15 @@ test(async function testReadUnmaskedSplittedTextFrames() {
new Buffer(new Uint8Array([0x80, 0x02, 0x6c, 0x6f]))
);
const [f1, f2] = await Promise.all([readFrame(buf1), readFrame(buf2)]);
- assert.equal(f1.isLastFrame, false);
- assert.equal(f1.mask, undefined);
- assert.equal(f1.opcode, OpCode.TextFrame);
- assert.equal(new Buffer(f1.payload).toString(), "Hel");
+ assertEq(f1.isLastFrame, false);
+ assertEq(f1.mask, undefined);
+ assertEq(f1.opcode, OpCode.TextFrame);
+ assertEq(new Buffer(f1.payload).toString(), "Hel");
- assert.equal(f2.isLastFrame, true);
- assert.equal(f2.mask, undefined);
- assert.equal(f2.opcode, OpCode.Continue);
- assert.equal(new Buffer(f2.payload).toString(), "lo");
+ assertEq(f2.isLastFrame, true);
+ assertEq(f2.mask, undefined);
+ assertEq(f2.opcode, OpCode.Continue);
+ assertEq(new Buffer(f2.payload).toString(), "lo");
});
test(async function testReadUnmaksedPingPongFrame() {
@@ -76,8 +77,8 @@ test(async function testReadUnmaksedPingPongFrame() {
new Buffer(new Uint8Array([0x89, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f]))
);
const ping = await readFrame(buf);
- assert.equal(ping.opcode, OpCode.Ping);
- assert.equal(new Buffer(ping.payload).toString(), "Hello");
+ assertEq(ping.opcode, OpCode.Ping);
+ assertEq(new Buffer(ping.payload).toString(), "Hello");
const buf2 = new BufReader(
new Buffer(
@@ -97,10 +98,10 @@ test(async function testReadUnmaksedPingPongFrame() {
)
);
const pong = await readFrame(buf2);
- assert.equal(pong.opcode, OpCode.Pong);
+ assertEq(pong.opcode, OpCode.Pong);
assert(pong.mask !== undefined);
unmask(pong.payload, pong.mask);
- assert.equal(new Buffer(pong.payload).toString(), "Hello");
+ assertEq(new Buffer(pong.payload).toString(), "Hello");
});
test(async function testReadUnmaksedBigBinaryFrame() {
@@ -110,10 +111,10 @@ test(async function testReadUnmaksedBigBinaryFrame() {
}
const buf = new BufReader(new Buffer(new Uint8Array(a)));
const bin = await readFrame(buf);
- assert.equal(bin.opcode, OpCode.BinaryFrame);
- assert.equal(bin.isLastFrame, true);
- assert.equal(bin.mask, undefined);
- assert.equal(bin.payload.length, 256);
+ assertEq(bin.opcode, OpCode.BinaryFrame);
+ assertEq(bin.isLastFrame, true);
+ assertEq(bin.mask, undefined);
+ assertEq(bin.payload.length, 256);
});
test(async function testReadUnmaskedBigBigBinaryFrame() {
@@ -123,16 +124,16 @@ test(async function testReadUnmaskedBigBigBinaryFrame() {
}
const buf = new BufReader(new Buffer(new Uint8Array(a)));
const bin = await readFrame(buf);
- assert.equal(bin.opcode, OpCode.BinaryFrame);
- assert.equal(bin.isLastFrame, true);
- assert.equal(bin.mask, undefined);
- assert.equal(bin.payload.length, 0xffff + 1);
+ assertEq(bin.opcode, OpCode.BinaryFrame);
+ assertEq(bin.isLastFrame, true);
+ assertEq(bin.mask, undefined);
+ assertEq(bin.payload.length, 0xffff + 1);
});
test(async function testCreateSecAccept() {
const nonce = "dGhlIHNhbXBsZSBub25jZQ==";
const d = createSecAccept(nonce);
- assert.equal(d, "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=");
+ assertEq(d, "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=");
});
test(function testAcceptable() {
@@ -142,7 +143,7 @@ test(function testAcceptable() {
"sec-websocket-key": "aaa"
})
});
- assert.equal(ret, true);
+ assertEq(ret, true);
});
const invalidHeaders = [
@@ -157,6 +158,6 @@ test(function testAcceptableInvalid() {
const ret = acceptable({
headers: new Headers(pat)
});
- assert.equal(ret, false);
+ assertEq(ret, false);
}
});