Skip to content

Commit

Permalink
[2.2.1] update google fonts lists
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdee committed Jun 6, 2018
1 parent c8d9d5c commit 5765576
Show file tree
Hide file tree
Showing 5 changed files with 357 additions and 344 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.2.1 (2018-06-06)

Updated: google-fonts-complete dependency


## 2.2.0 (2018-06-05)

Fixed: issue with array options
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postcss-font-magician",
"version": "2.2.0",
"version": "2.2.1",
"description": "PostCSS plugin that magically generates all the @font-face rules",
"author": "Jonathan Neal <jonathantneal@hotmail.com>",
"contributors": [
Expand Down Expand Up @@ -30,7 +30,7 @@
"dependencies": {
"bootstrap-fonts-complete": "^1.0.0",
"directory-fonts-complete": "^1.2.0",
"google-fonts-complete": "^1.2.1",
"google-fonts-complete": "^1.2.2",
"postcss": "^6.0.22"
},
"devDependencies": {
Expand Down
347 changes: 347 additions & 0 deletions test/index.js
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
);
});
});

0 comments on commit 5765576

Please sign in to comment.