Skip to content

Commit

Permalink
Use AssetGraph#info to emit the notification
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed Jun 6, 2020
1 parent 12b9ea7 commit bf15531
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/subfont.js
Expand Up @@ -140,7 +140,9 @@ module.exports = async function subfont(
.findRelations({ type: 'HttpRedirect' })
.sort((a, b) => a.id - b.id)) {
if (relation.from.isInitial) {
console.warn(`${relation.from.url} redirected to ${relation.to.url}`);
assetGraph.info(
new Error(`${relation.from.url} redirected to ${relation.to.url}`)
);
relation.to.isInitial = true;
relation.from.isInitial = false;
}
Expand Down
15 changes: 12 additions & 3 deletions test/subfont.js
Expand Up @@ -3,6 +3,7 @@ const sinon = require('sinon');
const expect = require('unexpected').clone().use(require('unexpected-sinon'));
const subfont = require('../lib/subfont');
const httpception = require('httpception');
const AssetGraph = require('assetgraph');
const proxyquire = require('proxyquire');
const pathModule = require('path');
const openSansBold = require('fs').readFileSync(
Expand All @@ -20,6 +21,10 @@ describe('subfont', function () {
mockConsole = { log: sinon.spy(), warn: sinon.spy(), error: sinon.spy() };
});

afterEach(function () {
sinon.restore();
});

describe('when a font is referenced by a stylesheet hosted outside the root', function () {
it('should move the CSS into the root', async function () {
httpception([
Expand Down Expand Up @@ -265,6 +270,8 @@ describe('subfont', function () {
]);

const root = 'http://example.com/';
sinon.stub(AssetGraph.prototype, 'info');

const assetGraph = await subfont(
{
root,
Expand All @@ -286,9 +293,11 @@ describe('subfont', function () {
'to equal',
'https://somewhereelse.com/index.html'
);
expect(mockConsole.warn, 'to have a call satisfying', () => {
mockConsole.warn(
'http://example.com/ redirected to https://somewhereelse.com/'
expect(assetGraph.info, 'to have a call satisfying', () => {
assetGraph.info(
new Error(
'http://example.com/ redirected to https://somewhereelse.com/'
)
);
});
});
Expand Down

0 comments on commit bf15531

Please sign in to comment.