UNPKG

2.15 kBJavaScriptView Raw
1/**
2 * Change into the dummy app dir
3 */
4process.chdir('./app');
5
6var assert = require('assert')
7 ,Kernel = require('../kernel/kernel.js')
8 ,krnl = new Kernel({ foo : 'bar' })
9 ,beating = false;
10
11/**
12 * Test configuration merge
13 */
14assert.strictEqual(krnl.config.foo, 'bar');
15console.log(krnl.utility.ansi('green', '[ OK ]') + ' config merge');
16
17/**
18 * Test include
19 */
20var cls = krnl.include(krnl.appdir + '/models/dummy');
21assert.ok(typeof cls.new === 'function');
22assert.ok(typeof cls.singleton === 'function');
23assert.ok(typeof cls.extends === 'function');
24assert.ok(typeof cls.module === 'function');
25assert.ok(typeof cls.prototype === 'object');
26assert.ok(typeof cls.context === 'object');
27console.log(krnl.utility.ansi('green', '[ OK ]') + ' kernel include');
28
29/**
30 * Test module kernel binding
31 */
32var obj = cls.new();
33assert.ok(obj.kernel instanceof Kernel);
34console.log(krnl.utility.ansi('green', '[ OK ]') + ' kernel bind');
35
36/**
37 * Test module loading through Instance
38 */
39var Instanceinc = krnl.include(krnl.kerneldir + '/instance')
40 ,Instance = Instanceinc.module
41 ,inst = Instanceinc.singleton()
42 ,cls = inst.model('dummy');
43
44assert.ok(typeof cls.new === 'function');
45assert.ok(typeof cls.singleton === 'function');
46assert.ok(typeof cls.extends === 'function');
47assert.ok(typeof cls.module === 'function');
48assert.ok(typeof cls.prototype === 'object');
49assert.ok(typeof cls.context === 'object');
50console.log(krnl.utility.ansi('green', '[ OK ]') + ' instance include');
51
52var obj = cls.new();
53assert.ok(obj.instance instanceof Instance);
54console.log(krnl.utility.ansi('green', '[ OK ]') + ' instance bind');
55
56/**
57 * Test for heartbeat
58 */
59krnl.once(krnl.HEARTBEAT, function() {
60 beating = true;
61});
62setTimeout(function() {
63 assert.ok(beating);
64 console.log(krnl.utility.ansi('green', '[ OK ]') + ' heartbeat');
65 krnl.shutdown();
66}, 1500);
67
68/**
69 * Test for shutdown
70 */
71krnl.once(krnl.OFFLINE, function() {
72 beating = false;
73});
74setTimeout(function() {
75 assert.ok(!beating);
76 console.log(krnl.utility.ansi('green', '[ OK ]') + ' shutdown');
77}, 5000);
\No newline at end of file