1+ import path from 'path'
2+ import fs from 'fs'
3+ import { CssToHtml } from '../cssToHtml.js'
4+ import assert from 'assert'
5+
6+
7+ const htmlFilePath = path . resolve ( import . meta. dirname + '/helpers/test.html' )
8+ const cssFilePath = path . resolve ( import . meta. dirname + '/helpers/test.css' )
9+
10+ new CssToHtml ( {
11+ css : `div {}` ,
12+ write : { in : htmlFilePath }
13+ } )
14+ assert . equal (
15+ fs . readFileSync ( htmlFilePath , 'utf8' ) , '<div></div>\n' ,
16+ 'Writing code to a file should work.'
17+ )
18+
19+
20+ fs . writeFileSync ( htmlFilePath ,
21+ `<some-html-content>
22+ </some-html-content>
23+ ` )
24+ new CssToHtml ( {
25+ css : `div {}` ,
26+ write : {
27+ in : htmlFilePath ,
28+ after : '<some-html-content>'
29+ }
30+ } )
31+ assert . equal (
32+ fs . readFileSync ( htmlFilePath , 'utf8' ) ,
33+ `<some-html-content>
34+ <div></div>
35+ ` ,
36+ 'The code must be written after certain content.'
37+ )
38+
39+
40+ fs . writeFileSync ( htmlFilePath ,
41+ `<some-html-content>
42+ </some-html-content>
43+ ` )
44+ new CssToHtml ( {
45+ css : `div {}` ,
46+ write : {
47+ in : htmlFilePath ,
48+ after : '<some-html-content>' ,
49+ before : '</some-html-content>'
50+ }
51+ } )
52+ assert . equal (
53+ fs . readFileSync ( htmlFilePath , 'utf8' ) ,
54+ `<some-html-content>
55+ <div></div>
56+ </some-html-content>
57+ ` ,
58+ 'The code must be written before and after certain content.'
59+ )
60+
61+
62+ fs . writeFileSync ( cssFilePath , '' )
63+ assert . equal (
64+ new CssToHtml ( {
65+ css : fs . readFileSync ( cssFilePath , 'utf8' ) ,
66+ } ) . outputHTML ,
67+
68+ undefined ,
69+
70+ 'Empty CSS should not be processed.'
71+ )
72+
73+
74+ fs . writeFileSync ( cssFilePath , 'div {} div span { /* @inside text */ }' )
75+ assert . equal (
76+ new CssToHtml ( {
77+ css : fs . readFileSync ( cssFilePath , 'utf8' ) ,
78+ } ) . outputHTML ,
79+
80+ `<div>
81+ <span>text</span>
82+ </div>
83+ ` ,
84+
85+ 'The code from the CSS file must be processed.'
86+ )
87+
88+
89+
90+ fs . writeFileSync ( htmlFilePath , '' )
91+ fs . writeFileSync ( cssFilePath , '' )
0 commit comments