Skip to content

Commit

Permalink
test wav/mp4 generation
Browse files Browse the repository at this point in the history
  • Loading branch information
SpiralP committed Dec 14, 2024
1 parent 14b7bd2 commit a83196c
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 22 deletions.
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 36 additions & 15 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
};
chatsounds-cli = chatsounds-cli-repo.outputs.packages.${system}.default;

hl1-msgpack = pkgs.fetchurl {
url = "https://raw.githubusercontent.com/PAC3-Server/chatsounds-valve-games/HEAD/hl1/list.msgpack";
hash = "sha256-ArdqCFv0wjiElqp6cwRZA/iFuaALr2silJh3STBgCl8=";
};
hl1-test-sound = pkgs.fetchurl {
url = "https://raw.githubusercontent.com/PAC3-Server/chatsounds-valve-games/HEAD/hl1/scientist/ah%20hello%20gordon%20freeman%20its%20good%20to%20see%20you.ogg";
hash = "sha256-QHHEXW18p2dtH/4ph0XGLZ5uvVokBQf+Njce37QWXnc=";
};

# use FC_DEBUG=1024 when running to debug what config files are loaded
fontconfig = pkgs.runCommand "fontconfig"
{
Expand Down Expand Up @@ -54,13 +63,13 @@

nativeBuildInputs = (with pkgs; [
# for tests
chatsounds-cli
ffmpeg
procps
])
++ (if dev then
(wasm.nativeBuildInputs ++ (with pkgs; [
chatsounds-cli
clippy
ffmpeg
rust-analyzer
(rustfmt.override { asNightly = true; })
])) else [ ]);
Expand All @@ -85,19 +94,31 @@
FONTCONFIG_FILE = "${fontconfig.out}/fonts.conf";
FONTCONFIG_PATH = "${fontconfig.out}/";
doCheck = true;
# preCheck = ''
# # fix for:
# # Failed to launch the browser process!
# # chrome_crashpad_handler: --database is required
# export HOME="$TMPDIR"

# # fix for missing fonts
# mkdir -vp "$HOME/.config/fontconfig"
# ln -vs '${pkgs.fontconfig.out}/etc/fonts/conf.d' "$HOME/.config/fontconfig/conf.d"
# cat '${pkgs.fontconfig.out}/etc/fonts/fonts.conf' \
# | ${lib.getExe pkgs.sd} --fixed-strings '${pkgs.dejavu_fonts.minimal}' '${pkgs.noto-fonts}' \
# > "$HOME/.config/fontconfig/fonts.conf"
# '';
preCheck =
let
cache-path = (fetched:
builtins.concatStringsSep "/" (
[ "chatsounds" ] ++
builtins.match "(..)(.+)" (
builtins.hashString "sha256" (
builtins.replaceStrings [ "%20" ] [ " " ] fetched.url
)
)
)
);
in
''
mkdir -vp \
"$(dirname ${cache-path hl1-msgpack})" \
"$(dirname ${cache-path hl1-test-sound})"
cp -v ${hl1-msgpack} "${cache-path hl1-msgpack}"
cp -v ${hl1-test-sound} "${cache-path hl1-test-sound}"
stat ${cache-path hl1-msgpack}
stat ${cache-path hl1-test-sound}
chatsounds-cli 'search ah hello gordon freeman its good to see you' | grep 'ah hello gordon freeman its good to see you'
chatsounds-cli 'ah hello gordon freeman its good to see you'
ln -vs ../chatsounds web/chatsounds
'';
checkPhase = ''
runHook preCheck
npm run test
Expand Down
35 changes: 31 additions & 4 deletions web/__tests__/end-to-end.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@ describe("end-to-end", () => {
dumpio: true,
});
page = await browser.newPage();
await page.emulateMediaFeatures([
{ name: "prefers-color-scheme", value: "dark" },
]);
});
afterAll(async () => {
await page?.close();
await browser?.close();
});

it("loads page", async () => {
await page.emulateMediaFeatures([
{ name: "prefers-color-scheme", value: "dark" },
]);
await page.goto("http://localhost:8080", {
const response = await page.goto("http://localhost:8080", {
waitUntil: "networkidle0",
});
expect(response?.ok()).toBe(true);

expect(Buffer.from(await page.screenshot())).toMatchImageSnapshot();
});
Expand All @@ -41,4 +42,30 @@ describe("end-to-end", () => {

expect(Buffer.from(await page.screenshot())).toMatchImageSnapshot();
}, 35000);

it("can give wav file", async () => {
const response = await page.goto(
"http://localhost:8080/?ah-hello-gordon-freeman-its-good-to-see-you.wav",
{ waitUntil: "networkidle0" },
);
console.log(response);
expect(response?.ok()).toBe(true);

const headers = response?.headers();
expect(headers).toHaveProperty("content-type", "audio/wav");
expect(headers).toHaveProperty("content-length", "612696");
});

it("can give mp4 file", async () => {
const response = await page.goto(
"http://localhost:8080/?ah-hello-gordon-freeman-its-good-to-see-you.mp4",
{ waitUntil: "networkidle0" },
);
console.log(response);
expect(response?.ok()).toBe(true);

const headers = response?.headers();
expect(headers).toHaveProperty("content-type", "video/mp4");
expect(headers).toHaveProperty("content-length", "61007");
});
});

0 comments on commit a83196c

Please sign in to comment.