From d14e72b01bbb412e51cdd792d74815c068374ce9 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 8 Feb 2017 14:26:19 +0900 Subject: [PATCH 1/8] [WIP] test --- package.json | 4 ++++ test/index.ts | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 test/index.ts diff --git a/package.json b/package.json index 4b7aaf6..4727322 100644 --- a/package.json +++ b/package.json @@ -12,12 +12,16 @@ "build": "gulp build" }, "devDependencies": { + "@types/chai": "3.4.34", "@types/debug": "0.0.29", + "@types/mocha": "2.2.39", "@types/node": "7.0.5", "@types/request": "0.0.39", + "chai": "3.5.0", "event-stream": "3.3.4", "gulp": "3.9.1", "gulp-typescript": "3.1.4", + "mocha": "3.2.0", "typescript": "2.1.5" }, "dependencies": { diff --git a/test/index.ts b/test/index.ts new file mode 100644 index 0000000..691c362 --- /dev/null +++ b/test/index.ts @@ -0,0 +1,21 @@ +/** + * Tests! + */ + +import http from 'http'; +import chai from 'chai'; +import summaly from '../'; + +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); + +const should = chai.should(); + +it('well-defined meta site', async () => { + should.equal(await summaly('localhost:0'), 'hoge'); +}); From e352fa13ad4127ebb2fc6d8c070dd654d6574a02 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 8 Feb 2017 15:17:28 +0900 Subject: [PATCH 2/8] [WIP] test --- README.md | 4 ++++ package.json | 5 ++++- test/htmls/basic.html | 12 ++++++++++++ test/htmls/no-metas.html | 11 +++++++++++ test/htmls/og-description.html | 13 +++++++++++++ test/htmls/og-title.html | 13 +++++++++++++ test/index.ts | 16 +++++++++++++--- 7 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 test/htmls/basic.html create mode 100644 test/htmls/no-metas.html create mode 100644 test/htmls/og-description.html create mode 100644 test/htmls/og-title.html 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'); + }); + }); }); From 4dd1c81b3f43da44e646db1ea12a9c6c23397be7 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 8 Feb 2017 15:45:48 +0900 Subject: [PATCH 3/8] [Test] Fix --- test/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/index.ts b/test/index.ts index 5541f89..8aeca49 100644 --- a/test/index.ts +++ b/test/index.ts @@ -2,7 +2,7 @@ * Tests! */ -import chai from 'chai'; +import * as chai from 'chai'; import * as express from 'express'; import summaly from '../'; From 6c51d8cdc25e7a723e081df7366636cbe316d509 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 8 Feb 2017 17:02:20 +0900 Subject: [PATCH 4/8] Test --- test/index.js | 37 +++++++++++++++++++++++++++++++++++++ test/index.ts | 31 ------------------------------- 2 files changed, 37 insertions(+), 31 deletions(-) create mode 100644 test/index.js delete mode 100644 test/index.ts diff --git a/test/index.js b/test/index.js new file mode 100644 index 0000000..5e6a7fc --- /dev/null +++ b/test/index.js @@ -0,0 +1,37 @@ +/** + * 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 server = express(); + server.use((req, res) => { + res.sendFile(__dirname + '/htmls/og-title.html'); + }); + server.listen(80, async () => { + const summary = await summaly('http://localhost'); + assert.equal(summary.title, 'KISS principle'); + done(); + }); + }); +}); diff --git a/test/index.ts b/test/index.ts deleted file mode 100644 index 8aeca49..0000000 --- a/test/index.ts +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Tests! - */ - -import * as chai from 'chai'; -import * as express from 'express'; - -import summaly from '../'; - -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); - -const should = chai.should(); - -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'); - }); - }); -}); From 7e3c650df2de4067f3773aadb98d62d2fc9a48d1 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 8 Feb 2017 17:23:13 +0900 Subject: [PATCH 5/8] [Test] Better sample --- test/htmls/og-title.html | 2 +- test/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/htmls/og-title.html b/test/htmls/og-title.html index 78ff54c..e0a52b5 100644 --- a/test/htmls/og-title.html +++ b/test/htmls/og-title.html @@ -3,7 +3,7 @@ - + YEE HAW diff --git a/test/index.js b/test/index.js index 5e6a7fc..67c77d0 100644 --- a/test/index.js +++ b/test/index.js @@ -30,7 +30,7 @@ describe('OGP', () => { }); server.listen(80, async () => { const summary = await summaly('http://localhost'); - assert.equal(summary.title, 'KISS principle'); + assert.equal(summary.title, 'Strawberry Pasta'); done(); }); }); From c0c51027d1e6f68640b3db89ab3c8f49cd7b446d Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 8 Feb 2017 17:27:16 +0900 Subject: [PATCH 6/8] =?UTF-8?q?[Test]=20=E3=81=84=E3=81=84=E6=84=9F?= =?UTF-8?q?=E3=81=98=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/htmls/og-description.html | 2 +- test/index.js | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/test/htmls/og-description.html b/test/htmls/og-description.html index f8afda6..e036893 100644 --- a/test/htmls/og-description.html +++ b/test/htmls/og-description.html @@ -3,7 +3,7 @@ - + YEE HAW diff --git a/test/index.js b/test/index.js index 67c77d0..b251395 100644 --- a/test/index.js +++ b/test/index.js @@ -24,13 +24,27 @@ process.on('unhandledRejection', console.dir); describe('OGP', () => { it('title', done => { - const server = express(); - server.use((req, res) => { + const app = express(); + app.use((req, res) => { res.sendFile(__dirname + '/htmls/og-title.html'); }); - server.listen(80, async () => { + 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(); }); }); From 9880b415debc8bfb873fd6d0a7f49703187cf303 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 8 Feb 2017 17:41:49 +0900 Subject: [PATCH 7/8] [Test] Add the og:image test --- test/htmls/og-image.html | 13 +++++++++++++ test/index.js | 13 +++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 test/htmls/og-image.html 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 @@ + + + + + + + YEE HAW + + +

Yo

+

Hey hey hey syuilo.

+ + diff --git a/test/index.js b/test/index.js index b251395..c3f3989 100644 --- a/test/index.js +++ b/test/index.js @@ -48,4 +48,17 @@ describe('OGP', () => { 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(); + }); + }); }); From 0e81c537e74d61842147286f490a1e85bd059629 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 8 Feb 2017 17:46:40 +0900 Subject: [PATCH 8/8] [Test] Add the og:site_name test --- test/htmls/og-site_name.html | 13 +++++++++++++ test/index.js | 13 +++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 test/htmls/og-site_name.html 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 @@ + + + + + + + YEE HAW + + +

Yo

+

Hey hey hey syuilo.

+ + diff --git a/test/index.js b/test/index.js index c3f3989..01edeac 100644 --- a/test/index.js +++ b/test/index.js @@ -49,6 +49,19 @@ describe('OGP', () => { }); }); + 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) => {