Skip to content

Commit

Permalink
test(e2e): refactor e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasgloning committed Aug 6, 2023
1 parent 6b9ed7c commit 4cc1c81
Show file tree
Hide file tree
Showing 29 changed files with 338 additions and 319 deletions.
7 changes: 5 additions & 2 deletions e2e/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const strings = [

export { commit_data } from "./commit_data.js";

export const typed_arrays = [
export const uint8_arrays = [
new Uint8Array(),
new Uint8Array([0]),
new Uint8Array([0, 1, 2, 3, 4, 6, 7]),
Expand All @@ -40,6 +40,9 @@ export const typed_arrays = [
0, 1, 2, 3, 4, 6, 78, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 30, 31,
]),
];

export const int32_arrays = [
new Int32Array([0].map((x) => -x)),
new Int32Array([0, 1, 2, 3, 4, 6, 7].map((x) => -x)),
new Int32Array(
Expand All @@ -53,7 +56,7 @@ export const typed_arrays = [
),
];

export const typed_array_view = new Uint8Array(typed_arrays[6].buffer, 4);
export const typed_array_view = new Uint8Array(uint8_arrays[4].buffer, 4);

export const array_buffers = [
new Uint8Array(),
Expand Down
18 changes: 18 additions & 0 deletions e2e/datachannel/Int32Array_as_ArrayBuffer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { int32_arrays } from "../data.js";
import { expect } from "https://esm.sh/v126/[email protected]/X-dHMvZXhwZWN0/es2021/chai.bundle.mjs";

/** @param {unknown[]} received */
export const check = (received) => {
for (const [i, typed_array] of int32_arrays.entries()) {
expect(received[i]).to.be.an.instanceof(ArrayBuffer);
expect(new Int32Array(received[i])).to.deep.equal(typed_array);
}
};
/**
* @param {import("../peerjs").DataConnection} dataConnection
*/
export const send = (dataConnection) => {
for (const typed_array of int32_arrays) {
dataConnection.send(typed_array);
}
};
17 changes: 17 additions & 0 deletions e2e/datachannel/TypedArrayView_as_ArrayBuffer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { typed_array_view } from "../data.js";
import { expect } from "https://esm.sh/v126/[email protected]/X-dHMvZXhwZWN0/es2021/chai.bundle.mjs";

/** @param {unknown[]} received */
export const check = (received) => {
const received_typed_array_view = received[0];
expect(received_typed_array_view).to.be.instanceOf(ArrayBuffer);
expect(new Uint8Array(received_typed_array_view)).to.deep.equal(
typed_array_view,
);
};
/**
* @param {import("../peerjs").DataConnection} dataConnection
*/
export const send = (dataConnection) => {
dataConnection.send(typed_array_view);
};
18 changes: 18 additions & 0 deletions e2e/datachannel/Uint8Array_as_ArrayBuffer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { uint8_arrays } from "../data.js";
import { expect } from "https://esm.sh/v126/[email protected]/X-dHMvZXhwZWN0/es2021/chai.bundle.mjs";

/** @param {unknown[]} received */
export const check = (received) => {
for (const [i, typed_array] of uint8_arrays.entries()) {
expect(received[i]).to.be.an.instanceof(ArrayBuffer);
expect(new Uint8Array(received[i])).to.deep.equal(typed_array);
}
};
/**
* @param {import("../peerjs").DataConnection} dataConnection
*/
export const send = (dataConnection) => {
for (const typed_array of uint8_arrays) {
dataConnection.send(typed_array);
}
};
29 changes: 5 additions & 24 deletions e2e/datachannel/arraybuffers.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,18 @@
import { typed_arrays, typed_array_view, array_buffers } from "../data.js";
import { array_buffers } from "../data.js";
import { expect } from "https://esm.sh/v126/[email protected]/X-dHMvZXhwZWN0/es2021/chai.bundle.mjs";

/** @param {unknown[]} received */
window.check = (received) => {
for (const [i, typed_array] of typed_arrays.entries()) {
expect(received[i]).to.be.an.instanceof(ArrayBuffer);
expect(received[i]).to.deep.equal(typed_array.buffer);
}
export const check = (received) => {
for (const [i, array_buffer] of array_buffers.entries()) {
expect(received[typed_arrays.length + i]).to.be.an.instanceof(ArrayBuffer);
expect(received[typed_arrays.length + i]).to.deep.equal(array_buffer);
}

const received_typed_array_view =
received[typed_arrays.length + array_buffers.length];
expect(new Uint8Array(received_typed_array_view)).to.deep.equal(
typed_array_view,
);
for (const [i, v] of new Uint8Array(received_typed_array_view).entries()) {
expect(v).to.deep.equal(typed_array_view[i]);
expect(received[i]).to.be.an.instanceof(ArrayBuffer);
expect(received[i]).to.deep.equal(array_buffer);
}
};
/**
* @param {import("../peerjs").DataConnection} dataConnection
*/
window.send = (dataConnection) => {
for (const typed_array of typed_arrays) {
dataConnection.send(typed_array);
}
export const send = (dataConnection) => {
for (const array_buffer of array_buffers) {
dataConnection.send(array_buffer);
}
dataConnection.send(typed_array_view);
};

window["connect-btn"].disabled = false;
6 changes: 3 additions & 3 deletions e2e/datachannel/arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { commit_data } from "../data.js";
import { expect } from "https://esm.sh/v126/[email protected]/X-dHMvZXhwZWN0/es2021/chai.bundle.mjs";

/** @param {unknown[]} received */
window.check = (received) => {
export const check = (received) => {
expect(received[1]).to.be.an("array").with.lengthOf(commit_data.length);
expect(received).to.deep.equal([[], commit_data]);
};
/**
* @param {import("../peerjs").DataConnection} dataConnection
*/
window.send = (dataConnection) => {
export const send = (dataConnection) => {
dataConnection.send([]);
dataConnection.send(commit_data);
};
window["connect-btn"].disabled = false;
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import { commit_data } from "../data.js";
import { expect } from "https://esm.sh/v126/[email protected]/X-dHMvZXhwZWN0/es2021/chai.bundle.mjs";

/** @param {unknown[]} received */
window.check = (received) => {
export const check = (received) => {
expect(received).to.deep.equal([[], commit_data.slice(0, 2)]);
};
/**
* @param {import("../peerjs").DataConnection} dataConnection
*/
window.send = (dataConnection) => {
export const send = (dataConnection) => {
dataConnection.send([]);
dataConnection.send(commit_data.slice(0, 2));
};
window["connect-btn"].disabled = false;
16 changes: 16 additions & 0 deletions e2e/datachannel/dates_as_json_string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { dates } from "../data.js";
import { expect } from "https://esm.sh/v126/[email protected]/X-dHMvZXhwZWN0/es2021/chai.bundle.mjs";

/** @param {unknown[]} received */
export const check = (received) => {
console.log(dates.map((date) => date.toString()));
expect(received).to.deep.equal(dates.map((date) => date.toJSON()));
};
/**
* @param {import("../peerjs").DataConnection} dataConnection
*/
export const send = (dataConnection) => {
for (const date of dates) {
dataConnection.send(date);
}
};
16 changes: 16 additions & 0 deletions e2e/datachannel/dates_as_string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { dates } from "../data.js";
import { expect } from "https://esm.sh/v126/[email protected]/X-dHMvZXhwZWN0/es2021/chai.bundle.mjs";

/** @param {unknown[]} received */
export const check = (received) => {
console.log(dates.map((date) => date.toString()));
expect(received).to.deep.equal(dates.map((date) => date.toString()));
};
/**
* @param {import("../peerjs").DataConnection} dataConnection
*/
export const send = (dataConnection) => {
for (const date of dates) {
dataConnection.send(date);
}
};
13 changes: 13 additions & 0 deletions e2e/datachannel/long_string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { long_string } from "../data.js";
import { expect } from "https://esm.sh/v126/[email protected]/X-dHMvZXhwZWN0/es2021/chai.bundle.mjs";

/** @param {unknown[]} received */
export const check = (received) => {
expect(received).to.deep.equal([long_string]);
};
/**
* @param {import("../peerjs").DataConnection} dataConnection
*/
export const send = (dataConnection) => {
dataConnection.send(long_string);
};
5 changes: 2 additions & 3 deletions e2e/datachannel/numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import { numbers } from "../data.js";
import { expect } from "https://esm.sh/v126/[email protected]/X-dHMvZXhwZWN0/es2021/chai.bundle.mjs";

/** @param {unknown[]} received */
window.check = (received) => {
export const check = (received) => {
expect(received).to.deep.equal(numbers);
};
/**
* @param {import("../peerjs").DataConnection} dataConnection
*/
window.send = (dataConnection) => {
export const send = (dataConnection) => {
for (const number of numbers) {
dataConnection.send(number);
}
};
window["connect-btn"].disabled = false;
6 changes: 3 additions & 3 deletions e2e/datachannel/objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { commit_data } from "../data.js";
import { expect } from "https://esm.sh/v126/[email protected]/X-dHMvZXhwZWN0/es2021/chai.bundle.mjs";

/** @param {unknown[]} received */
window.check = (received) => {
export const check = (received) => {
expect(received).to.be.an("array").with.lengthOf(commit_data.length);
expect(received).to.deep.equal(commit_data);
};
/**
* @param {import("../peerjs").DataConnection} dataConnection
*/
window.send = (dataConnection) => {
export const send = (dataConnection) => {
for (const commit of commit_data) {
dataConnection.send(commit);
}
};
window["connect-btn"].disabled = false;
6 changes: 1 addition & 5 deletions e2e/datachannel/serialization.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ <h1>Serialization</h1>
<div id="messages"></div>
<div id="result"></div>
<div id="error-message"></div>
<script src="/dist/peerjs.js"></script>
<!--<script src="https://unpkg.com/[email protected]/dist/peerjs.min.js"></script>-->
<script>
import(window.location.search.substring(6));
</script>
<script src="/dist/peerjs.min.js" type="application/javascript"></script>
<script src="serialization.js" type="module"></script>
</body>
</html>
Loading

0 comments on commit 4cc1c81

Please sign in to comment.