Skip to content

Commit 9458dfc

Browse files
committed
port tests to postcss-tape
1 parent eca82b9 commit 9458dfc

37 files changed

+527
-410
lines changed

.github/workflows/test.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: test
2+
on:
3+
push:
4+
branches:
5+
- 'main'
6+
pull_request:
7+
workflow_dispatch:
8+
9+
defaults:
10+
run:
11+
shell: bash
12+
13+
jobs:
14+
test:
15+
runs-on: ${{ matrix.os }}
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
os: [ubuntu-latest]
20+
node: [18, 'lts/*']
21+
steps:
22+
- uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 1
25+
- uses: actions/setup-node@v4
26+
with:
27+
node-version: ${{ matrix.node }}
28+
29+
- name: npm ci
30+
run: |
31+
npm ci
32+
33+
- name: test
34+
run: npm run test

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ node_modules/
22
.vscode/
33
npm-debug.log
44
test/fontface.js.result
5+
*.result.css
6+
*.result.css.map

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
- Fix support for `postcss-load-config` [#102](https://github.com/csstools/postcss-font-magician/pull/102)
66
- Fix repo and homepage urls [#101](https://github.com/csstools/postcss-font-magician/pull/101)
77
- Fix typo in readme [#87](https://github.com/csstools/postcss-font-magician/pull/87)
8+
- Fix source maps
9+
- Fix output path for `async` option,this is now relative to the process.
810

911

1012
## 3.0.0 (2020-10-03)

index.js

+14-10
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ function generateFont(postcss, node, family, fontFaceRules, options, defaultOpti
191191
fontFaceRule.append(
192192
postcss.decl({
193193
prop: 'font-stretch',
194-
value: options.stretch
194+
value: options.stretch,
195+
source: node.source
195196
})
196197
);
197198
}
@@ -201,7 +202,8 @@ function generateFont(postcss, node, family, fontFaceRules, options, defaultOpti
201202
fontFaceRule.append(
202203
postcss.decl({
203204
prop: 'font-display',
204-
value: options.display
205+
value: options.display,
206+
source: node.source
205207
})
206208
);
207209
}
@@ -213,7 +215,8 @@ function generateFont(postcss, node, family, fontFaceRules, options, defaultOpti
213215
fontFaceRule.clone().append(
214216
postcss.decl({
215217
prop: 'unicode-range',
216-
value: range
218+
value: range,
219+
source: node.source
217220
})
218221
)
219222
);
@@ -388,10 +391,8 @@ function plugin(initialOptions) {
388391
// set the font family
389392
const family = getQuoteless(decl.value);
390393

391-
if (!isRuleIgnored(decl)) {
392-
// set the font family as declared
393-
fontFamiliesDeclared[family] = true;
394-
}
394+
// set the font family as declared
395+
fontFamiliesDeclared[family] = true;
395396
});
396397
});
397398

@@ -401,7 +402,7 @@ function plugin(initialOptions) {
401402
const family = getFirstFontFamily(list, decl);
402403

403404
// if the font family is not declared
404-
if (!fontFamiliesDeclared[family]) {
405+
if (!fontFamiliesDeclared[family] && !isRuleIgnored(decl)) {
405406
// set the font family as declared
406407
fontFamiliesDeclared[family] = true;
407408

@@ -432,7 +433,9 @@ function plugin(initialOptions) {
432433
});
433434

434435
if (fontFaces) {
435-
const asyncPath = getRelativePath(root.source.input.file, options.async);
436+
const asyncPath = path.resolve(process.cwd(), options.async)
437+
438+
console.log(asyncPath);
436439

437440
const asyncJs =
438441
'(function(){' +
@@ -449,6 +452,7 @@ function plugin(initialOptions) {
449452
};
450453
}
451454

455+
plugin.postcss = true;
456+
452457
// set plugin
453458
module.exports = plugin;
454-
module.exports.postcss = true;

test/_tape.cjs

+153
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ postcssTape(plugin)({
1111
'google-fonts': {
1212
message: "supports google fonts",
1313
},
14+
'google-fonts-once': {
15+
message: "adds google fonts once",
16+
},
1417
'font-display-option': {
1518
message: "supports font-display option",
1619
options: {
@@ -28,4 +31,154 @@ postcssTape(plugin)({
2831
}
2932
},
3033
},
34+
'custom-google-fonts:with-default-formats': {
35+
message: "supports custom google fonts (default formats)",
36+
options: {
37+
variants: {
38+
'Open Sans': {
39+
'300': []
40+
}
41+
}
42+
},
43+
},
44+
'custom-google-fonts:unicode-range': {
45+
message: "supports custom unicode-range",
46+
options: {
47+
variants: {
48+
'Open Sans': {
49+
'300': [
50+
'woff',
51+
'U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF'
52+
],
53+
'400 italic': ['eot woff']
54+
}
55+
}
56+
},
57+
},
58+
'custom-google-fonts:unicode-range-google-subsets': {
59+
message: "supports custom unicode-range (google subsets)",
60+
options: {
61+
variants: {
62+
'Open Sans': {
63+
'300': [
64+
'woff2',
65+
'cyrillic, latin-ext'
66+
],
67+
'400 italic': ['woff2', 'vietnamese']
68+
}
69+
}
70+
},
71+
},
72+
'custom-google-fonts:custom-font-stretch-omit-normal': {
73+
message: "supports custom unicode-range (google subsets)",
74+
options: {
75+
variants: {
76+
'Open Sans': {
77+
'300 condensed': ['woff'],
78+
'400 italic': ['eot woff']
79+
}
80+
}
81+
},
82+
},
83+
'custom-google-fonts:custom-font-stretch-with-normal': {
84+
message: "supports custom unicode-range (google subsets)",
85+
options: {
86+
variants: {
87+
'Open Sans': {
88+
'300 normal condensed': ['woff'],
89+
'400 italic': ['eot woff']
90+
}
91+
}
92+
},
93+
},
94+
'custom-google-fonts:custom-font-stretch-with-italic': {
95+
message: "supports custom unicode-range (google subsets)",
96+
options: {
97+
variants: {
98+
'Open Sans': {
99+
'300': ['woff'],
100+
'400 italic ultra-condensed': ['eot woff']
101+
}
102+
}
103+
},
104+
},
105+
'ignore': {
106+
message: "supports ignoring a declaration",
107+
},
108+
'hosted-fonts': {
109+
message: "supports hosted fonts",
110+
options: {
111+
hosted: ['./test/fonts']
112+
}
113+
},
114+
'hosted-fonts:custom-font-path': {
115+
message: "supports hosted fonts",
116+
options: {
117+
hosted: ['./test/fonts', '/some/custom/path']
118+
},
119+
},
120+
'preserves-existing-font-face': {
121+
message: "does not overwrite existing @font-face rules",
122+
},
123+
'foundry-exclusion': {
124+
message: "support foundry exclusion",
125+
options: {
126+
foundries: 'hosted'
127+
},
128+
},
129+
'font-aliasing': {
130+
message: "support font aliasing",
131+
options: {
132+
aliases: {
133+
body: 'Open Sans'
134+
},
135+
variants: {
136+
body: {
137+
'400': ['woff']
138+
}
139+
}
140+
},
141+
},
142+
'custom-fonts': {
143+
message: "support custom fonts",
144+
options: {
145+
custom: {
146+
body: {
147+
variants: {
148+
normal: {
149+
400: {
150+
url: {
151+
woff2: 'path/to/my-body-font.woff2'
152+
}
153+
}
154+
}
155+
}
156+
}
157+
}
158+
},
159+
},
160+
'async-font-loading': {
161+
message: "support async font loading",
162+
options: {
163+
async: './test/async-font-loading.js'
164+
},
165+
},
166+
'protocol:http': {
167+
message: "supports custom configuration protocol (http)",
168+
options: {
169+
protocol: 'http:'
170+
},
171+
},
172+
'protocol:https': {
173+
message: "supports custom configuration protocol (https)",
174+
options: {
175+
protocol: 'https:'
176+
},
177+
},
178+
'material-icons': {
179+
message: "supports Material Icons",
180+
options: {
181+
protocol: 'https:'
182+
},
183+
},
31184
});

test/async-font-loading.css

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
a {
2+
font-family: Alice
3+
}
4+
5+
b {}

test/async-font-loading.expect.css

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
a {
2+
font-family: Alice
3+
}
4+
5+
b {}

test/async-font-loading.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/custom-fonts.css

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
a {
2+
font-family: body
3+
}
4+
5+
b {}

test/custom-fonts.expect.css

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@font-face {
2+
font-family: body;
3+
font-style: normal;
4+
font-weight: 400;
5+
src: url(path/to/my-body-font.woff2) format("woff2")
6+
}
7+
8+
a {
9+
font-family: body
10+
}
11+
12+
b {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
@font-face {
2+
font-family: "Open Sans";
3+
font-style: normal;
4+
font-weight: 300;
5+
src: url(//fonts.gstatic.com/s/opensans/v36/memSYaGs126MiZpBA-UvWbX2vVnXBbObj2OVZyOOSr4dVJWUgsiH0B4uaVQ.woff) format("woff");
6+
font-stretch: condensed
7+
}
8+
9+
@font-face {
10+
font-family: "Open Sans";
11+
font-style: italic;
12+
font-weight: 400;
13+
src: url(//fonts.gstatic.com/s/opensans/v36/memQYaGs126MiZpBA-UFUIcVXSCEkx2cmqvXlWq8tWZ0Pw86hd0Rk8ZkWV4exA.eot?#) format("eot"),url(//fonts.gstatic.com/s/opensans/v36/memQYaGs126MiZpBA-UFUIcVXSCEkx2cmqvXlWq8tWZ0Pw86hd0Rk8ZkWV4exg.woff) format("woff")
14+
}
15+
16+
a {
17+
font-family: "Open Sans"
18+
}
19+
20+
b {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
@font-face {
2+
font-family: "Open Sans";
3+
font-style: normal;
4+
font-weight: 300;
5+
src: url(//fonts.gstatic.com/s/opensans/v36/memSYaGs126MiZpBA-UvWbX2vVnXBbObj2OVZyOOSr4dVJWUgsiH0B4uaVQ.woff) format("woff")
6+
}
7+
8+
@font-face {
9+
font-family: "Open Sans";
10+
font-style: italic;
11+
font-weight: 400;
12+
src: url(//fonts.gstatic.com/s/opensans/v36/memQYaGs126MiZpBA-UFUIcVXSCEkx2cmqvXlWq8tWZ0Pw86hd0Rk8ZkWV4exA.eot?#) format("eot"),url(//fonts.gstatic.com/s/opensans/v36/memQYaGs126MiZpBA-UFUIcVXSCEkx2cmqvXlWq8tWZ0Pw86hd0Rk8ZkWV4exg.woff) format("woff");
13+
font-stretch: ultra-condensed
14+
}
15+
16+
a {
17+
font-family: "Open Sans"
18+
}
19+
20+
b {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
@font-face {
2+
font-family: "Open Sans";
3+
font-style: normal;
4+
font-weight: 300;
5+
src: url(//fonts.gstatic.com/s/opensans/v36/memSYaGs126MiZpBA-UvWbX2vVnXBbObj2OVZyOOSr4dVJWUgsiH0B4uaVQ.woff) format("woff");
6+
font-stretch: condensed
7+
}
8+
9+
@font-face {
10+
font-family: "Open Sans";
11+
font-style: italic;
12+
font-weight: 400;
13+
src: url(//fonts.gstatic.com/s/opensans/v36/memQYaGs126MiZpBA-UFUIcVXSCEkx2cmqvXlWq8tWZ0Pw86hd0Rk8ZkWV4exA.eot?#) format("eot"),url(//fonts.gstatic.com/s/opensans/v36/memQYaGs126MiZpBA-UFUIcVXSCEkx2cmqvXlWq8tWZ0Pw86hd0Rk8ZkWV4exg.woff) format("woff")
14+
}
15+
16+
a {
17+
font-family: "Open Sans"
18+
}
19+
20+
b {}

0 commit comments

Comments
 (0)