-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
102 lines (82 loc) · 2.53 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*!
* minibase-create-plugin <https://github.com/node-minibase/minibase-create-plugin>
*
* Copyright (c) Charlike Mike Reagent <@tunnckoCore> (https://i.am.charlike.online)
* Released under the MIT license.
*/
/* jshint asi:true */
'use strict'
var test = require('mukla')
var createPlugin = require('./index')
var plugins = require('base-plugins')
var Base = require('base')
var dush = require('dush')
var app = dush()
test('should return a function that accepts options and returns a plugin', function (done) {
app.once('error', done)
var called = 0
var plugin = createPlugin('fooquxie', function (app, options) {
test.strictEqual(options.foo, 'bar')
called++
})
app.use(plugin({ foo: 'bar' }))
test.strictEqual(called, 1)
test.strictEqual(app.registered.fooquxie, true)
done()
})
test('should merge plugin options with these passed through .use method', function (done) {
app.once('error', done)
var called = false
var plugin = createPlugin(function (app, options) {
test.strictEqual(options.aaa, 'bbb')
test.strictEqual(options.ccc, 12345)
called = true
})
app.use('foo', plugin({ aaa: 'bbb' }), {
ccc: 12345
})
test.strictEqual(called, true)
test.strictEqual(app.registered.foo, true)
done()
})
test('should not merge plugin options into app.options', function (done) {
var called = false
var app = dush()
var plugin = createPlugin('zzz', function (app, options) {
test.strictEqual(app.options.foo, 'bar')
test.strictEqual(app.options.aaa, undefined)
test.strictEqual(app.options.ccc, undefined)
test.strictEqual(options.aaa, 'bbb')
test.strictEqual(options.ccc, 'ddd')
called = true
})
app.once('error', done)
app.options = { foo: 'bar' }
app.use(plugin({ aaa: 'bbb' }), { ccc: 'ddd' })
test.strictEqual(called, true)
test.strictEqual(app.registered.zzz, true)
done()
})
test('should work for raw Base apps, which not use base-plugins', function (done) {
var plugin = createPlugin(function somePlugin (app, base, options, env) {
test.strictEqual(arguments.length, 4)
test.strictEqual(options.abc, 'xyz')
done()
})
var base = new Base()
base.on('error', done)
base.use(plugin({ abc: 'xyz' }))
done()
})
test('should work for Base apps that uses base-plugins', function (done) {
var base = new Base()
base.use(plugins())
var foobarPlugin = createPlugin(function (app, base, options) {
test.deepEqual(options, {
xxx: 'vbz',
baz: 12345
})
done()
})
base.use(foobarPlugin({ xxx: 'vbz' }), { baz: 12345 })
})