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 26e7640..ade2441 100644 --- a/package.json +++ b/package.json @@ -9,16 +9,19 @@ "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/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", 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 principle + + +

KISS principle

+

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 principle

+

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..f8afda6 --- /dev/null +++ b/test/htmls/og-description.html @@ -0,0 +1,13 @@ + + + + + + + YEE HAW + + +

Yo

+

Hey hey hey syuilo.

+ + diff --git a/test/htmls/og-title.html b/test/htmls/og-title.html new file mode 100644 index 0000000..78ff54c --- /dev/null +++ b/test/htmls/og-title.html @@ -0,0 +1,13 @@ + + + + + + + YEE HAW + + +

Yo

+

Hey hey hey syuilo.

+ + diff --git a/test/index.ts b/test/index.ts index 691c362..5541f89 100644 --- a/test/index.ts +++ b/test/index.ts @@ -2,8 +2,9 @@ * Tests! */ -import http from 'http'; import chai from 'chai'; +import * as express from 'express'; + import summaly from '../'; Error.stackTraceLimit = Infinity; @@ -16,6 +17,15 @@ process.on('unhandledRejection', console.dir); const should = chai.should(); -it('well-defined meta site', async () => { - should.equal(await summaly('localhost:0'), 'hoge'); +describe('OGP', () => { + it('title', () => { + const server = express(); + server.use((req, res) => { + res.sendFile('./htmls/og-title.html'); + }); + server.listen(0, async () => { + const summary = await summaly('localhost:0'); + should.equal(summary.title, 'KISS principle'); + }); + }); });