Skip to content

Commit

Permalink
✅ Add E2E test for sha256 (#685)
Browse files Browse the repository at this point in the history
cc @vvmnnnkv @ngxson 

Follow up to #684
  • Loading branch information
coyotte508 committed May 18, 2024
1 parent adec3de commit 6396f72
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ jobs:
run: |
pnpm i --ignore-workspace --registry http://localhost:4874/
pnpm build
pnpm run test:browser
- uses: denoland/setup-deno@v1
with:
Expand Down
1 change: 1 addition & 0 deletions e2e/svelte/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ node_modules
!.env.example
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
pnpm-lock.yaml
19 changes: 12 additions & 7 deletions e2e/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,30 @@
"name": "myapp",
"version": "0.0.1",
"private": true,
"packageManager": "pnpm@8.10.5",
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"test:browser": "vitest run --browser.name=chrome --browser.headless"
},
"devDependencies": {
"@sveltejs/adapter-auto": "^2.0.0",
"@sveltejs/kit": "^1.5.0",
"svelte": "^3.54.0",
"@sveltejs/adapter-auto": "^3.2.0",
"@sveltejs/kit": "^2.5.9",
"@sveltejs/vite-plugin-svelte": "^3.0.0",
"@vitest/browser": "^1.6.0",
"svelte": "^4.2.17",
"svelte-check": "^3.0.1",
"tslib": "^2.4.1",
"typescript": "^5.0.0",
"vite": "^4.3.0"
"vite": "^5.2.11",
"vitest": "^1.6.0"
},
"type": "module",
"dependencies": {
"@huggingface/inference": "*",
"@huggingface/hub": "*"
"@huggingface/hub": "*",
"@huggingface/inference": "*"
}
}
37 changes: 37 additions & 0 deletions e2e/svelte/src/test.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { assert, it, describe } from "vitest";
import { __internal_sha256 } from "@huggingface/hub";

const lfsContent = "0123456789".repeat(1_000_000);

describe("hub", () => {
it("should compute sha256 with webworker", async function () {
const blob = new Blob([lfsContent]);

const iterator = __internal_sha256(blob, { useWebWorker: { minSize: 1 } });
// Get return value of the generator
const values: number[] = [];
while (1) {
const { done, value } = await iterator.next();
if (done) {
assert.strictEqual(value, "d52fcc26b48dbd4d79b125eb0a29b803ade07613c67ac7c6f2751aefef008486");

const builtInResult = await crypto.subtle.digest("SHA-256", await blob.arrayBuffer());
const hex =
builtInResult instanceof ArrayBuffer
? new Uint8Array(builtInResult).reduce((acc, i) => acc + i.toString(16).padStart(2, "0"), "")
: builtInResult;
assert.strictEqual(hex, "d52fcc26b48dbd4d79b125eb0a29b803ade07613c67ac7c6f2751aefef008486");
break;
}

if (typeof value === "number") {
values.push(value);
}
}

// Check that we received progress values, which should happen with a webworker
assert(values.length > 2);
assert.strictEqual(values[0], 0);
assert.strictEqual(values[values.length - 1], 1);
}, 60_000);
});
4 changes: 2 additions & 2 deletions e2e/svelte/svelte.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import adapter from "@sveltejs/adapter-auto";
import { vitePreprocess } from "@sveltejs/kit/vite";
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";

/** @type {import('@sveltejs/kit').Config} */
const config = {
Expand All @@ -9,7 +9,7 @@ const config = {

kit: {
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
// If your environment is not supported or you settled on a specific environment, switch out the adapter.
// If your environment is not supported, or you settled on a specific environment, switch out the adapter.
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
adapter: adapter(),
},
Expand Down

0 comments on commit 6396f72

Please sign in to comment.