Skip to content

Commit

Permalink
Use fontkit to look for the presence of a licenseURL in the tests, av…
Browse files Browse the repository at this point in the history
…oiding ttx
  • Loading branch information
papandreou committed Jun 28, 2021
1 parent 00816d7 commit 4e97447
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^5.0.0",
"fast-xml-parser": "^3.19.0",
"gettemporaryfilepath": "^1.0.1",
"fontkit": "^1.8.1",
"mocha": "^7.0.0",
"nyc": "^15.0.0",
"offline-github-changelog": "^2.0.0",
Expand Down
31 changes: 10 additions & 21 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
const childProcess = require('child_process');
const getTemporaryFilePath = require('gettemporaryfilepath');
const fs = require('fs').promises;

const fontkit = require('fontkit');
const expect = require('unexpected')
.clone()
.addAssertion(
'<Buffer> [not] to have name id <number>',
async (expect, fontBuffer, nameId) => {
const outputFile = getTemporaryFilePath({ suffix: '.ttf' });
await fs.writeFile(outputFile, fontBuffer);
const xmlBuffer = childProcess.execSync(`ttx -t name -o - ${outputFile}`);
const nameRecords = require('fast-xml-parser').parse(
xmlBuffer.toString(),
{
ignoreAttributes: false,
parseAttributeValue: true,
}
).ttFont.name.namerecord;
'<Buffer> [not] to include name field <string>',
async (expect, fontBuffer, fieldName) => {
expect.errorMode = 'nested';
expect(nameRecords, '[not] to have an item satisfying', {
'@_nameID': nameId,
});
expect(
fontkit.create(fontBuffer).name.records,
'[not] to have property',
fieldName
);
}
);
const subsetFont = require('..');
Expand Down Expand Up @@ -79,7 +68,7 @@ describe('subset-font', function () {
describe('when not preserving any name ids', function () {
it('should not preserve name id 14', async function () {
const result = await subsetFont(this.sfntFont, 'abcd');
await expect(result, 'not to have name id', 14);
await expect(result, 'not to include name field', 'licenseURL');
});
});

Expand All @@ -91,7 +80,7 @@ describe('subset-font', function () {
});

it('should preserve name id 14', async function () {
await expect(this.result, 'to have name id', 14);
await expect(this.result, 'to include name field', 'licenseURL');
});
});
});
Expand Down

0 comments on commit 4e97447

Please sign in to comment.