Merge pull request #25 from syuilo/test

Test #12
This commit is contained in:
syuilo⭐️ 2017-02-08 17:47:57 +09:00 committed by GitHub
commit f5d1ce5d80
9 changed files with 164 additions and 1 deletions

View File

@ -65,6 +65,10 @@ console.log(summary); // will be ... ↓
*/
```
Testing
-------
`npm run test`
License
-------
[MIT](LICENSE)

View File

@ -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": {

12
test/htmls/basic.html Normal file
View File

@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>KISS principle</title>
</head>
<body>
<h1>KISS principle</h1>
<p>KISS is an acronym for "Keep it simple, stupid" as a design principle noted by the U.S. Navy in 1960.</p>
</body>
</html>

11
test/htmls/no-metas.html Normal file
View File

@ -0,0 +1,11 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<h1>KISS principle</h1>
<p>KISS is an acronym for "Keep it simple, stupid" as a design principle noted by the U.S. Navy in 1960.</p>
</body>
</html>

View File

@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta property="og:description" content="Strawberry Pasta">
<title>YEE HAW</title>
</head>
<body>
<h1>Yo</h1>
<p>Hey hey hey syuilo.</p>
</body>
</html>

13
test/htmls/og-image.html Normal file
View File

@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta property="og:image" content="https://himasaku.net/himasaku.png">
<title>YEE HAW</title>
</head>
<body>
<h1>Yo</h1>
<p>Hey hey hey syuilo.</p>
</body>
</html>

View File

@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta property="og:site_name" content="Strawberry Pasta">
<title>YEE HAW</title>
</head>
<body>
<h1>Yo</h1>
<p>Hey hey hey syuilo.</p>
</body>
</html>

13
test/htmls/og-title.html Normal file
View File

@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta property="og:title" content="Strawberry Pasta">
<title>YEE HAW</title>
</head>
<body>
<h1>Yo</h1>
<p>Hey hey hey syuilo.</p>
</body>
</html>

77
test/index.js Normal file
View File

@ -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();
});
});
});