forked from iterative/cml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cml-publish.test.js
120 lines (96 loc) · 4.32 KB
/
cml-publish.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
118
119
120
jest.setTimeout(200000);
const fs = require('fs');
const { exec } = require('../src/utils');
describe('CML e2e', () => {
test('cml-publish -h', async () => {
const output = await exec(`echo none | node ./bin/cml-publish.js -h`);
expect(output).toMatchInlineSnapshot(`
"Usage: cml-publish.js <path to file>
Options:
--version Show version number [boolean]
--md Output in markdown format [title || name](url). [boolean]
--title, -t Markdown title [title](url) or ![](url title).
--gitlab-uploads Uses GitLab uploads instead of CML storage. Use GitLab
uploads to get around CML size limitations for hosting
artifacts persistently. Only available for GitLab CI.
[deprecated: Use --native instead] [boolean]
--native Uses driver's native capabilities to upload assets instead
of CML's storage. [boolean]
--rm-watermark Avoid CML watermark. [boolean]
--file, -f Append the output to the given file. Create it if does not
exist.
--repo Specifies the repo to be used. If not specified is extracted
from the CI ENV.
--token Personal access token to be used. If not specified in
extracted from ENV repo_token or GITLAB_TOKEN.
--driver If not specify it infers it from the ENV.
[choices: \\"github\\", \\"gitlab\\"]
-h Show help [boolean]"
`);
});
test('cml-publish assets/logo.png --md', async () => {
const output = await exec(
`echo none | node ./bin/cml-publish.js assets/logo.png --md`
);
expect(output.startsWith('![](')).toBe(true);
});
test('cml-publish assets/logo.png', async () => {
const output = await exec(
`echo none | node ./bin/cml-publish.js assets/logo.png`
);
expect(output.startsWith('https://')).toBe(true);
});
test('cml-publish assets/logo.pdf --md', async () => {
const title = 'this is awesome';
const output = await exec(
`echo none | node ./bin/cml-publish.js assets/logo.pdf --md --title '${title}'`
);
expect(output.startsWith(`[${title}](`)).toBe(true);
});
test('cml-publish assets/logo.pdf', async () => {
const output = await exec(
`echo none | node ./bin/cml-publish.js assets/logo.pdf`
);
expect(output.startsWith('https://')).toBe(true);
});
test('cml-publish assets/test.svg --md', async () => {
const title = 'this is awesome';
const output = await exec(
`echo none | node ./bin/cml-publish.js assets/test.svg --md --title '${title}'`
);
expect(output.startsWith('![](') && output.endsWith(`${title}")`)).toBe(
true
);
});
test('cml-publish assets/test.svg', async () => {
const output = await exec(
`echo none | node ./bin/cml-publish.js assets/test.svg`
);
expect(output.startsWith('https://')).toBe(true);
});
test('cml-publish assets/logo.pdf to file', async () => {
const file = `cml-publish-test.md`;
await exec(
`echo none | node ./bin/cml-publish.js assets/logo.pdf --file ${file}`
);
expect(fs.existsSync(file)).toBe(true);
await fs.promises.unlink(file);
});
test('cml-publish assets/test.svg in Gitlab storage', async () => {
const { TEST_GITLAB_REPO: repo, TEST_GITLAB_TOKEN: token } = process.env;
const output = await exec(
`echo none | node ./bin/cml-publish.js --repo=${repo} --token=${token} --gitlab-uploads assets/test.svg`
);
expect(output.startsWith('https://')).toBe(true);
});
test('cml-publish /nonexistent produces file error', async () => {
await expect(
exec('echo none | node ./bin/cml-publish.js /nonexistent')
).rejects.toThrowError('ENOENT: no such file or directory, stat');
});
test('echo invalid | cml-publish produces buffer mime type error', async () => {
await expect(
exec(`echo invalid | node ./bin/cml-publish.js`)
).rejects.toThrowError('Failed guessing mime type of buffer');
});
});