-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
357 additions
and
344 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,347 @@ | ||
/* global describe, it */ | ||
var postcss = require('postcss'); | ||
var expect = require('chai').expect; | ||
|
||
var plugin = require('../'); | ||
|
||
var test = function(input, output, opts, done) { | ||
postcss([plugin(opts)]) | ||
.process(input) | ||
.then(function(result) { | ||
result.root.walkAtRules('font-face', function(rule) { | ||
rule.walkDecls(function(decl) { | ||
expect(typeof decl.value).to.eql('string'); | ||
}); | ||
}); | ||
|
||
expect(result.css).to.eql(output); | ||
|
||
expect(result.warnings()).to.be.empty; | ||
|
||
done(); | ||
}) | ||
.catch(function(error) { | ||
done(error); | ||
}); | ||
}; | ||
|
||
describe('postcss-font-magician', function() { | ||
it('supports bootstrap fonts', function(done) { | ||
test( | ||
'a{font-family:monospace}b{}', | ||
|
||
'@font-face{font-family:monospace;font-style:italic;font-weight:400;src:local("Menlo Italic"),local(Menlo-Italic),local("Consolas Italic"),local(Consolas-Italic),local("Courier New Italic")}' + | ||
'@font-face{font-family:monospace;font-style:italic;font-weight:700;src:local("Menlo Bold Italic"),local(Menlo-BoldItalic),local(Monaco),local("Consolas Bold Italic"),local(Consolas-BoldItalic),local("Courier New Bold Italic")}' + | ||
'@font-face{font-family:monospace;font-style:normal;font-weight:400;src:local("Menlo Regular"),local(Menlo-Regular),local(Monaco),local(Consolas),local("Courier New")}' + | ||
'@font-face{font-family:monospace;font-style:normal;font-weight:700;src:local("Menlo Bold"),local(Menlo-Bold),local(Monaco),local("Consolas Bold"),local(Consolas-Bold),local("Courier New Bold")}' + | ||
'a{font-family:monospace}b{}', | ||
|
||
{}, | ||
done | ||
); | ||
}); | ||
|
||
it('adds bootstrap fonts once', function(done) { | ||
test( | ||
'a{font-family:monospace}b{font-family:monospace}', | ||
|
||
'@font-face{font-family:monospace;font-style:italic;font-weight:400;src:local("Menlo Italic"),local(Menlo-Italic),local("Consolas Italic"),local(Consolas-Italic),local("Courier New Italic")}' + | ||
'@font-face{font-family:monospace;font-style:italic;font-weight:700;src:local("Menlo Bold Italic"),local(Menlo-BoldItalic),local(Monaco),local("Consolas Bold Italic"),local(Consolas-BoldItalic),local("Courier New Bold Italic")}' + | ||
'@font-face{font-family:monospace;font-style:normal;font-weight:400;src:local("Menlo Regular"),local(Menlo-Regular),local(Monaco),local(Consolas),local("Courier New")}' + | ||
'@font-face{font-family:monospace;font-style:normal;font-weight:700;src:local("Menlo Bold"),local(Menlo-Bold),local(Monaco),local("Consolas Bold"),local(Consolas-Bold),local("Courier New Bold")}' + | ||
'a{font-family:monospace}b{font-family:monospace}', | ||
|
||
{}, | ||
done | ||
); | ||
}); | ||
|
||
it('supports google fonts', function(done) { | ||
test( | ||
'a{font-family:"Alice"}b{}', | ||
|
||
'@font-face{font-family:Alice;font-style:normal;font-weight:400;src:local("Alice Regular"),local(Alice-Regular),url(//fonts.gstatic.com/s/alice/v9/OpNCnoEEmtHa6GcOrgo.eot?#) format("eot"),url(//fonts.gstatic.com/s/alice/v9/OpNCnoEEmtHa6GcOrg4.woff2) format("woff2"),url(//fonts.gstatic.com/s/alice/v9/OpNCnoEEmtHa6GcOrgg.woff) format("woff")}a{font-family:"Alice"}b{}', | ||
{}, | ||
done | ||
); | ||
}); | ||
|
||
it('supports font-display option', function(done) { | ||
test( | ||
'a{font-family:"Alice"}b{}', | ||
|
||
'@font-face{font-family:Alice;font-style:normal;font-weight:400;src:local("Alice Regular"),local(Alice-Regular),url(//fonts.gstatic.com/s/alice/v9/OpNCnoEEmtHa6GcOrgo.eot?#) format("eot"),url(//fonts.gstatic.com/s/alice/v9/OpNCnoEEmtHa6GcOrg4.woff2) format("woff2"),url(//fonts.gstatic.com/s/alice/v9/OpNCnoEEmtHa6GcOrgg.woff) format("woff");font-display:swap}a{font-family:"Alice"}b{}', | ||
{ display: 'swap' }, | ||
done | ||
); | ||
}); | ||
|
||
describe('Custom google fonts options:', function() { | ||
it('supports custom google fonts', function(done) { | ||
test( | ||
'a{font-family:"Open Sans"}b{}', | ||
|
||
'@font-face{font-family:"Open Sans";font-style:normal;font-weight:300;src:url(//fonts.gstatic.com/s/opensans/v15/mem5YaGs126MiZpBA-UN_r8OUuhv.woff) format("woff")}@font-face{font-family:"Open Sans";font-style:italic;font-weight:400;src:url(//fonts.gstatic.com/s/opensans/v15/mem6YaGs126MiZpBA-UFUK0Zdck.eot?#) format("eot"),url(//fonts.gstatic.com/s/opensans/v15/mem6YaGs126MiZpBA-UFUK0Zdcs.woff) format("woff")}a{font-family:"Open Sans"}b{}', | ||
{ | ||
variants: { | ||
'Open Sans': { | ||
'300': ['woff'], | ||
'400 italic': ['eot woff'] | ||
} | ||
} | ||
}, | ||
done | ||
); | ||
}); | ||
|
||
it('supports custom google fonts (default formats)', function(done) { | ||
test( | ||
'a{font-family:"Open Sans"}b{}', | ||
|
||
'@font-face{font-family:"Open Sans";font-style:normal;font-weight:300;src:local("Open Sans Light"),local(OpenSans-Light),url(//fonts.gstatic.com/s/opensans/v15/mem5YaGs126MiZpBA-UN_r8OUuht.eot?#) format("eot"),url(//fonts.gstatic.com/s/opensans/v15/mem5YaGs126MiZpBA-UN_r8OUuhp.woff2) format("woff2"),url(//fonts.gstatic.com/s/opensans/v15/mem5YaGs126MiZpBA-UN_r8OUuhv.woff) format("woff")}a{font-family:"Open Sans"}b{}', | ||
|
||
{ | ||
variants: { | ||
'Open Sans': { | ||
'300': [] | ||
} | ||
} | ||
}, | ||
done | ||
); | ||
}); | ||
|
||
it('supports custom unicode-range', function(done) { | ||
test( | ||
'a{font-family:"Open Sans"}b{}', | ||
|
||
'@font-face{font-family:"Open Sans";font-style:normal;font-weight:300;src:url(//fonts.gstatic.com/s/opensans/v15/mem5YaGs126MiZpBA-UN_r8OUuhv.woff) format("woff");unicode-range:U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF}@font-face{font-family:"Open Sans";font-style:italic;font-weight:400;src:url(//fonts.gstatic.com/s/opensans/v15/mem6YaGs126MiZpBA-UFUK0Zdck.eot?#) format("eot"),url(//fonts.gstatic.com/s/opensans/v15/mem6YaGs126MiZpBA-UFUK0Zdcs.woff) format("woff")}a{font-family:"Open Sans"}b{}', | ||
{ | ||
variants: { | ||
'Open Sans': { | ||
'300': [ | ||
'woff', | ||
'U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF' | ||
], | ||
'400 italic': ['eot woff'] | ||
} | ||
} | ||
}, | ||
done | ||
); | ||
}); | ||
|
||
it('supports custom font-stretch: omit "normal" style', function(done) { | ||
test( | ||
'a{font-family:"Open Sans"}b{}', | ||
|
||
'@font-face{font-family:"Open Sans";font-style:normal;font-weight:300;src:url(//fonts.gstatic.com/s/opensans/v15/mem5YaGs126MiZpBA-UN_r8OUuhv.woff) format("woff");font-stretch:condensed}@font-face{font-family:"Open Sans";font-style:italic;font-weight:400;src:url(//fonts.gstatic.com/s/opensans/v15/mem6YaGs126MiZpBA-UFUK0Zdck.eot?#) format("eot"),url(//fonts.gstatic.com/s/opensans/v15/mem6YaGs126MiZpBA-UFUK0Zdcs.woff) format("woff")}a{font-family:"Open Sans"}b{}', | ||
{ | ||
variants: { | ||
'Open Sans': { | ||
'300 condensed': ['woff'], | ||
'400 italic': ['eot woff'] | ||
} | ||
} | ||
}, | ||
done | ||
); | ||
}); | ||
|
||
it('supports custom font-stretch: with "normal" style', function(done) { | ||
test( | ||
'a{font-family:"Open Sans"}b{}', | ||
|
||
'@font-face{font-family:"Open Sans";font-style:normal;font-weight:300;src:url(//fonts.gstatic.com/s/opensans/v15/mem5YaGs126MiZpBA-UN_r8OUuhv.woff) format("woff");font-stretch:condensed}@font-face{font-family:"Open Sans";font-style:italic;font-weight:400;src:url(//fonts.gstatic.com/s/opensans/v15/mem6YaGs126MiZpBA-UFUK0Zdck.eot?#) format("eot"),url(//fonts.gstatic.com/s/opensans/v15/mem6YaGs126MiZpBA-UFUK0Zdcs.woff) format("woff")}a{font-family:"Open Sans"}b{}', | ||
{ | ||
variants: { | ||
'Open Sans': { | ||
'300 normal condensed': ['woff'], | ||
'400 italic': ['eot woff'] | ||
} | ||
} | ||
}, | ||
done | ||
); | ||
}); | ||
|
||
it('supports custom font-stretch: with "italic" style', function(done) { | ||
test( | ||
'a{font-family:"Open Sans"}b{}', | ||
|
||
'@font-face{font-family:"Open Sans";font-style:normal;font-weight:300;src:url(//fonts.gstatic.com/s/opensans/v15/mem5YaGs126MiZpBA-UN_r8OUuhv.woff) format("woff")}@font-face{font-family:"Open Sans";font-style:italic;font-weight:400;src:url(//fonts.gstatic.com/s/opensans/v15/mem6YaGs126MiZpBA-UFUK0Zdck.eot?#) format("eot"),url(//fonts.gstatic.com/s/opensans/v15/mem6YaGs126MiZpBA-UFUK0Zdcs.woff) format("woff");font-stretch:ultra-condensed}a{font-family:"Open Sans"}b{}', | ||
{ | ||
variants: { | ||
'Open Sans': { | ||
'300': ['woff'], | ||
'400 italic ultra-condensed': ['eot woff'] | ||
} | ||
} | ||
}, | ||
done | ||
); | ||
}); | ||
}); | ||
|
||
it('adds google fonts once', function(done) { | ||
test( | ||
'a{font-family:"Alice"}b{font-family:"Alice"}', | ||
|
||
'@font-face{font-family:Alice;font-style:normal;font-weight:400;src:local("Alice Regular"),local(Alice-Regular),url(//fonts.gstatic.com/s/alice/v9/OpNCnoEEmtHa6GcOrgo.eot?#) format("eot"),url(//fonts.gstatic.com/s/alice/v9/OpNCnoEEmtHa6GcOrg4.woff2) format("woff2"),url(//fonts.gstatic.com/s/alice/v9/OpNCnoEEmtHa6GcOrgg.woff) format("woff")}a{font-family:"Alice"}b{font-family:"Alice"}', | ||
|
||
{}, | ||
done | ||
); | ||
}); | ||
|
||
it('supports hosted fonts', function(done) { | ||
test( | ||
'a{font-family:"Source Sans Pro"}b{}', | ||
|
||
'@font-face{font-family:"Source Sans Pro";font-style:normal;font-weight:400;src:local(SourceSansPro-Regular),local(SourceSansPro-Regular),url(./test/fonts/pathFont.woff) format("woff")}' + | ||
'a{font-family:"Source Sans Pro"}b{}', | ||
|
||
{ | ||
hosted: ['./test/fonts'] | ||
}, | ||
done | ||
); | ||
}); | ||
|
||
it('supports hosted fonts (string fallback)', function(done) { | ||
test( | ||
'a{font-family:"Source Sans Pro"}b{}', | ||
|
||
'@font-face{font-family:"Source Sans Pro";font-style:normal;font-weight:400;src:local(SourceSansPro-Regular),local(SourceSansPro-Regular),url(./test/fonts/pathFont.woff) format("woff")}' + | ||
'a{font-family:"Source Sans Pro"}b{}', | ||
|
||
{ | ||
hosted: './test/fonts' | ||
}, | ||
done | ||
); | ||
}); | ||
|
||
it('supports hosted fonts with custom font path', function(done) { | ||
test( | ||
'a{font-family:"Source Sans Pro"}b{}', | ||
|
||
'@font-face{font-family:"Source Sans Pro";font-style:normal;font-weight:400;src:local(SourceSansPro-Regular),local(SourceSansPro-Regular),url(/some/custom/path/pathFont.woff) format("woff")}' + | ||
'a{font-family:"Source Sans Pro"}b{}', | ||
|
||
{ | ||
hosted: ['./test/fonts', '/some/custom/path'] | ||
}, | ||
done | ||
); | ||
}); | ||
|
||
it('does not overwrite existing @font-face rules', function(done) { | ||
test( | ||
'@font-face{font-family:Alice}a{font-family:"Alice"}b{}', | ||
|
||
'@font-face{font-family:Alice}a{font-family:"Alice"}b{}', | ||
|
||
{}, | ||
done | ||
); | ||
}); | ||
|
||
it('support foundry exclusion', function(done) { | ||
test( | ||
'a{font-family:"Alice"}b{}', | ||
|
||
'a{font-family:"Alice"}b{}', | ||
|
||
{ | ||
foundries: 'hosted' | ||
}, | ||
done | ||
); | ||
}); | ||
|
||
it('support font aliasing', function(done) { | ||
test( | ||
'a{font-family:body}b{}', | ||
|
||
'@font-face{font-family:body;font-style:normal;font-weight:400;src:url(//fonts.gstatic.com/s/opensans/v15/mem8YaGs126MiZpBA-UFVZ0d.woff) format("woff")}a{font-family:body}b{}', | ||
|
||
{ | ||
aliases: { | ||
body: 'Open Sans' | ||
}, | ||
variants: { | ||
body: { | ||
'400': ['woff'] | ||
} | ||
} | ||
}, | ||
done | ||
); | ||
}); | ||
|
||
it('support custom fonts', function(done) { | ||
test( | ||
'a{font-family:body}b{}', | ||
|
||
'@font-face{font-family:body;font-style:normal;font-weight:400;src:url(path/to/my-body-font.woff2) format("woff2")}' + | ||
'a{font-family:body}b{}', | ||
|
||
{ | ||
custom: { | ||
body: { | ||
variants: { | ||
normal: { | ||
400: { | ||
url: { | ||
woff2: 'path/to/my-body-font.woff2' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
done | ||
); | ||
}); | ||
|
||
it('support async font loading', function(done) { | ||
test( | ||
'a{font-family:Alice}b{}', | ||
|
||
'a{font-family:Alice}b{}', | ||
|
||
{ | ||
async: './test/fontface.js.result' | ||
}, | ||
done | ||
); | ||
}); | ||
|
||
it('supports custom configuration protocol (http)', function(done) { | ||
test( | ||
'a{font-family:"Alice"}b{}', | ||
|
||
'@font-face{font-family:Alice;font-style:normal;font-weight:400;src:local("Alice Regular"),local(Alice-Regular),url(http://fonts.gstatic.com/s/alice/v9/OpNCnoEEmtHa6GcOrgo.eot?#) format("eot"),url(http://fonts.gstatic.com/s/alice/v9/OpNCnoEEmtHa6GcOrg4.woff2) format("woff2"),url(http://fonts.gstatic.com/s/alice/v9/OpNCnoEEmtHa6GcOrgg.woff) format("woff")}a{font-family:"Alice"}b{}', | ||
|
||
{ | ||
protocol: 'http:' | ||
}, | ||
done | ||
); | ||
}); | ||
|
||
it('supports custom configuration protocol (https)', function(done) { | ||
test( | ||
'a{font-family:"Alice"}b{}', | ||
|
||
'@font-face{font-family:Alice;font-style:normal;font-weight:400;src:local("Alice Regular"),local(Alice-Regular),url(https://fonts.gstatic.com/s/alice/v9/OpNCnoEEmtHa6GcOrgo.eot?#) format("eot"),url(https://fonts.gstatic.com/s/alice/v9/OpNCnoEEmtHa6GcOrg4.woff2) format("woff2"),url(https://fonts.gstatic.com/s/alice/v9/OpNCnoEEmtHa6GcOrgg.woff) format("woff")}a{font-family:"Alice"}b{}', | ||
|
||
{ | ||
protocol: 'https:' | ||
}, | ||
done | ||
); | ||
}); | ||
}); |
Oops, something went wrong.