1 |
|
2 |
|
3 |
|
4 |
|
5 | 'use strict'
|
6 |
|
7 | const define = require('../lib/define.js')
|
8 | const assert = require('assert')
|
9 | const { moduleProxy } = require('apemanmock')
|
10 | const co = require('co')
|
11 |
|
12 | describe('define', function () {
|
13 | this.timeout(18000)
|
14 |
|
15 | before(() => co(function * () {
|
16 |
|
17 | }))
|
18 |
|
19 | after(() => co(function * () {
|
20 |
|
21 | }))
|
22 |
|
23 | it('Create an instance', () => co(function * () {
|
24 | let module = define({
|
25 | logging: true
|
26 | })
|
27 | let api = moduleProxy(module, { ctx: { state: {} } })
|
28 | assert.ok(api)
|
29 | }))
|
30 |
|
31 | it('Call API methods', () => co(function * () {
|
32 | let module = define({
|
33 | logging: true
|
34 | })
|
35 | let api = moduleProxy(module, { ctx: { state: {} } })
|
36 | let pong = yield api.ping('The pong!')
|
37 | assert.equal(pong, 'The pong!')
|
38 |
|
39 | yield api.compileAll('*.js', {
|
40 | out: `${__dirname}/../tmp/testing-compiled`,
|
41 | cwd: `${__dirname}/../misc/mock`
|
42 | })
|
43 | }))
|
44 |
|
45 | it('Compare spec and implement', () => co(function * () {
|
46 | let module = define({
|
47 | logging: false
|
48 | })
|
49 | let implNames = Object.keys(module).filter((name) => !/^[\$_]/.test(name))
|
50 | let specNames = Object.keys(module.$spec)
|
51 | for (let implName of implNames) {
|
52 | assert.ok(!!~specNames.indexOf(implName), `${implName} is implemented, but not described in "$spec"`)
|
53 | }
|
54 | for (let specName of specNames) {
|
55 | assert.ok(!!~implNames.indexOf(specName), `${specName} is described in "$spec", but not implemented`)
|
56 | }
|
57 | }))
|
58 | })
|
59 |
|
60 |
|