UNPKG

1.52 kBJavaScriptView Raw
1/**
2 * Test case for define.
3 * Runs with mocha.
4 */
5'use strict'
6
7const define = require('../lib/define.js')
8const assert = require('assert')
9const { moduleProxy } = require('apemanmock')
10const co = require('co')
11
12describe('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/* global describe, before, after, it */