-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
83 lines (70 loc) · 3.56 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
'use strict'
const test = require('tape')
const bm = require('.')
test('minimal manifest', function (t) {
const input = { name: 'test' }
const output = bm(input)
t.same(input, { name: 'test' })
t.ok(input !== output, 'new object identity')
t.same(output, {
name: 'test',
wants: {},
supports: {},
options: {}
})
t.end()
})
test('normalized manifest', function (t) {
const input = { name: 'test', wants: {}, supports: {}, options: {} }
const output = bm(input)
t.ok(input === output, 'kept object identity')
t.end()
})
test('manifest must be an object', function (t) {
t.throws(() => bm(), /TypeError: Manifest must be an object/)
t.throws(() => bm(null), /TypeError: Manifest must be an object/)
t.throws(() => bm([]), /TypeError: Manifest must be an object/)
t.throws(() => bm(''), /TypeError: Manifest must be an object/)
t.end()
})
test('name is required and must be a lowercase string', function (t) {
t.throws(() => bm({}), /TypeError: The manifest.name property is required and must be a string/)
t.throws(() => bm({ name: null }), /TypeError: The manifest.name property is required and must be a string/)
t.throws(() => bm({ name: '' }), /TypeError: The manifest.name property is required and must be a string/)
t.throws(() => bm({ name: {} }), /TypeError: The manifest.name property is required and must be a string/)
t.throws(() => bm({ name: 'aA' }), /TypeError: The manifest.name property must be lowercase/)
t.end()
})
test('version must be a string', function (t) {
t.throws(() => bm({ name: 'a', version: 0 }), /TypeError: The optional manifest.version property must be a string/)
t.throws(() => bm({ name: 'a', version: 30 }), /TypeError: The optional manifest.version property must be a string/)
t.throws(() => bm({ name: 'a', version: '' }), /TypeError: The optional manifest.version property must be a string/)
t.end()
})
test('title must be a string', function (t) {
t.throws(() => bm({ name: 'a', title: 0 }), /TypeError: The optional manifest.title property must be a string/)
t.throws(() => bm({ name: 'a', title: 30 }), /TypeError: The optional manifest.title property must be a string/)
t.throws(() => bm({ name: 'a', title: '' }), /TypeError: The optional manifest.title property must be a string/)
t.end()
})
test('provider must be a string', function (t) {
t.throws(() => bm({ name: 'a', provider: 0 }), /TypeError: The optional manifest.provider property must be a string/)
t.throws(() => bm({ name: 'a', provider: 30 }), /TypeError: The optional manifest.provider property must be a string/)
t.throws(() => bm({ name: 'a', provider: '' }), /TypeError: The optional manifest.provider property must be a string/)
t.end()
})
test('wants must be an object', function (t) {
t.throws(() => bm({ name: 'a', wants: [] }), /TypeError: The optional manifest.wants property must be an object/)
t.throws(() => bm({ name: 'a', wants: '' }), /TypeError: The optional manifest.wants property must be an object/)
t.end()
})
test('supports must be an object', function (t) {
t.throws(() => bm({ name: 'a', supports: [] }), /TypeError: The optional manifest.supports property must be an object/)
t.throws(() => bm({ name: 'a', supports: '' }), /TypeError: The optional manifest.supports property must be an object/)
t.end()
})
test('options must be an object', function (t) {
t.throws(() => bm({ name: 'a', options: [] }), /TypeError: The optional manifest.options property must be an object/)
t.throws(() => bm({ name: 'a', options: '' }), /TypeError: The optional manifest.options property must be an object/)
t.end()
})