-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
55 lines (46 loc) · 1.73 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
'use strict';
const requireFromString = require('require-from-string');
const {rollup} = require('rollup');
const rollupNodeResolve = require('rollup-plugin-node-resolve');
const test = require('tape');
function runTest(arrayToSentenceJa, description) {
test(description, t => {
t.strictEqual(arrayToSentenceJa.name, 'arrayToSentenceJa', 'should have a function name.');
t.strictEqual(
arrayToSentenceJa(['a', 'b', 'c']),
'a、bおよびc',
'should join all elements of an array and create a string.'
);
t.strictEqual(
arrayToSentenceJa(['右', '左', '上', '下'], {
separator: 'と',
lastSeparator: '、そして'
}),
'右と左と上、そして下',
'should override separators via options.'
);
t.throws(
() => arrayToSentenceJa('foo', null),
/^TypeError.*foo is not an array\. Expected an array\./,
'should throw a type error when the first argument is not an array.'
);
t.throws(
() => arrayToSentenceJa([], {separator: false}),
/^TypeError.*false is not a string\. `separator` option must be a string\./,
'should throw a type error when `separator` option is not a string.'
);
t.throws(
() => arrayToSentenceJa([], {lastSeparator: true}),
/^TypeError.*true is not a string\. `lastSeparator` option must be a string\./,
'should throw a type error when `lastSeparator` option is not a string.'
);
t.end();
});
}
rollup({
entry: require('./package.json')['jsnext:main'],
plugins: rollupNodeResolve({jsnext: true})
}).then(bundle => {
runTest(require('.'), 'require(\'array-to-sentence-ja\')');
runTest(requireFromString(bundle.generate({format: 'cjs'}).code), 'Module exports');
});