Skip to content

Commit

Permalink
Merge branch 'release/1.2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
compeak committed Oct 25, 2018
2 parents 8eece11 + 986f75d commit d7bf933
Show file tree
Hide file tree
Showing 19 changed files with 1,075 additions and 551 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ sudo: false
node_js:
- '8'
- '10'
matrix:
allow_failures:
- node_js: 10
script:
- yarn test
before_install: yarn global add greenkeeper-lockfile@1
Expand Down
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog

## v1.2.1, 2018-08031
## v1.2.2, 2018-10-25

- Upgraded dependencies.
- Improved tests to support Node versions 8 and 10.

## v1.2.1, 2018-08-31

- Fixed docker build by downgrading `eslint` dependency to `4.19.1`.

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM alpine:3.7
FROM alpine:3.8

ENV PORT 8080
EXPOSE 8080
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const {NotFound} = require('./lib/exceptions')
const {URL} = require('url')
const { NotFound } = require('./lib/exceptions')
const { URL } = require('url')
const Embetty = require('@heise/embetty-base')
const express = require('express')
const helmet = require('helmet')
Expand Down
2 changes: 1 addition & 1 deletion lib/exceptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ NotFound.statusCode = 404
const Forbidden = new Error()
Forbidden.statusCode = 403

module.exports = {BadRequest, Forbidden, NotFound}
module.exports = { BadRequest, Forbidden, NotFound }
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@heise/embetty-server",
"version": "1.2.1",
"version": "1.2.2",
"main": "index.js",
"repository": "[email protected]:heiseonline/embetty-server.git",
"author": "Philipp Busse <[email protected]>",
Expand All @@ -13,19 +13,20 @@
"scripts": {
"start": "./bin/www",
"dev": "nodemon ./bin/www",
"test": "NODE_ENV=test mocha --bail --check-leaks -t 10000"
"test": "NODE_ENV=test mocha --bail --check-leaks -t 10000",
"lint": "eslint ."
},
"publishConfig": {
"access": "public",
"registry": "http://registry.npmjs.org"
},
"devDependencies": {
"@heise/request-promise-native-record": "^1.0.1",
"eslint": "^4.19.1",
"eslint": "^5.7.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-import": "^2.10.0",
"eslint-plugin-node": "^6.0.1",
"eslint-plugin-promise": "^3.7.0",
"eslint-plugin-node": "^7.0.1",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0",
"mocha": "^5.0.0",
"nodemon": "^1.12.1",
Expand All @@ -36,7 +37,7 @@
"@heise/embetty-base": "^1.0.0-beta.5",
"commander": "^2.15.1",
"cors": "^2.8.4",
"debug": "^3.1.0",
"debug": "^4.1.0",
"express": "^4.16.2",
"helmet": "^3.9.0",
"morgan": "^1.9.0",
Expand Down
4 changes: 2 additions & 2 deletions routes/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {Forbidden} = require('../lib/exceptions')
const { Forbidden } = require('../lib/exceptions')
const cors = require('cors')
const debug = require('debug')('embetty.web:server')
const express = require('express')
Expand Down Expand Up @@ -26,7 +26,7 @@ router.use(cors({
router.use('/embetty.js', (req, res, next) => {
const embettyPath = require.resolve('@heise/embetty/dist/embetty.js')
res.type('application/javascript')
fs.createReadStream(embettyPath, {encoding: 'utf8'}).pipe(res)
fs.createReadStream(embettyPath, { encoding: 'utf8' }).pipe(res)
})
router.use('/tweet', tweet)
router.use('/video', video)
Expand Down
4 changes: 2 additions & 2 deletions routes/tweet.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {BadRequest, NotFound} = require('../lib/exceptions')
const { BadRequest, NotFound } = require('../lib/exceptions')
const express = require('express')

const router = express.Router()
Expand Down Expand Up @@ -52,7 +52,7 @@ router.get('/:id-images-:number', async (req, res, next) => {
})

router.get('/:id.amp', (req, res) => {
res.render('tweet.html', {tweet: req.tweet})
res.render('tweet.html', { tweet: req.tweet })
})

router.get('/:id', (req, res) => {
Expand Down
6 changes: 3 additions & 3 deletions routes/video/facebook.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {BadRequest} = require('../../lib/exceptions')
const { BadRequest } = require('../../lib/exceptions')
const express = require('express')

const router = express.Router()
Expand All @@ -15,7 +15,7 @@ router.param('id', async (req, res, next, id) => {

router.get('/:id-poster-image', async (req, res, next) => {
try {
const {data, type} = await req.video.getPosterImage()
const { data, type } = await req.video.getPosterImage()
if (!data) return next()
res.type(type)
res.send(data)
Expand All @@ -25,7 +25,7 @@ router.get('/:id-poster-image', async (req, res, next) => {
})

router.get('/:id.amp', (req, res) => {
res.render('video.html', {video: req.video})
res.render('video.html', { video: req.video })
})

router.get('/:id', (req, res) => {
Expand Down
8 changes: 4 additions & 4 deletions routes/video/vimeo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {BadRequest} = require('../../lib/exceptions')
const { BadRequest } = require('../../lib/exceptions')
const express = require('express')

const router = express.Router()
Expand All @@ -15,7 +15,7 @@ router.param('id', async (req, res, next, id) => {

router.get('/:id-poster-image', async (req, res, next) => {
try {
const {data, type} = await req.video.getPosterImage()
const { data, type } = await req.video.getPosterImage()
if (!data) return next()
res.type(type)
res.send(data)
Expand All @@ -25,8 +25,8 @@ router.get('/:id-poster-image', async (req, res, next) => {
})

router.get('/:id.amp', (req, res) => {
const attributes = {...req.query}
res.render('video.html', {video: req.video, attributes})
const attributes = { ...req.query }
res.render('video.html', { video: req.video, attributes })
})

router.get('/:id', (req, res) => {
Expand Down
8 changes: 4 additions & 4 deletions routes/video/youtube.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {BadRequest} = require('../../lib/exceptions')
const { BadRequest } = require('../../lib/exceptions')
const express = require('express')

const router = express.Router()
Expand All @@ -15,7 +15,7 @@ router.param('id', async (req, res, next, id) => {

router.get('/:id-poster-image', async (req, res, next) => {
try {
const {data, type} = await req.video.getPosterImage()
const { data, type } = await req.video.getPosterImage()
if (!data) return next()
res.type(type)
res.send(data)
Expand All @@ -25,8 +25,8 @@ router.get('/:id-poster-image', async (req, res, next) => {
})

router.get('/:id.amp', (req, res) => {
const attributes = {...req.query}
res.render('video.html', {video: req.video, attributes})
const attributes = { ...req.query }
res.render('video.html', { video: req.video, attributes })
})

router.get('/:id', (req, res) => {
Expand Down
4 changes: 2 additions & 2 deletions test/_util.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {spawn} = require('child_process')
const { spawn } = require('child_process')
const path = require('path')

module.exports = class Util {
Expand All @@ -15,7 +15,7 @@ module.exports = class Util {
cmd.stdout.on('data', d => { stdout += d.toString() })

cmd.on('close', exitCode => {
if (exitCode === 0) return resolve({cmd, exitCode, stdout})
if (exitCode === 0) return resolve({ cmd, exitCode, stdout })
const error = new Error(exitCode)
error.stdout = stdout
error.exitCode = exitCode
Expand Down
30 changes: 15 additions & 15 deletions test/cli.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
const {spawnSync} = require('child_process')
const {embettyBin, run} = require('./_util')
const {version} = require('../package.json')
const { spawnSync } = require('child_process')
const { embettyBin, run } = require('./_util')
const { version } = require('../package.json')
const assert = require('assert')

describe('CLI', () => {
it('embetty', async () => {
const {exitCode, stdout} = await run(embettyBin)
const { exitCode, stdout } = await run(embettyBin)
assert.ok(/Usage: /.test(stdout))
assert.equal(exitCode, 0)
assert.strictEqual(exitCode, 0)
})

it('embetty --help', async () => {
const {exitCode, stdout} = await run(embettyBin, ['--help'])
const { exitCode, stdout } = await run(embettyBin, ['--help'])
assert.ok(stdout.includes('Usage: embetty <command> [options'))
assert.equal(exitCode, 0)
assert.strictEqual(exitCode, 0)
})

it('embetty --version', async () => {
const {exitCode, stdout} = await run(embettyBin, ['--version'])
assert.equal(stdout, version + '\n')
assert.equal(exitCode, 0)
const { exitCode, stdout } = await run(embettyBin, ['--version'])
assert.strictEqual(stdout, version + '\n')
assert.strictEqual(exitCode, 0)
})

it('embetty start --help', async () => {
const {exitCode, stdout} = await run(embettyBin, ['start', '--help'])
const { exitCode, stdout } = await run(embettyBin, ['start', '--help'])
assert.ok(stdout.includes('Usage: embetty-start [options]'))
assert.equal(exitCode, 0)
assert.strictEqual(exitCode, 0)
})

it('embetty start --port <port>', () => {
const {stderr} = spawnSync(embettyBin, ['start', '-v', '--port', 8888], {timeout: 3000})
const { stderr } = spawnSync(embettyBin, ['start', '-v', '--port', 8888], { timeout: 3000 })
assert.ok(stderr.toString().includes('Listening on port 8888'))
})

it('embetty start --debug', () => {
const {stderr} = spawnSync(embettyBin, ['start', '--debug'], {timeout: 3000})
const { stderr } = spawnSync(embettyBin, ['start', '--debug'], { timeout: 3000 })
const out = stderr.toString()
assert.ok(out.includes('express:router'))
assert.ok(out.includes('embetty.base'))
})

it('embetty start --cache <cache>', () => {
const {stderr} = spawnSync(embettyBin, ['start', '-v', '--cache', 'redis://'], {timeout: 3000})
const { stderr } = spawnSync(embettyBin, ['start', '-v', '--cache', 'redis://'], { timeout: 3000 })
assert.ok(stderr.toString().includes('Using Redis cache'))
})
})
18 changes: 9 additions & 9 deletions test/cors.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ describe('CORS', () => {
const origin = 'http://example.com'
process.env.VALID_ORIGINS = origin
const response = await request(app).get('/').set('Origin', origin)
assert.equal(response.headers['access-control-allow-origin'], origin)
assert.equal(response.status, 404)
assert.strictEqual(response.headers['access-control-allow-origin'], origin)
assert.strictEqual(response.status, 404)
})

it('should send a 403 status if no valid origin has been sent', async () => {
process.env.VALID_ORIGINS = 'http://example.com'
const response = await request(app)
.get('/')
.set('Origin', 'http://otherorigin.example.com')
assert.equal(response.status, 403)
assert.strictEqual(response.status, 403)
})

it('should send dynamic origin headers', async () => {
Expand All @@ -26,26 +26,26 @@ describe('CORS', () => {
const response = await request(app)
.get('/')
.set('Origin', 'http://a.example.com')
assert.equal(response.headers['access-control-allow-origin'], 'http://a.example.com')
assert.equal(response.status, 404)
assert.strictEqual(response.headers['access-control-allow-origin'], 'http://a.example.com')
assert.strictEqual(response.status, 404)

const response2 = await request(app)
.get('/')
.set('Origin', 'http://b.example.com')
assert.equal(response2.headers['access-control-allow-origin'], 'http://b.example.com')
assert.equal(response2.status, 404)
assert.strictEqual(response2.headers['access-control-allow-origin'], 'http://b.example.com')
assert.strictEqual(response2.status, 404)

const response3 = await request(app)
.get('/')
.set('Origin', 'http://c.example.com')
assert.equal(response3.status, 403)
assert.strictEqual(response3.status, 403)
})

it('should support "*" origin', async () => {
process.env.VALID_ORIGINS = '*'
const response = await request(app)
.get('/')
.set('Origin', 'http://example.com')
assert.equal(response.status, 404)
assert.strictEqual(response.status, 404)
})
})
2 changes: 1 addition & 1 deletion test/embetty-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ describe('embetty-server', () => {

it('should provide the version', async () => {
const response = await request(app).get('/version')
assert.equal(response.text, require('../package.json').version)
assert.strictEqual(response.text, require('../package.json').version)
})
})
4 changes: 2 additions & 2 deletions test/exceptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ const Exceptions = require('../lib/exceptions')

describe('Exceptions', () => {
it('#BadRequest', () => {
assert.equal(Exceptions.BadRequest.statusCode, 400)
assert.strictEqual(Exceptions.BadRequest.statusCode, 400)
})

it('#NotFound', () => {
assert.equal(Exceptions.NotFound.statusCode, 404)
assert.strictEqual(Exceptions.NotFound.statusCode, 404)
})
})
10 changes: 5 additions & 5 deletions test/tweet.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {start} = require('@heise/request-promise-native-record')
const { start } = require('@heise/request-promise-native-record')
const assert = require('assert')
const path = require('path')
const request = require('supertest')
Expand Down Expand Up @@ -42,7 +42,7 @@ describe('Tweet', () => {
.get(`/tweet/${Tweets.s200}`)
.expect('Content-Type', /json/)
.expect(200)
assert.equal(response.body.id_str, Tweets.s200)
assert.strictEqual(response.body.id_str, Tweets.s200)
})

it('/tweet/:id-profile-image => 404', async () => {
Expand All @@ -66,7 +66,7 @@ describe('Tweet', () => {
assert.ok(Buffer.isBuffer(response.body))
const imageLength = Buffer.byteLength(response.body)
assert.ok(imageLength > 100)
assert.equal(response.headers['content-length'], imageLength)
assert.strictEqual(response.headers['content-length'], `${imageLength}`)
})

it('/tweet/:id-images-:number => 400', async () => {
Expand All @@ -90,7 +90,7 @@ describe('Tweet', () => {
assert.ok(Buffer.isBuffer(response.body))
const imageLength = Buffer.byteLength(response.body)
assert.ok(imageLength > 100)
assert.equal(response.headers['content-length'], imageLength)
assert.strictEqual(response.headers['content-length'], `${imageLength}`)
})

it('/tweet/:id-link-image => 200', async () => {
Expand All @@ -102,7 +102,7 @@ describe('Tweet', () => {
assert.ok(Buffer.isBuffer(response.body))
const imageLength = Buffer.byteLength(response.body)
assert.ok(imageLength > 100)
assert.equal(response.headers['content-length'], imageLength)
assert.strictEqual(response.headers['content-length'], `${imageLength}`)
})

it('/tweet/:id-link-image => 404', async () => {
Expand Down
Loading

0 comments on commit d7bf933

Please sign in to comment.