files.js 767 B

12345678910111213141516171819202122232425
  1. import { commit_data } from "../data.js";
  2. import { expect } from "https://esm.sh/v126/chai@4.3.7/X-dHMvZXhwZWN0/es2021/chai.bundle.mjs";
  3. const Encoder = new TextEncoder();
  4. /** @param {unknown[]} received */
  5. export const check = (received) => {
  6. expect(received).to.be.an("array").with.lengthOf(commit_data.length);
  7. const commits_as_arraybuffer = commit_data.map(
  8. (blob) => Encoder.encode(JSON.stringify(blob)).buffer,
  9. );
  10. expect(received).to.deep.equal(commits_as_arraybuffer);
  11. };
  12. /**
  13. * @param {import("../peerjs").DataConnection} dataConnection
  14. */
  15. export const send = async (dataConnection) => {
  16. for (const commit of commit_data) {
  17. await dataConnection.send(
  18. new File([JSON.stringify(commit)], "commit.txt", {
  19. type: "dummy/data",
  20. }),
  21. );
  22. }
  23. };