diff --git a/test/htmls/no-favicon.html b/test/htmls/no-favicon.html new file mode 100644 index 0000000..0518f82 --- /dev/null +++ b/test/htmls/no-favicon.html @@ -0,0 +1,12 @@ + + + +
+ +Alice's Strawberry Pasta
+ + diff --git a/test/index.js b/test/index.js index 8ce31a2..a18c8bc 100644 --- a/test/index.js +++ b/test/index.js @@ -25,10 +25,37 @@ const host = `http://localhost:${port}`; /* tests below */ +it('faviconがHTML上で指定されていないが、ルートに存在する場合、正しく設定される', done => { + const app = express(); + app.get('/', (req, res) => { + res.sendFile(__dirname + '/htmls/no-favicon.html'); + }); + app.get('/favicon.ico', (_, res) => res.sendStatus(200)); + const server = app.listen(port, async () => { + const summary = await summaly(host); + assert.equal(summary.icon, `${host}/favicon.ico`); + server.close(); + done(); + }); +}); + +it('faviconがHTML上で指定されていなくて、ルートにも存在しなかった場合 null になる', done => { + const app = express(); + app.get('/', (req, res) => { + res.sendFile(__dirname + '/htmls/no-favicon.html'); + }); + const server = app.listen(port, async () => { + const summary = await summaly(host); + assert.equal(summary.icon, null); + server.close(); + done(); + }); +}); + describe('OGP', () => { it('title', done => { const app = express(); - app.use((req, res) => { + app.get('/', (req, res) => { res.sendFile(__dirname + '/htmls/og-title.html'); }); const server = app.listen(port, async () => { @@ -41,7 +68,7 @@ describe('OGP', () => { it('description', done => { const app = express(); - app.use((req, res) => { + app.get('/', (req, res) => { res.sendFile(__dirname + '/htmls/og-description.html'); }); const server = app.listen(port, async () => { @@ -54,7 +81,7 @@ describe('OGP', () => { it('site_name', done => { const app = express(); - app.use((req, res) => { + app.get('/', (req, res) => { res.sendFile(__dirname + '/htmls/og-site_name.html'); }); const server = app.listen(port, async () => { @@ -67,7 +94,7 @@ describe('OGP', () => { it('thumbnail', done => { const app = express(); - app.use((req, res) => { + app.get('/', (req, res) => { res.sendFile(__dirname + '/htmls/og-image.html'); }); const server = app.listen(port, async () => { @@ -82,7 +109,7 @@ describe('OGP', () => { describe('TwitterCard', () => { it('title', done => { const app = express(); - app.use((req, res) => { + app.get('/', (req, res) => { res.sendFile(__dirname + '/htmls/twitter-title.html'); }); const server = app.listen(port, async () => { @@ -95,7 +122,7 @@ describe('TwitterCard', () => { it('description', done => { const app = express(); - app.use((req, res) => { + app.get('/', (req, res) => { res.sendFile(__dirname + '/htmls/twitter-description.html'); }); const server = app.listen(port, async () => { @@ -108,7 +135,7 @@ describe('TwitterCard', () => { it('thumbnail', done => { const app = express(); - app.use((req, res) => { + app.get('/', (req, res) => { res.sendFile(__dirname + '/htmls/twitter-image.html'); }); const server = app.listen(port, async () => {