-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest.js
117 lines (82 loc) · 3.8 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import test from 'ava';
import {cordova} from 'cordova-lib';
import sinon from 'sinon';
import gutil from 'gulp-util';
import fn from '.';
function plugin(plugin, opts) {
return new Promise((resolve, reject) => {
const stream = fn(plugin, opts);
stream.on('data', () => { });
stream.on('error', reject);
stream.on('end', resolve);
stream.write(new gutil.File());
stream.end();
});
}
test.beforeEach(() => {
cordova.plugin = sinon.stub().returns(Promise.resolve());
});
test.serial('add plugin', async t => {
await plugin('foo');
t.deepEqual(cordova.plugin.lastCall.args, ['add', 'foo', {}]);
});
test.serial('remove trailing / from git-based plugin', async t => {
await plugin('https://github.com/SamVerschueren/cordova-ua-bb10///');
t.deepEqual(cordova.plugin.lastCall.args, ['add', 'https://github.com/SamVerschueren/cordova-ua-bb10', {}]);
});
test.serial('add specific version', async t => {
await plugin('foo', '1.0.0');
t.deepEqual(cordova.plugin.lastCall.args, ['add', 'foo@1.0.0', {}]);
});
test.serial('add version to git-based plugin', async t => {
await plugin('https://github.com/SamVerschueren/cordova-ua-bb10', '1.0.0');
t.deepEqual(cordova.plugin.lastCall.args, ['add', 'https://github.com/SamVerschueren/cordova-ua-bb10#v1.0.0', {}]);
});
test.serial('add specific version object', async t => {
await plugin('foo', {version: '1.0.0'});
t.deepEqual(cordova.plugin.lastCall.args, ['add', 'foo@1.0.0', {}]);
});
test.serial('add object version to git-based plugin', async t => {
await plugin('https://github.com/SamVerschueren/cordova-ua-bb10', {version: '1.0.0'});
t.deepEqual(cordova.plugin.lastCall.args, ['add', 'https://github.com/SamVerschueren/cordova-ua-bb10#v1.0.0', {}]);
});
test.serial('add `latest` version to git-based plugin', async t => {
await plugin('https://github.com/SamVerschueren/cordova-ua-bb10', {version: 'latest'});
t.deepEqual(cordova.plugin.lastCall.args, ['add', 'https://github.com/SamVerschueren/cordova-ua-bb10', {}]);
});
test.serial('add plugin with variables', async t => {
await plugin('foo', {variables: {bar: 'bar', baz: 'baz'}});
t.deepEqual(cordova.plugin.lastCall.args, ['add', 'foo', {cli_variables: {bar: 'bar', baz: 'baz'}}]); // eslint-disable-line camelcase
});
test.serial('add plugin with version and variables', async t => {
await plugin('foo', {version: 'latest', variables: {bar: 'bar', baz: 'baz'}});
t.deepEqual(cordova.plugin.lastCall.args, ['add', 'foo@latest', {cli_variables: {bar: 'bar', baz: 'baz'}}]); // eslint-disable-line camelcase
});
test.serial('add two plugins when array is provided', async t => {
await plugin(['foo', 'bar']);
t.deepEqual(cordova.plugin.args[0], ['add', 'foo', {}]);
t.deepEqual(cordova.plugin.args[1], ['add', 'bar', {}]);
});
test.serial('emit options object when array is provided', async t => {
await plugin(['foo', 'bar'], {version: '1.0.0', variables: {baz: 'baz'}});
t.deepEqual(cordova.plugin.args[0], ['add', 'foo', {}]);
t.deepEqual(cordova.plugin.args[1], ['add', 'bar', {}]);
});
test.serial('add two plugins when object is provided', async t => {
await plugin({foo: 'latest', bar: '1.0.0'});
t.deepEqual(cordova.plugin.args[0], ['add', 'foo@latest', {}]);
t.deepEqual(cordova.plugin.args[1], ['add', 'bar@1.0.0', {}]);
});
test.serial('options object in plugin object', async t => {
await plugin({foo: 'latest', bar: {version: '1.0.0', variables: {baz: 'baz'}}});
t.deepEqual(cordova.plugin.args[0], ['add', 'foo@latest', {}]);
t.deepEqual(cordova.plugin.args[1], ['add', 'bar@1.0.0', {cli_variables: {baz: 'baz'}}]); // eslint-disable-line camelcase
});
test.serial('throw error', async t => {
cordova.plugin = function () {
return new Promise((resolve, reject) => {
reject(new Error('something went wrong'));
});
};
await t.throws(plugin('foo'), 'something went wrong');
});