forked from fregante/chrome-webstore-upload-cli
/
util.js
87 lines (72 loc) · 1.94 KB
/
util.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
import test from 'ava';
import util from '../util';
import stubs from './helpers/stubs';
const { stubProcessExit, stubConsoleLog } = stubs;
test('isUploadSuccess', t => {
t.true(util.isUploadSuccess({
uploadState: 'SUCCESS'
}));
});
test('exitWithUploadFailure', t => {
t.plan(3);
const errorCode = 1;
const errorDetail = 'This is detailed!';
const resetExit = stubProcessExit(code => t.is(code, 1));
const resetLog = stubConsoleLog(val => {
if (val === `Error Code: ${errorCode}`) {
t.pass('Error code');
}
if (val === `Details: ${errorDetail}`) {
t.pass('Error details');
}
});
util.exitWithUploadFailure({
itemError: [{
error_code: errorCode,
error_detail: errorDetail
}]
});
resetExit();
resetLog();
});
test('exitWithPublishStatus', t => {
t.plan(2);
const status = 'Success';
const resetExit = stubProcessExit(code => t.is(code, 0));
const resetLog = stubConsoleLog(val => {
if (val === `Publish Status: ${status}`) {
t.pass('Publish Status');
}
});
util.exitWithPublishStatus({
status: [status]
});
resetExit();
resetLog();
});
test('zipPath', t => {
const pathMappings = [{
root: 'extension',
file: 'extension/manifest.json',
expected: 'manifest.json'
}, {
root: 'extension/',
file: 'extension/foo/bar.js',
expected: 'foo/bar.js'
}, {
root: '.',
file: './manifest.json',
expected: 'manifest.json'
}, {
root: 'extension/foo',
file: 'extension/foo/manifest.json',
expected: 'manifest.json'
}, {
root: 'extension/foo',
file: 'extension/foo/bar/biz.js',
expected: 'bar/biz.js'
}];
pathMappings.forEach(({ root, file, expected }) =>{
t.is(util.zipPath(root, file), expected);
});
});