diff --git a/README.md b/README.md index 1e4009b..0c313ea 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,10 @@ console.log(summary); // will be ... ↓ */ ``` +Testing +------- +`npm run test` + License ------- [MIT](LICENSE) diff --git a/package.json b/package.json index 912c124..75b171c 100644 --- a/package.json +++ b/package.json @@ -9,18 +9,25 @@ "main": "./built/index.js", "types": "./built/index.d.ts", "scripts": { - "build": "gulp build" + "build": "gulp build", + "test": "mocha --harmony" }, "devDependencies": { + "@types/chai": "3.4.34", "@types/debug": "0.0.29", + "@types/express": "4.0.35", + "@types/mocha": "2.2.39", "@types/event-stream": "3.3.30", "@types/gulp": "3.8.32", "@types/gulp-typescript": "0.0.32", "@types/node": "7.0.5", "@types/request": "0.0.39", + "chai": "3.5.0", "event-stream": "3.3.4", + "express": "4.14.1", "gulp": "3.9.1", "gulp-typescript": "3.1.4", + "mocha": "3.2.0", "typescript": "2.1.5" }, "dependencies": { diff --git a/test/htmls/basic.html b/test/htmls/basic.html new file mode 100644 index 0000000..7d83caf --- /dev/null +++ b/test/htmls/basic.html @@ -0,0 +1,12 @@ + + + +
+ +KISS is an acronym for "Keep it simple, stupid" as a design principle noted by the U.S. Navy in 1960.
+ + diff --git a/test/htmls/no-metas.html b/test/htmls/no-metas.html new file mode 100644 index 0000000..938eee4 --- /dev/null +++ b/test/htmls/no-metas.html @@ -0,0 +1,11 @@ + + + + + + + +KISS is an acronym for "Keep it simple, stupid" as a design principle noted by the U.S. Navy in 1960.
+ + diff --git a/test/htmls/og-description.html b/test/htmls/og-description.html new file mode 100644 index 0000000..e036893 --- /dev/null +++ b/test/htmls/og-description.html @@ -0,0 +1,13 @@ + + + + + + +Hey hey hey syuilo.
+ + diff --git a/test/htmls/og-image.html b/test/htmls/og-image.html new file mode 100644 index 0000000..3c380d7 --- /dev/null +++ b/test/htmls/og-image.html @@ -0,0 +1,13 @@ + + + + + + +Hey hey hey syuilo.
+ + diff --git a/test/htmls/og-site_name.html b/test/htmls/og-site_name.html new file mode 100644 index 0000000..25d8d2b --- /dev/null +++ b/test/htmls/og-site_name.html @@ -0,0 +1,13 @@ + + + + + + +Hey hey hey syuilo.
+ + diff --git a/test/htmls/og-title.html b/test/htmls/og-title.html new file mode 100644 index 0000000..e0a52b5 --- /dev/null +++ b/test/htmls/og-title.html @@ -0,0 +1,13 @@ + + + + + + +Hey hey hey syuilo.
+ + diff --git a/test/index.js b/test/index.js new file mode 100644 index 0000000..01edeac --- /dev/null +++ b/test/index.js @@ -0,0 +1,77 @@ +/** + * Tests! + */ + +'use strict'; + +/* dependencies below */ + +const assert = require('assert'); +const express = require('express'); +const summaly = require('../').default; + +/* settings below */ + +Error.stackTraceLimit = Infinity; + +// During the test the env variable is set to test +process.env.NODE_ENV = 'test'; + +// Display detail of unhandled promise rejection +process.on('unhandledRejection', console.dir); + +/* tests below */ + +describe('OGP', () => { + it('title', done => { + const app = express(); + app.use((req, res) => { + res.sendFile(__dirname + '/htmls/og-title.html'); + }); + const server = app.listen(80, async () => { + const summary = await summaly('http://localhost'); + assert.equal(summary.title, 'Strawberry Pasta'); + server.close(); + done(); + }); + }); + + it('description', done => { + const app = express(); + app.use((req, res) => { + res.sendFile(__dirname + '/htmls/og-description.html'); + }); + const server = app.listen(80, async () => { + const summary = await summaly('http://localhost'); + assert.equal(summary.description, 'Strawberry Pasta'); + server.close(); + done(); + }); + }); + + it('site_name', done => { + const app = express(); + app.use((req, res) => { + res.sendFile(__dirname + '/htmls/og-site_name.html'); + }); + const server = app.listen(80, async () => { + const summary = await summaly('http://localhost'); + assert.equal(summary.sitename, 'Strawberry Pasta'); + server.close(); + done(); + }); + }); + + it('thumbnail', done => { + const app = express(); + app.use((req, res) => { + res.sendFile(__dirname + '/htmls/og-image.html'); + }); + const server = app.listen(80, async () => { + const summary = await summaly('http://localhost'); + assert.equal(summary.thumbnail, 'https://himasaku.net/himasaku.png'); + server.close(); + done(); + }); + }); +});