Download internal/node-utils/src/__tests__/hash.test.ts from binhugg3/admin: direct link, hf CLI and curl.
- Browser
- Download file 1.72 kB
-
https://huggingface.co/spaces/binhugg3/admin/resolve/main/internal/node-utils/src/__tests__/hash.test.ts
- Command line
-
hf download hf://spaces/binhugg3/admin/internal/node-utils/src/__tests__/hash.test.ts
-
curl -L -o hash.test.ts https://huggingface.co/spaces/binhugg3/admin/resolve/main/internal/node-utils/src/__tests__/hash.test.ts
1.72 kB
| import { createHash } from 'node:crypto'; | |
| import { describe, expect, it } from 'vitest'; | |
| import { generatorContentHash } from '../hash'; | |
| describe('generatorContentHash', () => { | |
| it('should generate an MD5 hash for the content', () => { | |
| const content = 'example content'; | |
| const expectedHash = createHash('md5') | |
| .update(content, 'utf8') | |
| .digest('hex'); | |
| const actualHash = generatorContentHash(content); | |
| expect(actualHash).toBe(expectedHash); | |
| }); | |
| it('should generate an MD5 hash with specified length', () => { | |
| const content = 'example content'; | |
| const hashLength = 10; | |
| const generatedHash = generatorContentHash(content, hashLength); | |
| expect(generatedHash).toHaveLength(hashLength); | |
| }); | |
| it('should correctly generate the hash with specified length', () => { | |
| const content = 'example content'; | |
| const hashLength = 8; | |
| const expectedHash = createHash('md5') | |
| .update(content, 'utf8') | |
| .digest('hex') | |
| .slice(0, hashLength); | |
| const generatedHash = generatorContentHash(content, hashLength); | |
| expect(generatedHash).toBe(expectedHash); | |
| }); | |
| it('should return full hash if hash length parameter is not provided', () => { | |
| const content = 'example content'; | |
| const expectedHash = createHash('md5') | |
| .update(content, 'utf8') | |
| .digest('hex'); | |
| const actualHash = generatorContentHash(content); | |
| expect(actualHash).toBe(expectedHash); | |
| }); | |
| it('should handle empty content', () => { | |
| const content = ''; | |
| const expectedHash = createHash('md5') | |
| .update(content, 'utf8') | |
| .digest('hex'); | |
| const actualHash = generatorContentHash(content); | |
| expect(actualHash).toBe(expectedHash); | |
| }); | |
| }); | |