Skip to content

Commit

Permalink
test: 3rd party plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
labaikie authored and gr2m committed Jun 13, 2017
1 parent c825821 commit f7db55f
Show file tree
Hide file tree
Showing 15 changed files with 407 additions and 120 deletions.
4 changes: 3 additions & 1 deletion test/integration/force-gzip-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ var hapiPluginOptions = {
inMemory: true,
loglevel: 'error',
paths: {},
PouchDB: PouchDB
PouchDB: PouchDB,
plugins: [],
app: {}
}
}

Expand Down
4 changes: 3 additions & 1 deletion test/integration/handle-404-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ var hapiPluginOptions = {
inMemory: true,
loglevel: 'error',
paths: {},
PouchDB: PouchDB
PouchDB: PouchDB,
plugins: [],
app: {}
}
}

Expand Down
4 changes: 3 additions & 1 deletion test/integration/handle-hoodie-request-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ var hapiPluginOptions = {
inMemory: true,
loglevel: 'error',
paths: {},
PouchDB: PouchDB
PouchDB: PouchDB,
plugins: [],
app: {}
}
}

Expand Down
23 changes: 23 additions & 0 deletions test/integration/plugins-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var simple = require('simple-mock')
var test = require('tap').test

var hapiPlugin = require('../../server')
var serverMock = {
register: simple.stub().callbackWith(null),
ext: simple.stub()
}

require('npmlog').level = 'error'

test('plugins', function (t) {
hapiPlugin.register(serverMock, {
paths: {
data: '.'
},
plugins: ['hoodie-plugin-foobar'],
app: {}
}, function (error) {
t.error(error)
t.end()
})
})
32 changes: 23 additions & 9 deletions test/integration/server-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,28 @@ test('server', function (t) {
hapiPlugin.register(serverMock, {
paths: {
data: '.'
}
}, function (error, config) {
},
plugins: [],
app: {}
}, function (error) {
t.error(error)
t.end()
})
})

test('server with options without options.path (#554)', function (t) {
hapiPlugin.register(serverMock, {}, function (error, config) {
t.error(error)
t.end()
})
test('does not modify the passed options object', function (t) {
var options = {
db: {
url: 'http://admin:admin@localhost:5984'
},
plugins: [],
app: {}
}

hapiPlugin.register(serverMock, options, function () {})

t.is(options.db.url, 'http://admin:admin@localhost:5984')
t.end()
})

test('error on register is passed to callback', function (t) {
Expand All @@ -37,7 +47,9 @@ test('error on register is passed to callback', function (t) {
hapiPlugin.register(serverErrorMock, {
paths: {
data: '.'
}
},
plugins: [],
app: {}
}, function (error, server, options) {
t.ok(error)
t.end()
Expand All @@ -48,7 +60,9 @@ test('application root with valid server module', function (t) {
var options = {
paths: {
public: 'public'
}
},
plugins: [],
app: {}
}
var savedPath = process.cwd()
t.tearDown(function () {
Expand Down
4 changes: 3 additions & 1 deletion test/integration/smoke-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ var hapiPluginOptions = {
inMemory: true,
loglevel: 'error',
paths: {},
PouchDB: PouchDB
PouchDB: PouchDB,
plugins: [],
app: {}
}
}

Expand Down
17 changes: 17 additions & 0 deletions test/unit/cli/app-defaults-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,22 @@ test('app options', function (group) {
t.end()
})

group.test('with hoodie.name', function (t) {
var getAppDefaults = proxyquire('../../../cli/app-defaults', {
'path': pathMock,
'./package.json': {
name: 'pkg-name',
hoodie: {
name: 'foo'
}
}
})
var options = getAppDefaults()

t.deepEqual(options.name, 'foo', 'sets name from pkg.hoodie.name')

t.end()
})

group.end()
})
3 changes: 3 additions & 0 deletions test/unit/cli/hoodie-default-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ test('hoodie defaults test', function (group) {
t.deepEqual(defaults, {
address: '127.0.0.1',
adminPassword: undefined,
app: {},
client: {},
data: '.hoodie',
dbAdapter: 'pouchdb-adapter-fs',
Expand All @@ -16,7 +17,9 @@ test('hoodie defaults test', function (group) {
dbUrlUsername: undefined,
inMemory: false,
loglevel: 'warn',
name: undefined,
port: 8080,
plugins: [],
public: 'public',
url: undefined
}, 'setting hoodie defaults')
Expand Down
38 changes: 31 additions & 7 deletions test/unit/cli/options-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,20 @@ var packageJsonMock = {

var mockWebrootLocator = simple.stub()

var hoodieDefaults = {
port: 'hoodie-default-port',
public: 'hoodie-default-public',
dbUrl: 'hoodie-default-dbUrl',
dbAdapter: 'hoodie-default-dbAdapter',
address: 'hoodie-localhost',
plugins: []
}

function createCliOptionsProxy (yargsApi) {
return proxyquire('../../../cli/options', {
'npmlog': { warn: simple.spy() },
'./hoodie-defaults': function () {
return {
port: 'hoodie-default-port',
public: 'hoodie-default-public',
dbUrl: 'hoodie-default-dbUrl',
dbAdapter: 'hoodie-default-dbAdapter',
address: 'hoodie-localhost'
}
return hoodieDefaults
},
'./app-defaults': mockAppDefaults(),
'./webroot-locator': mockWebrootLocator,
Expand Down Expand Up @@ -127,3 +130,24 @@ test('bindAddress', function (t) {

t.end()
})

test('app plugin', function (t) {
var getOptions = proxyquire('../../../cli/options', {
'fs': {
existsSync: simple.stub().returnWith(true)
},
'npmlog': { warn: simple.spy() },
'./hoodie-defaults': function () {
return hoodieDefaults
},
'./app-defaults': mockAppDefaults(),
'./webroot-locator': mockWebrootLocator,
'yargs': createYargsMock({}),
'../package.json': packageJsonMock
})

var options = getOptions('project-path')
t.deepEqual(options.plugins, ['project-path'])

t.end()
})
8 changes: 4 additions & 4 deletions test/unit/client/bundle-handler-factory-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ test('bundle-handler-factory', function (group) {
done()
})

group.test('passes clientPath, targetPath and config to bundleClient', function (t) {
group.test('passes clientPath, targetPath and options to bundleClient', function (t) {
var clientPath = '/client/path'
var targetPath = '/target/path'
var config = {}
var options = {}

var handler = createHandler(clientPath, targetPath, config)
var handler = createHandler(clientPath, targetPath, options)
handler()

t.is(bundleStub.callCount, 1, 'bundleClient gets called')
var bundleStubArgs = bundleStub.lastCall.args

t.is(bundleStubArgs[0], clientPath, 'passes clientPath as first argument')
t.is(bundleStubArgs[1], targetPath, 'passes targetPath as second argument')
t.equals(bundleStubArgs[2], config, 'passes config as third argument')
t.equals(bundleStubArgs[2], options, 'passes options as third argument')

t.end()
})
Expand Down
Loading

0 comments on commit f7db55f

Please sign in to comment.