@realfavicongenerator/check-favicon 0.4.3 → 0.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import { CheckerMessage, DesktopFaviconReport, Fetcher } from "../types";
2
2
  import { HTMLElement } from 'node-html-parser';
3
- export declare const PngFaviconFileSize = 48;
3
+ export declare const PngFaviconFileSize = 96;
4
4
  export declare const checkSvgFavicon: (baseUrl: string, head: HTMLElement | null, fetcher?: Fetcher) => Promise<CheckerMessage[]>;
5
5
  export declare const checkSvgFaviconFile: (baseUrl: string, url: string, fetcher: Fetcher) => Promise<CheckerMessage[]>;
6
6
  export declare const checkPngFavicon: (baseUrl: string, head: HTMLElement | null, fetcher?: Fetcher) => Promise<DesktopFaviconReport>;
@@ -17,7 +17,7 @@ const types_1 = require("../types");
17
17
  const sharp_1 = __importDefault(require("sharp"));
18
18
  const helper_1 = require("../helper");
19
19
  const ico_1 = require("./ico");
20
- exports.PngFaviconFileSize = 48;
20
+ exports.PngFaviconFileSize = 96;
21
21
  const checkSvgFavicon = (baseUrl_1, head_1, ...args_1) => __awaiter(void 0, [baseUrl_1, head_1, ...args_1], void 0, function* (baseUrl, head, fetcher = helper_1.fetchFetcher) {
22
22
  const messages = [];
23
23
  if (!head) {
@@ -133,7 +133,7 @@ const checkPngFavicon = (baseUrl_2, head_2, ...args_2) => __awaiter(void 0, [bas
133
133
  if (sizedIconMarkup.length === 0) {
134
134
  messages.push({
135
135
  status: types_1.CheckerStatus.Error,
136
- id: types_1.MessageId.no48x48DesktopPngFavicon,
136
+ id: types_1.MessageId.no96x96DesktopPngFavicon,
137
137
  text: `There is no ${size} desktop PNG favicon`
138
138
  });
139
139
  }
@@ -143,7 +143,7 @@ const checkPngFavicon = (baseUrl_2, head_2, ...args_2) => __awaiter(void 0, [bas
143
143
  id: types_1.MessageId.desktopPngFaviconDeclared,
144
144
  text: `The ${size} desktop PNG favicon is declared`
145
145
  });
146
- const href = icons[0].attributes.href;
146
+ const href = sizedIconMarkup[0].attributes.href;
147
147
  if (!href) {
148
148
  messages.push({
149
149
  status: types_1.CheckerStatus.Error,
@@ -14,26 +14,26 @@ const desktop_1 = require("./desktop");
14
14
  const types_1 = require("../types");
15
15
  const helper_1 = require("../helper");
16
16
  const test_helper_1 = require("../test-helper");
17
- const runTest = (headFragment_1, output_1, ...args_1) => __awaiter(void 0, [headFragment_1, output_1, ...args_1], void 0, function* (headFragment, output, fetchDatabase = {}) {
17
+ const runSvgTest = (headFragment_1, output_1, ...args_1) => __awaiter(void 0, [headFragment_1, output_1, ...args_1], void 0, function* (headFragment, output, fetchDatabase = {}) {
18
18
  const root = headFragment ? (0, node_html_parser_1.parse)(headFragment) : null;
19
19
  const result = yield (0, desktop_1.checkSvgFavicon)('https://example.com/', root, (0, test_helper_1.testFetcher)(fetchDatabase));
20
20
  const filteredMessages = result.map(m => ({ status: m.status, id: m.id }));
21
21
  expect(filteredMessages).toEqual(output);
22
22
  });
23
23
  test('checkSvgFavicon - noHead', () => __awaiter(void 0, void 0, void 0, function* () {
24
- yield runTest(null, [{
24
+ yield runSvgTest(null, [{
25
25
  status: types_1.CheckerStatus.Error,
26
26
  id: types_1.MessageId.noHead,
27
27
  }]);
28
28
  }));
29
29
  test('checkSvgFavicon - noSvgFavicon', () => __awaiter(void 0, void 0, void 0, function* () {
30
- yield runTest(`<title>SOme text</title>`, [{
30
+ yield runSvgTest(`<title>SOme text</title>`, [{
31
31
  status: types_1.CheckerStatus.Error,
32
32
  id: types_1.MessageId.noSvgFavicon,
33
33
  }]);
34
34
  }));
35
35
  test('checkSvgFavicon - multipleSvgFavicons', () => __awaiter(void 0, void 0, void 0, function* () {
36
- yield runTest(`
36
+ yield runSvgTest(`
37
37
  <link rel="icon" type="image/svg+xml" href="/the-icon.svg" />
38
38
  <link rel="icon" type="image/svg+xml" href="/another-icon.svg" />
39
39
  `, [{
@@ -42,7 +42,7 @@ test('checkSvgFavicon - multipleSvgFavicons', () => __awaiter(void 0, void 0, vo
42
42
  }]);
43
43
  }));
44
44
  test('checkSvgFavicon - svgFaviconDeclared & noSvgFaviconHref', () => __awaiter(void 0, void 0, void 0, function* () {
45
- yield runTest(`<link rel="icon" type="image/svg+xml" />`, [{
45
+ yield runSvgTest(`<link rel="icon" type="image/svg+xml" />`, [{
46
46
  status: types_1.CheckerStatus.Ok,
47
47
  id: types_1.MessageId.svgFaviconDeclared,
48
48
  }, {
@@ -51,7 +51,7 @@ test('checkSvgFavicon - svgFaviconDeclared & noSvgFaviconHref', () => __awaiter(
51
51
  }]);
52
52
  }));
53
53
  test('checkSvgFavicon - svgFaviconDeclared & svgFavicon404', () => __awaiter(void 0, void 0, void 0, function* () {
54
- yield runTest(`<link rel="icon" type="image/svg+xml" href="/the-icon.svg" />`, [{
54
+ yield runSvgTest(`<link rel="icon" type="image/svg+xml" href="/the-icon.svg" />`, [{
55
55
  status: types_1.CheckerStatus.Ok,
56
56
  id: types_1.MessageId.svgFaviconDeclared,
57
57
  }, {
@@ -60,7 +60,7 @@ test('checkSvgFavicon - svgFaviconDeclared & svgFavicon404', () => __awaiter(voi
60
60
  }]);
61
61
  }));
62
62
  test('checkSvgFavicon - svgFaviconDeclared & svgFaviconCannotGet', () => __awaiter(void 0, void 0, void 0, function* () {
63
- yield runTest(`<link rel="icon" type="image/svg+xml" href="/the-icon.svg" />`, [{
63
+ yield runSvgTest(`<link rel="icon" type="image/svg+xml" href="/the-icon.svg" />`, [{
64
64
  status: types_1.CheckerStatus.Ok,
65
65
  id: types_1.MessageId.svgFaviconDeclared,
66
66
  }, {
@@ -76,7 +76,7 @@ test('checkSvgFavicon - svgFaviconDeclared & svgFaviconCannotGet', () => __await
76
76
  test('checkSvgFavicon - svgFaviconDeclared & svgFaviconDownloadable & svgFaviconSquare', () => __awaiter(void 0, void 0, void 0, function* () {
77
77
  const testIconPath = './fixtures/happy-face.svg';
78
78
  const serpIcon = yield (0, helper_1.filePathToString)(testIconPath);
79
- yield runTest(`<link rel="icon" type="image/svg+xml" href="/the-icon.svg" />`, [
79
+ yield runSvgTest(`<link rel="icon" type="image/svg+xml" href="/the-icon.svg" />`, [
80
80
  {
81
81
  status: types_1.CheckerStatus.Ok,
82
82
  id: types_1.MessageId.svgFaviconDeclared,
@@ -95,3 +95,51 @@ test('checkSvgFavicon - svgFaviconDeclared & svgFaviconDownloadable & svgFavicon
95
95
  }
96
96
  });
97
97
  }));
98
+ const runPngTest = (headFragment_2, output_2, ...args_2) => __awaiter(void 0, [headFragment_2, output_2, ...args_2], void 0, function* (headFragment, output, fetchDatabase = {}) {
99
+ const root = headFragment ? (0, node_html_parser_1.parse)(headFragment) : null;
100
+ const result = yield (0, desktop_1.checkPngFavicon)('https://example.com/', root, (0, test_helper_1.testFetcher)(fetchDatabase));
101
+ const filteredMessages = result.messages.map(m => ({ status: m.status, id: m.id }));
102
+ expect(filteredMessages).toEqual(output);
103
+ });
104
+ const testIcon16 = './fixtures/16x16.png';
105
+ const testIcon32 = './fixtures/32x32.png';
106
+ const testIcon48 = './fixtures/48x48.png';
107
+ const testIcon96 = './fixtures/96x96.png';
108
+ test('checkSvgFavicon - Three PNG icons with different sizes', () => __awaiter(void 0, void 0, void 0, function* () {
109
+ yield runPngTest(`
110
+ <link rel="icon" type="image/png" sizes="16x16" href="/favicon/favicon-16x16.png">
111
+ <link rel="icon" type="image/png" sizes="32x32" href="/favicon/favicon-32x32.png">
112
+ <link rel="icon" type="image/png" sizes="48x48" href="/favicon/favicon-48x48.png">
113
+ <link rel="icon" type="image/png" sizes="96x96" href="/favicon/favicon-96x96.png">
114
+ `, [{
115
+ status: types_1.CheckerStatus.Ok,
116
+ id: types_1.MessageId.desktopPngFaviconDeclared,
117
+ }, {
118
+ status: types_1.CheckerStatus.Ok,
119
+ id: types_1.MessageId.desktopPngFaviconDownloadable,
120
+ }, {
121
+ status: types_1.CheckerStatus.Ok,
122
+ id: types_1.MessageId.desktopPngFaviconRightSize,
123
+ }], {
124
+ 'https://example.com/favicon/favicon-16x16.png': {
125
+ status: 200,
126
+ contentType: 'image/png',
127
+ readableStream: yield (0, helper_1.filePathToReadableStream)(testIcon16),
128
+ },
129
+ 'https://example.com/favicon/favicon-32x32.png': {
130
+ status: 200,
131
+ contentType: 'image/png',
132
+ readableStream: yield (0, helper_1.filePathToReadableStream)(testIcon32),
133
+ },
134
+ 'https://example.com/favicon/favicon-48x48.png': {
135
+ status: 200,
136
+ contentType: 'image/png',
137
+ readableStream: yield (0, helper_1.filePathToReadableStream)(testIcon48),
138
+ },
139
+ 'https://example.com/favicon/favicon-96x96.png': {
140
+ status: 200,
141
+ contentType: 'image/png',
142
+ readableStream: yield (0, helper_1.filePathToReadableStream)(testIcon96),
143
+ }
144
+ });
145
+ }));
package/dist/types.d.ts CHANGED
@@ -25,7 +25,7 @@ export declare enum MessageId {
25
25
  icoFaviconMissingSizes = 18,
26
26
  icoFaviconExpectedSizes = 19,
27
27
  noDesktopPngFavicon = 20,
28
- no48x48DesktopPngFavicon = 21,
28
+ no96x96DesktopPngFavicon = 21,
29
29
  desktopPngFaviconDeclared = 22,
30
30
  noDesktopPngFaviconHref = 23,
31
31
  desktopPngFaviconCannotGet = 24,
package/dist/types.js CHANGED
@@ -30,7 +30,7 @@ var MessageId;
30
30
  MessageId[MessageId["icoFaviconMissingSizes"] = 18] = "icoFaviconMissingSizes";
31
31
  MessageId[MessageId["icoFaviconExpectedSizes"] = 19] = "icoFaviconExpectedSizes";
32
32
  MessageId[MessageId["noDesktopPngFavicon"] = 20] = "noDesktopPngFavicon";
33
- MessageId[MessageId["no48x48DesktopPngFavicon"] = 21] = "no48x48DesktopPngFavicon";
33
+ MessageId[MessageId["no96x96DesktopPngFavicon"] = 21] = "no96x96DesktopPngFavicon";
34
34
  MessageId[MessageId["desktopPngFaviconDeclared"] = 22] = "desktopPngFaviconDeclared";
35
35
  MessageId[MessageId["noDesktopPngFaviconHref"] = 23] = "noDesktopPngFaviconHref";
36
36
  MessageId[MessageId["desktopPngFaviconCannotGet"] = 24] = "desktopPngFaviconCannotGet";
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@realfavicongenerator/check-favicon",
3
- "version": "0.4.3",
3
+ "version": "0.4.6",
4
4
  "description": "Check the favicon of a website",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {
8
8
  "test": "jest",
9
+ "test:watch": "jest --watch",
9
10
  "build": "tsc",
10
11
  "prepublishOnly": "npm run build"
11
12
  },
@@ -38,5 +39,5 @@
38
39
  "node-html-parser": "^6.1.13",
39
40
  "sharp": "^0.32.6"
40
41
  },
41
- "gitHead": "521809bb438faddd63218e736f20f89ffb2cab71"
42
+ "gitHead": "f62941a779e6ce1b49ad97bfea8a9eb71e7ceba5"
42
43
  }
@@ -1,12 +1,12 @@
1
1
  import { parse } from 'node-html-parser'
2
- import { checkSvgFavicon } from "./desktop";
2
+ import { checkPngFavicon, checkSvgFavicon } from "./desktop";
3
3
  import { CheckerMessage, CheckerStatus, FetchResponse, MessageId } from '../types';
4
4
  import { filePathToReadableStream, filePathToString, stringToReadableStream } from '../helper';
5
5
  import { testFetcher } from '../test-helper';
6
6
 
7
7
  type TestOutput = Pick<CheckerMessage, 'id' | 'status'>[];
8
8
 
9
- const runTest = async (
9
+ const runSvgTest = async (
10
10
  headFragment: string | null,
11
11
  output: TestOutput,
12
12
  fetchDatabase: { [url: string]: FetchResponse } = {}
@@ -18,21 +18,21 @@ const runTest = async (
18
18
  }
19
19
 
20
20
  test('checkSvgFavicon - noHead', async () => {
21
- await runTest(null, [{
21
+ await runSvgTest(null, [{
22
22
  status: CheckerStatus.Error,
23
23
  id: MessageId.noHead,
24
24
  }]);
25
25
  })
26
26
 
27
27
  test('checkSvgFavicon - noSvgFavicon', async () => {
28
- await runTest(`<title>SOme text</title>`, [{
28
+ await runSvgTest(`<title>SOme text</title>`, [{
29
29
  status: CheckerStatus.Error,
30
30
  id: MessageId.noSvgFavicon,
31
31
  }]);
32
32
  })
33
33
 
34
34
  test('checkSvgFavicon - multipleSvgFavicons', async () => {
35
- await runTest(`
35
+ await runSvgTest(`
36
36
  <link rel="icon" type="image/svg+xml" href="/the-icon.svg" />
37
37
  <link rel="icon" type="image/svg+xml" href="/another-icon.svg" />
38
38
  `, [{
@@ -42,7 +42,7 @@ test('checkSvgFavicon - multipleSvgFavicons', async () => {
42
42
  })
43
43
 
44
44
  test('checkSvgFavicon - svgFaviconDeclared & noSvgFaviconHref', async () => {
45
- await runTest(`<link rel="icon" type="image/svg+xml" />`, [{
45
+ await runSvgTest(`<link rel="icon" type="image/svg+xml" />`, [{
46
46
  status: CheckerStatus.Ok,
47
47
  id: MessageId.svgFaviconDeclared,
48
48
  }, {
@@ -52,7 +52,7 @@ test('checkSvgFavicon - svgFaviconDeclared & noSvgFaviconHref', async () => {
52
52
  })
53
53
 
54
54
  test('checkSvgFavicon - svgFaviconDeclared & svgFavicon404', async () => {
55
- await runTest(`<link rel="icon" type="image/svg+xml" href="/the-icon.svg" />`, [{
55
+ await runSvgTest(`<link rel="icon" type="image/svg+xml" href="/the-icon.svg" />`, [{
56
56
  status: CheckerStatus.Ok,
57
57
  id: MessageId.svgFaviconDeclared,
58
58
  }, {
@@ -62,7 +62,7 @@ test('checkSvgFavicon - svgFaviconDeclared & svgFavicon404', async () => {
62
62
  })
63
63
 
64
64
  test('checkSvgFavicon - svgFaviconDeclared & svgFaviconCannotGet', async () => {
65
- await runTest(`<link rel="icon" type="image/svg+xml" href="/the-icon.svg" />`, [{
65
+ await runSvgTest(`<link rel="icon" type="image/svg+xml" href="/the-icon.svg" />`, [{
66
66
  status: CheckerStatus.Ok,
67
67
  id: MessageId.svgFaviconDeclared,
68
68
  }, {
@@ -81,7 +81,7 @@ test('checkSvgFavicon - svgFaviconDeclared & svgFaviconDownloadable & svgFavicon
81
81
 
82
82
  const serpIcon = await filePathToString(testIconPath);
83
83
 
84
- await runTest(`<link rel="icon" type="image/svg+xml" href="/the-icon.svg" />`, [
84
+ await runSvgTest(`<link rel="icon" type="image/svg+xml" href="/the-icon.svg" />`, [
85
85
  {
86
86
  status: CheckerStatus.Ok,
87
87
  id: MessageId.svgFaviconDeclared,
@@ -99,3 +99,59 @@ test('checkSvgFavicon - svgFaviconDeclared & svgFaviconDownloadable & svgFavicon
99
99
  }
100
100
  });
101
101
  })
102
+
103
+ const runPngTest = async (
104
+ headFragment: string | null,
105
+ output: TestOutput,
106
+ fetchDatabase: { [url: string]: FetchResponse } = {}
107
+ ) => {
108
+ const root = headFragment ? parse(headFragment) : null;
109
+ const result = await checkPngFavicon('https://example.com/', root, testFetcher(fetchDatabase));
110
+ const filteredMessages = result.messages.map(m => ({ status: m.status, id: m.id }));
111
+ expect(filteredMessages).toEqual(output);
112
+ }
113
+
114
+ const testIcon16 = './fixtures/16x16.png';
115
+ const testIcon32 = './fixtures/32x32.png';
116
+ const testIcon48 = './fixtures/48x48.png';
117
+ const testIcon96 = './fixtures/96x96.png';
118
+
119
+ test('checkSvgFavicon - Three PNG icons with different sizes', async () => {
120
+ await runPngTest(`
121
+ <link rel="icon" type="image/png" sizes="16x16" href="/favicon/favicon-16x16.png">
122
+ <link rel="icon" type="image/png" sizes="32x32" href="/favicon/favicon-32x32.png">
123
+ <link rel="icon" type="image/png" sizes="48x48" href="/favicon/favicon-48x48.png">
124
+ <link rel="icon" type="image/png" sizes="96x96" href="/favicon/favicon-96x96.png">
125
+ `, [{
126
+ status: CheckerStatus.Ok,
127
+ id: MessageId.desktopPngFaviconDeclared,
128
+ }, {
129
+ status: CheckerStatus.Ok,
130
+ id: MessageId.desktopPngFaviconDownloadable,
131
+ }, {
132
+ status: CheckerStatus.Ok,
133
+ id: MessageId.desktopPngFaviconRightSize,
134
+ }],
135
+ {
136
+ 'https://example.com/favicon/favicon-16x16.png': {
137
+ status: 200,
138
+ contentType: 'image/png',
139
+ readableStream: await filePathToReadableStream(testIcon16),
140
+ },
141
+ 'https://example.com/favicon/favicon-32x32.png': {
142
+ status: 200,
143
+ contentType: 'image/png',
144
+ readableStream: await filePathToReadableStream(testIcon32),
145
+ },
146
+ 'https://example.com/favicon/favicon-48x48.png': {
147
+ status: 200,
148
+ contentType: 'image/png',
149
+ readableStream: await filePathToReadableStream(testIcon48),
150
+ },
151
+ 'https://example.com/favicon/favicon-96x96.png': {
152
+ status: 200,
153
+ contentType: 'image/png',
154
+ readableStream: await filePathToReadableStream(testIcon96),
155
+ }
156
+ });
157
+ })
@@ -4,7 +4,7 @@ import sharp from 'sharp'
4
4
  import { CheckIconProcessor, checkIcon, fetchFetcher, mergeUrlAndPath, readableStreamToString } from "../helper";
5
5
  import { checkIcoFavicon } from "./ico";
6
6
 
7
- export const PngFaviconFileSize = 48;
7
+ export const PngFaviconFileSize = 96;
8
8
 
9
9
  export const checkSvgFavicon = async (baseUrl: string, head: HTMLElement | null, fetcher: Fetcher = fetchFetcher): Promise<CheckerMessage[]> => {
10
10
  const messages: CheckerMessage[] = [];
@@ -128,7 +128,7 @@ export const checkPngFavicon = async (baseUrl: string, head: HTMLElement | null,
128
128
  if (sizedIconMarkup.length === 0) {
129
129
  messages.push({
130
130
  status: CheckerStatus.Error,
131
- id: MessageId.no48x48DesktopPngFavicon,
131
+ id: MessageId.no96x96DesktopPngFavicon,
132
132
  text: `There is no ${size} desktop PNG favicon`
133
133
  });
134
134
  } else {
@@ -137,8 +137,8 @@ export const checkPngFavicon = async (baseUrl: string, head: HTMLElement | null,
137
137
  id: MessageId.desktopPngFaviconDeclared,
138
138
  text: `The ${size} desktop PNG favicon is declared`
139
139
  });
140
-
141
- const href = icons[0].attributes.href;
140
+
141
+ const href = sizedIconMarkup[0].attributes.href;
142
142
  if (!href) {
143
143
  messages.push({
144
144
  status: CheckerStatus.Error,
package/src/types.ts CHANGED
@@ -30,7 +30,7 @@ export enum MessageId {
30
30
  icoFaviconExpectedSizes,
31
31
 
32
32
  noDesktopPngFavicon,
33
- no48x48DesktopPngFavicon,
33
+ no96x96DesktopPngFavicon,
34
34
  desktopPngFaviconDeclared,
35
35
  noDesktopPngFaviconHref,
36
36
  desktopPngFaviconCannotGet,