Coverage for src/tests/frontend/test_manifest.py: 100%

23 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2024-01-01 00:00 +0000

1"""Module for testing the Manifest class.""" 

2 

3from kwai_api.frontend.manifest import Manifest 

4 

5 

6def test_load_manifest_from_string(): 

7 """Test loading the manifest from a string.""" 

8 manifest = Manifest.load_from_string( 

9 """ 

10 { 

11 "src/index.ts": { 

12 "isEntry": true, 

13 "file": "assets/index-8a61960c.js", 

14 "src": "src/index.ts" 

15 } 

16 } 

17 """ 

18 ) 

19 assert len(manifest.chunks) > 0, "There should be a chunk in the manifest." 

20 assert manifest.has_chunk("src/index.ts") is not None, "The chunk should exist." 

21 assert manifest.get_chunk("src/index.ts") is not None, "The chunk should exist." 

22 

23 

24def test_chunks(manifest: Manifest): 

25 """Test the chunks property.""" 

26 chunks = manifest.chunks 

27 assert len(chunks) > 0, "There should be chunks in the manifest." 

28 

29 

30def test_has_chunk(manifest: Manifest): 

31 """Test the has_chunk method.""" 

32 assert manifest.has_chunk("src/index.ts") is True, "The chunk should exist." 

33 assert manifest.has_chunk("images/hero.jpg") is True, "The chunk should exist." 

34 

35 

36def test_chunk(manifest: Manifest): 

37 """Test the get_chunk method.""" 

38 chunk = manifest.get_chunk("src/index.ts") 

39 assert chunk is not None, "The chunk should exist." 

40 assert chunk.src == "src/index.ts", "The src should be 'src/index.ts'" 

41 assert chunk.file == "assets/index-533fa9ea.js" 

42 assert len(chunk.imports) > 0 

43 assert chunk.entry is True 

44 assert len(chunk.assets) > 0 

45 assert len(chunk.css) > 0 

46 assert len(chunk.dynamic_imports) > 0 

47 assert chunk.dynamic_entry is False