@realfavicongenerator/check-favicon
Version:
Check the favicon of a website
72 lines (70 loc) • 3.05 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const google_1 = require("./google");
const helper_1 = require("./helper");
const test_helper_1 = require("./test-helper");
const types_1 = require("./types");
test('getRobotsFileUrl', () => {
expect((0, google_1.getRobotsFileUrl)('https://example.com')).toEqual('https://example.com/robots.txt');
expect((0, google_1.getRobotsFileUrl)('https://example.com/some-path')).toEqual('https://example.com/robots.txt');
});
const runRobotsTest = (urls, robotsFile, messages) => __awaiter(void 0, void 0, void 0, function* () {
const report = yield (0, google_1.checkRobotsFile)('https://example.com', urls, (0, test_helper_1.testFetcher)(robotsFile ? {
'https://example.com/robots.txt': {
status: 200,
contentType: 'text/plain',
readableStream: yield (0, helper_1.stringToReadableStream)(robotsFile)
}
} : {}));
const filteredMessages = report.map(m => ({ status: m.status, id: m.id }));
expect(filteredMessages).toEqual(messages);
});
test('checkRobotsFile - No robots file', () => __awaiter(void 0, void 0, void 0, function* () {
yield runRobotsTest(['https://example.com/favicon.png'], null, [
{
status: types_1.CheckerStatus.Ok,
id: types_1.MessageId.googleNoRobotsFile
}
]);
}));
test('checkRobotsFile - PNG favicon is accessible', () => __awaiter(void 0, void 0, void 0, function* () {
yield runRobotsTest(['https://example.com/favicon.png'], `
User-agent: *
Allow: /`, [
{
status: types_1.CheckerStatus.Ok,
id: types_1.MessageId.googleRobotsFileFound
},
{
status: types_1.CheckerStatus.Ok,
id: types_1.MessageId.googlePngIconAllowedByRobots
}
]);
}));
test('checkRobotsFile - PNG favicon is *not* accessible', () => __awaiter(void 0, void 0, void 0, function* () {
yield runRobotsTest(['https://example.com/favicon.png'], `
# *
User-agent: *
Allow: /
User-agent: Googlebot-Image
Disallow: /*.png
`, [
{
status: types_1.CheckerStatus.Ok,
id: types_1.MessageId.googleRobotsFileFound
},
{
status: types_1.CheckerStatus.Error,
id: types_1.MessageId.googlePngIconBlockedByRobots
}
]);
}));