@@ -9,25 +9,53 @@ async function run (input, output, opts = {}) {
9
9
expect ( result . warnings ( ) ) . toHaveLength ( 0 ) ;
10
10
}
11
11
12
- test ( 'sortFiles sorts files by extension alphabetically' , ( ) => {
13
- const files = [
14
- { name : 'file3' , ext : 'c' } ,
15
- { name : 'file1' , ext : 'a' } ,
16
- { name : 'file4' , ext : 'd' } ,
17
- { name : 'file5' , ext : 'd' } ,
18
- { name : 'file2' , ext : 'b' } ,
19
- ] ;
20
- const expectedOrder = [
21
- { name : 'file1' , ext : 'a' } ,
22
- { name : 'file2' , ext : 'b' } ,
23
- { name : 'file3' , ext : 'c' } ,
24
- { name : 'file4' , ext : 'd' } ,
25
- { name : 'file5' , ext : 'd' } ,
26
- ] ;
27
- const sortedFiles = files . sort ( sortFiles ) ;
28
- expect ( sortedFiles ) . toEqual ( expectedOrder ) ;
12
+ describe ( 'sortFiles' , ( ) => {
13
+ it ( 'should sort files based on weights' , ( ) => {
14
+ const files = [
15
+ { name : 'file1' , ext : 'ttf' } ,
16
+ { name : 'file2' , ext : 'woff2' } ,
17
+ { name : 'file3' , ext : 'woff' } ,
18
+ { name : 'file4' , ext : 'otf' } ,
19
+ ] ;
20
+
21
+ const sortedFiles = files . sort ( sortFiles ) ;
22
+
23
+ expect ( sortedFiles ) . toEqual ( [
24
+ { name : 'file2' , ext : 'woff2' } ,
25
+ { name : 'file3' , ext : 'woff' } ,
26
+ { name : 'file1' , ext : 'ttf' } ,
27
+ { name : 'file4' , ext : 'otf' } ,
28
+ ] ) ;
29
+ } ) ;
30
+
31
+ it ( 'should sort files with the same weight based on extension' , ( ) => {
32
+ const files = [
33
+ { name : 'file1' , ext : 'woff' } ,
34
+ { name : 'file2' , ext : 'woff2' } ,
35
+ { name : 'file3' , ext : 'otf' } ,
36
+ { name : 'file4' , ext : 'ttf' } ,
37
+ { name : 'file5' , ext : 'woff2' } ,
38
+ { name : 'file6' , ext : 'ttf' } ,
39
+ { name : 'file7' , ext : 'woff' } ,
40
+ { name : 'file8' , ext : 'otf' } ,
41
+ ] ;
42
+
43
+ const sortedFiles = files . sort ( sortFiles ) ;
44
+
45
+ expect ( sortedFiles ) . toEqual ( [
46
+ { name : 'file2' , ext : 'woff2' } ,
47
+ { name : 'file5' , ext : 'woff2' } ,
48
+ { name : 'file1' , ext : 'woff' } ,
49
+ { name : 'file7' , ext : 'woff' } ,
50
+ { name : 'file4' , ext : 'ttf' } ,
51
+ { name : 'file6' , ext : 'ttf' } ,
52
+ { name : 'file3' , ext : 'otf' } ,
53
+ { name : 'file8' , ext : 'otf' } ,
54
+ ] ) ;
55
+ } ) ;
29
56
} ) ;
30
57
58
+ describe ( 'Generate font-face' , ( ) => {
31
59
it ( 'The console should display a warning message when no font files are found in the given directory' , async ( ) => {
32
60
const result = await postcss ( [ plugin ( { fontsDir : './fonts/empty/' } ) ] ) . process ( '' , { from : undefined } ) ;
33
61
expect ( result . warnings ( ) ) . toHaveLength ( 1 ) ;
@@ -36,7 +64,7 @@ it('The console should display a warning message when no font files are found in
36
64
it ( 'Create default output from files in font folder' , async ( ) => {
37
65
const output = `@font-face {
38
66
font-family: "Prague";
39
- src: local("Prague"), url("/fonts/Prague-Black.woff ") format("woff "), url("/fonts/Prague-Black.woff2 ") format("woff2 ");
67
+ src: local("Prague"), url("/fonts/Prague-Black.woff2 ") format("woff2 "), url("/fonts/Prague-Black.woff ") format("woff ");
40
68
font-weight: 900;
41
69
font-style: normal;
42
70
font-display: swap
@@ -47,7 +75,7 @@ it('Create default output from files in font folder', async () => {
47
75
it ( 'Create output from files in font folder without swap option' , async ( ) => {
48
76
const output = `@font-face {
49
77
font-family: "Prague Special";
50
- src: local("Prague Special"), url("/fonts/PragueSpecial-ExtraLightItalic.ttf ") format("ttf "), url("/fonts/PragueSpecial-ExtraLightItalic.woff") format("woff"), url("/fonts/PragueSpecial-ExtraLightItalic.woff2 ") format("woff2 ");
78
+ src: local("Prague Special"), url("/fonts/PragueSpecial-ExtraLightItalic.woff2 ") format("woff2 "), url("/fonts/PragueSpecial-ExtraLightItalic.woff") format("woff"), url("/fonts/PragueSpecial-ExtraLightItalic.ttf ") format("ttf ");
51
79
font-weight: 200;
52
80
font-style: italic
53
81
}` ;
@@ -57,9 +85,10 @@ it('Create output from files in font folder without swap option', async () => {
57
85
it ( 'Create output from files in font folder without swap and local option' , async ( ) => {
58
86
const output = `@font-face {
59
87
font-family: "Prague Special";
60
- src: url("/fonts/PragueSpecial-ExtraLightItalic.ttf ") format("ttf "), url("/fonts/PragueSpecial-ExtraLightItalic.woff") format("woff"), url("/fonts/PragueSpecial-ExtraLightItalic.woff2 ") format("woff2 ");
88
+ src: url("/fonts/PragueSpecial-ExtraLightItalic.woff2 ") format("woff2 "), url("/fonts/PragueSpecial-ExtraLightItalic.woff") format("woff"), url("/fonts/PragueSpecial-ExtraLightItalic.ttf ") format("ttf ");
61
89
font-weight: 200;
62
90
font-style: italic
63
91
}` ;
64
92
await run ( '' , output , { fontsDir : './fonts/PragueSpecial/' , swap : false , local : false } ) ;
65
93
} ) ;
94
+ } ) ;
0 commit comments