Skip to content

Commit 6901c5f

Browse files
Copilotxenova
andcommitted
Add comprehensive tests for package exports and update Jest config
Co-authored-by: xenova <[email protected]>
1 parent 9c8b4ac commit 6901c5f

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

jest.config.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ export default {
178178

179179
// Module name mapper for path aliases
180180
moduleNameMapper: {
181+
"^@huggingface/tokenizers$": "<rootDir>/src/index.ts",
182+
"^@huggingface/tokenizers/pre-tokenizers$": "<rootDir>/src/pre-tokenizers.ts",
183+
"^@huggingface/tokenizers/models$": "<rootDir>/src/models.ts",
184+
"^@huggingface/tokenizers/normalizers$": "<rootDir>/src/normalizers.ts",
185+
"^@huggingface/tokenizers/decoders$": "<rootDir>/src/decoders.ts",
186+
"^@huggingface/tokenizers/post-processors$": "<rootDir>/src/post-processors.ts",
181187
"^@utils$": "<rootDir>/src/utils/index.ts",
182188
"^@utils/(.*)$": "<rootDir>/src/utils/$1",
183189
"^@core/(.*)$": "<rootDir>/src/core/$1",

tests/package-exports.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Integration test to verify package.json exports work correctly
2+
// This simulates how a user would import from the published package
3+
4+
import { Tokenizer } from "@huggingface/tokenizers";
5+
import type { Encoding } from "@huggingface/tokenizers";
6+
import { Metaspace, Whitespace } from "@huggingface/tokenizers/pre-tokenizers";
7+
import { BPE } from "@huggingface/tokenizers/models";
8+
import { Lowercase, StripAccents } from "@huggingface/tokenizers/normalizers";
9+
import { BPEDecoder } from "@huggingface/tokenizers/decoders";
10+
import { TemplateProcessing } from "@huggingface/tokenizers/post-processors";
11+
12+
describe("Package exports integration", () => {
13+
it("should import main exports", () => {
14+
expect(Tokenizer).toBeDefined();
15+
16+
// Encoding is a type-only export
17+
const enc: Encoding = {
18+
ids: [1, 2, 3],
19+
tokens: ["a", "b", "c"],
20+
attention_mask: [1, 1, 1],
21+
};
22+
expect(enc.ids).toHaveLength(3);
23+
});
24+
25+
it("should import pre-tokenizers", () => {
26+
expect(Metaspace).toBeDefined();
27+
expect(Whitespace).toBeDefined();
28+
});
29+
30+
it("should import models", () => {
31+
expect(BPE).toBeDefined();
32+
});
33+
34+
it("should import normalizers", () => {
35+
expect(Lowercase).toBeDefined();
36+
expect(StripAccents).toBeDefined();
37+
});
38+
39+
it("should import decoders", () => {
40+
expect(BPEDecoder).toBeDefined();
41+
});
42+
43+
it("should import post-processors", () => {
44+
expect(TemplateProcessing).toBeDefined();
45+
});
46+
});

0 commit comments

Comments
 (0)