@realfavicongenerator/check-favicon 0.4.0 → 0.4.5

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.
@@ -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,44 @@ 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
+ test('checkSvgFavicon - Three PNG icons with different sizes', () => __awaiter(void 0, void 0, void 0, function* () {
108
+ yield runPngTest(`
109
+ <link rel="icon" type="image/png" sizes="16x16" href="/favicon/favicon-16x16.png">
110
+ <link rel="icon" type="image/png" sizes="32x32" href="/favicon/favicon-32x32.png">
111
+ <link rel="icon" type="image/png" sizes="48x48" href="/favicon/favicon-48x48.png">
112
+ `, [{
113
+ status: types_1.CheckerStatus.Ok,
114
+ id: types_1.MessageId.desktopPngFaviconDeclared,
115
+ }, {
116
+ status: types_1.CheckerStatus.Ok,
117
+ id: types_1.MessageId.desktopPngFaviconDownloadable,
118
+ }, {
119
+ status: types_1.CheckerStatus.Ok,
120
+ id: types_1.MessageId.desktopPngFaviconRightSize,
121
+ }], {
122
+ 'https://example.com/favicon/favicon-16x16.png': {
123
+ status: 200,
124
+ contentType: 'image/png',
125
+ readableStream: yield (0, helper_1.filePathToReadableStream)(testIcon16),
126
+ },
127
+ 'https://example.com/favicon/favicon-32x32.png': {
128
+ status: 200,
129
+ contentType: 'image/png',
130
+ readableStream: yield (0, helper_1.filePathToReadableStream)(testIcon32),
131
+ },
132
+ 'https://example.com/favicon/favicon-48x48.png': {
133
+ status: 200,
134
+ contentType: 'image/png',
135
+ readableStream: yield (0, helper_1.filePathToReadableStream)(testIcon48),
136
+ }
137
+ });
138
+ }));
@@ -82,14 +82,6 @@ const checkTouchIconIcon = (baseUrl_2, head_2, ...args_2) => __awaiter(void 0, [
82
82
  id: types_1.MessageId.touchIconDeclared,
83
83
  text: 'The touch icon is declared'
84
84
  });
85
- const sizes = iconMarkup.map(icon => icon.getAttribute('sizes')).filter(size => size);
86
- if (sizes.length > 0) {
87
- messages.push({
88
- status: types_1.CheckerStatus.Warning,
89
- id: types_1.MessageId.touchIconWithSize,
90
- text: `Some Touch icon have a specific size (${sizes.join(', ')})`
91
- });
92
- }
93
85
  const duplicatedSizes = (0, exports.getDuplicatedSizes)(iconMarkup.map(icon => icon.getAttribute('sizes')));
94
86
  if (duplicatedSizes.length > 0) {
95
87
  messages.push({
@@ -73,23 +73,6 @@ test('checkTouchIcon - noTouchIcon', () => __awaiter(void 0, void 0, void 0, fun
73
73
  id: types_1.MessageId.noTouchIcon,
74
74
  }] });
75
75
  }));
76
- test('checkTouchIcon - touchIconWithSize', () => __awaiter(void 0, void 0, void 0, function* () {
77
- yield runCheckTouchIconTest(`
78
- <link rel="apple-touch-icon" sizes="152x152" href="some-other-icon.png">
79
- `, { messages: [{
80
- status: types_1.CheckerStatus.Ok,
81
- id: types_1.MessageId.touchIconDeclared,
82
- }, {
83
- status: types_1.CheckerStatus.Warning,
84
- id: types_1.MessageId.touchIconWithSize,
85
- }] }, {
86
- 'https://example.com/some-other-icon.png': {
87
- status: 200,
88
- contentType: 'image/png',
89
- readableStream: null
90
- }
91
- });
92
- }));
93
76
  test('checkTouchIcon - multipleTouchIcon - no size', () => __awaiter(void 0, void 0, void 0, function* () {
94
77
  yield runCheckTouchIconTest(`
95
78
  <link rel="apple-touch-icon" href="some-icon.png">
@@ -120,9 +103,6 @@ test('checkTouchIcon - multipleTouchIcon - specific size', () => __awaiter(void
120
103
  `, { messages: [{
121
104
  status: types_1.CheckerStatus.Ok,
122
105
  id: types_1.MessageId.touchIconDeclared,
123
- }, {
124
- status: types_1.CheckerStatus.Warning,
125
- id: types_1.MessageId.touchIconWithSize,
126
106
  }, {
127
107
  status: types_1.CheckerStatus.Error,
128
108
  id: types_1.MessageId.duplicatedTouchIconSizes,
@@ -139,23 +119,6 @@ test('checkTouchIcon - multipleTouchIcon - specific size', () => __awaiter(void
139
119
  }
140
120
  });
141
121
  }));
142
- test('checkTouchIcon - touchIconWithSize', () => __awaiter(void 0, void 0, void 0, function* () {
143
- yield runCheckTouchIconTest(`
144
- <link rel="apple-touch-icon" sizes="180x180" href="some-other-icon.png">
145
- `, { messages: [{
146
- status: types_1.CheckerStatus.Ok,
147
- id: types_1.MessageId.touchIconDeclared,
148
- }, {
149
- status: types_1.CheckerStatus.Warning,
150
- id: types_1.MessageId.touchIconWithSize,
151
- }] }, {
152
- 'https://example.com/some-other-icon.png': {
153
- status: 200,
154
- contentType: 'image/png',
155
- readableStream: null
156
- }
157
- });
158
- }));
159
122
  const testIcon = './fixtures/180x180.png';
160
123
  test('checkTouchIcon - Regular case', () => __awaiter(void 0, void 0, void 0, function* () {
161
124
  yield runCheckTouchIconTest(`
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.0",
3
+ "version": "0.4.5",
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": "4abed5dcaa62ba02e111a31c295eb5fc5bef98c5"
42
+ "gitHead": "ff517731a374ff42747e65aa036b064d1a1f1aa1"
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,52 @@ 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
+
118
+ test('checkSvgFavicon - Three PNG icons with different sizes', async () => {
119
+ await runPngTest(`
120
+ <link rel="icon" type="image/png" sizes="16x16" href="/favicon/favicon-16x16.png">
121
+ <link rel="icon" type="image/png" sizes="32x32" href="/favicon/favicon-32x32.png">
122
+ <link rel="icon" type="image/png" sizes="48x48" href="/favicon/favicon-48x48.png">
123
+ `, [{
124
+ status: CheckerStatus.Ok,
125
+ id: MessageId.desktopPngFaviconDeclared,
126
+ }, {
127
+ status: CheckerStatus.Ok,
128
+ id: MessageId.desktopPngFaviconDownloadable,
129
+ }, {
130
+ status: CheckerStatus.Ok,
131
+ id: MessageId.desktopPngFaviconRightSize,
132
+ }],
133
+ {
134
+ 'https://example.com/favicon/favicon-16x16.png': {
135
+ status: 200,
136
+ contentType: 'image/png',
137
+ readableStream: await filePathToReadableStream(testIcon16),
138
+ },
139
+ 'https://example.com/favicon/favicon-32x32.png': {
140
+ status: 200,
141
+ contentType: 'image/png',
142
+ readableStream: await filePathToReadableStream(testIcon32),
143
+ },
144
+ 'https://example.com/favicon/favicon-48x48.png': {
145
+ status: 200,
146
+ contentType: 'image/png',
147
+ readableStream: await filePathToReadableStream(testIcon48),
148
+ }
149
+ });
150
+ })
@@ -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,
@@ -88,24 +88,6 @@ test('checkTouchIcon - noTouchIcon', async () => {
88
88
  }]});
89
89
  })
90
90
 
91
- test('checkTouchIcon - touchIconWithSize', async () => {
92
- await runCheckTouchIconTest(`
93
- <link rel="apple-touch-icon" sizes="152x152" href="some-other-icon.png">
94
- `, { messages: [{
95
- status: CheckerStatus.Ok,
96
- id: MessageId.touchIconDeclared,
97
- }, {
98
- status: CheckerStatus.Warning,
99
- id: MessageId.touchIconWithSize,
100
- }]}, {
101
- 'https://example.com/some-other-icon.png': {
102
- status: 200,
103
- contentType: 'image/png',
104
- readableStream: null
105
- }
106
- });
107
- })
108
-
109
91
  test('checkTouchIcon - multipleTouchIcon - no size', async () => {
110
92
  await runCheckTouchIconTest(`
111
93
  <link rel="apple-touch-icon" href="some-icon.png">
@@ -137,9 +119,6 @@ test('checkTouchIcon - multipleTouchIcon - specific size', async () => {
137
119
  `, { messages: [{
138
120
  status: CheckerStatus.Ok,
139
121
  id: MessageId.touchIconDeclared,
140
- }, {
141
- status: CheckerStatus.Warning,
142
- id: MessageId.touchIconWithSize,
143
122
  }, {
144
123
  status: CheckerStatus.Error,
145
124
  id: MessageId.duplicatedTouchIconSizes,
@@ -157,24 +136,6 @@ test('checkTouchIcon - multipleTouchIcon - specific size', async () => {
157
136
  });
158
137
  })
159
138
 
160
- test('checkTouchIcon - touchIconWithSize', async () => {
161
- await runCheckTouchIconTest(`
162
- <link rel="apple-touch-icon" sizes="180x180" href="some-other-icon.png">
163
- `, { messages: [{
164
- status: CheckerStatus.Ok,
165
- id: MessageId.touchIconDeclared,
166
- }, {
167
- status: CheckerStatus.Warning,
168
- id: MessageId.touchIconWithSize,
169
- }]}, {
170
- 'https://example.com/some-other-icon.png': {
171
- status: 200,
172
- contentType: 'image/png',
173
- readableStream: null
174
- }
175
- });
176
- })
177
-
178
139
  const testIcon = './fixtures/180x180.png';
179
140
 
180
141
  test('checkTouchIcon - Regular case', async () => {
package/src/touch-icon.ts CHANGED
@@ -88,15 +88,6 @@ export const checkTouchIconIcon = async (baseUrl: string, head: HTMLElement | nu
88
88
  text: 'The touch icon is declared'
89
89
  });
90
90
 
91
- const sizes = iconMarkup.map(icon => icon.getAttribute('sizes')).filter(size => size);
92
- if (sizes.length > 0) {
93
- messages.push({
94
- status: CheckerStatus.Warning,
95
- id: MessageId.touchIconWithSize,
96
- text: `Some Touch icon have a specific size (${sizes.join(', ')})`
97
- });
98
- }
99
-
100
91
  const duplicatedSizes = getDuplicatedSizes(iconMarkup.map(icon => icon.getAttribute('sizes')));
101
92
  if (duplicatedSizes.length > 0) {
102
93
  messages.push({