|
1 | 1 | import HtmlWebpackPlugin from 'html-webpack-plugin'; |
2 | 2 | import { existsSync, rmSync } from 'node:fs'; |
3 | 3 | import { join } from 'node:path'; |
| 4 | +import type { TemplateOptions } from '../src/types.js'; |
4 | 5 | import { getDirname, testWebpackPlugin } from './testUtils.js'; |
5 | 6 |
|
6 | 7 | const fixtureCwd = getDirname(import.meta.url, './fixtures/loader'); |
@@ -35,13 +36,63 @@ describe('htmlPluginLoader', () => { |
35 | 36 | rel: 'icon', |
36 | 37 | attributes: {}, |
37 | 38 | }, |
38 | | - }, |
| 39 | + headMetaTags: [ |
| 40 | + '<meta name="description" content="default description">', |
| 41 | + ], |
| 42 | + headStyles: [ |
| 43 | + { |
| 44 | + id: 'style1', |
| 45 | + href: 'style1.css', |
| 46 | + position: 'beginning', |
| 47 | + }, |
| 48 | + ], |
| 49 | + headInlineStyles: [ |
| 50 | + { |
| 51 | + id: 'style1', |
| 52 | + content: 'p {}', |
| 53 | + position: 'beginning', |
| 54 | + }, |
| 55 | + ], |
| 56 | + headScripts: [ |
| 57 | + { |
| 58 | + id: 'script1', |
| 59 | + src: 'script1.js', |
| 60 | + position: 'beginning', |
| 61 | + }, |
| 62 | + ], |
| 63 | + headInlineScripts: [ |
| 64 | + { |
| 65 | + id: 'script2', |
| 66 | + content: 'console.log("script2")', |
| 67 | + position: 'end', |
| 68 | + }, |
| 69 | + ], |
| 70 | + bodyScripts: [ |
| 71 | + { |
| 72 | + id: 'script3', |
| 73 | + src: 'script3.js', |
| 74 | + position: 'end', |
| 75 | + }, |
| 76 | + ], |
| 77 | + } satisfies TemplateOptions, |
39 | 78 | }), |
40 | 79 | ], |
41 | 80 | }, |
42 | 81 | fixtureDist |
43 | 82 | ); |
44 | 83 | expect(result).toContain('<title>default title</title>'); |
45 | 84 | expect(result).toContain('<link rel="icon" href="default favicon">'); |
| 85 | + expect(result).toContain( |
| 86 | + '<meta name="description" content="default description">' |
| 87 | + ); |
| 88 | + expect(result).toContain('<style id="style1">p {}</style>'); |
| 89 | + expect(result).toContain( |
| 90 | + '<link rel="stylesheet" href="style1.css" id="style1">' |
| 91 | + ); |
| 92 | + expect(result).toContain('<script id="script1" src="script1.js"></script>'); |
| 93 | + expect(result).toContain( |
| 94 | + '<script id="script2">console.log("script2")</script>' |
| 95 | + ); |
| 96 | + expect(result).toContain('<script id="script3" src="script3.js"></script>'); |
46 | 97 | }); |
47 | 98 | }); |
0 commit comments