Skip to content

Commit 9cfa5ab

Browse files
authored
Separate unit tests and integration (e2e) tests (#1207)
1 parent 4880a40 commit 9cfa5ab

19 files changed

+372
-353
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ terraform.*
99
!terraform.test.js
1010
crash.log
1111
/build
12+
/coverage

bin/cml/asset/publish.e2e.test.js

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
const fs = require('fs');
2+
const { exec } = require('../../../src/utils');
3+
4+
describe('CML e2e', () => {
5+
test('cml publish assets/logo.png --md', async () => {
6+
const output = await exec(`node ./bin/cml.js publish assets/logo.png --md`);
7+
8+
expect(output.startsWith('![](')).toBe(true);
9+
});
10+
11+
test('cml publish assets/logo.png', async () => {
12+
const output = await exec(`node ./bin/cml.js publish assets/logo.png`);
13+
14+
expect(output.startsWith('https://')).toBe(true);
15+
});
16+
17+
test('cml publish assets/logo.pdf --md', async () => {
18+
const title = 'this is awesome';
19+
const output = await exec(
20+
`node ./bin/cml.js publish assets/logo.pdf --md --title '${title}'`
21+
);
22+
23+
expect(output.startsWith(`[${title}](`)).toBe(true);
24+
});
25+
26+
test('cml publish assets/logo.pdf', async () => {
27+
const output = await exec(`node ./bin/cml.js publish assets/logo.pdf`);
28+
29+
expect(output.startsWith('https://')).toBe(true);
30+
});
31+
32+
test('cml publish assets/test.svg --md', async () => {
33+
const title = 'this is awesome';
34+
const output = await exec(
35+
`node ./bin/cml.js publish assets/test.svg --md --title '${title}'`
36+
);
37+
38+
expect(output.startsWith('![](') && output.endsWith(`${title}")`)).toBe(
39+
true
40+
);
41+
});
42+
43+
test('cml publish assets/test.svg', async () => {
44+
const output = await exec(`node ./bin/cml.js publish assets/test.svg`);
45+
46+
expect(output.startsWith('https://')).toBe(true);
47+
});
48+
49+
test('cml publish assets/logo.pdf to file', async () => {
50+
const file = `cml-publish-test.md`;
51+
52+
await exec(`node ./bin/cml.js publish assets/logo.pdf --file ${file}`);
53+
54+
expect(fs.existsSync(file)).toBe(true);
55+
await fs.promises.unlink(file);
56+
});
57+
58+
test('cml publish assets/vega-lite.json', async () => {
59+
const output = await exec(
60+
`node ./bin/cml.js publish --mime-type=application/json assets/vega-lite.json`
61+
);
62+
63+
expect(output.startsWith('https://')).toBe(true);
64+
expect(output.includes('cml=json')).toBe(true);
65+
});
66+
67+
test('cml publish assets/test.svg in Gitlab storage', async () => {
68+
const { TEST_GITLAB_REPO: repo, TEST_GITLAB_TOKEN: token } = process.env;
69+
70+
const output = await exec(
71+
`node ./bin/cml.js publish --repo=${repo} --token=${token} --gitlab-uploads assets/test.svg`
72+
);
73+
74+
expect(output.startsWith('https://')).toBe(true);
75+
});
76+
77+
test('cml publish /nonexistent produces file error', async () => {
78+
await expect(
79+
exec('node ./bin/cml.js publish /nonexistent')
80+
).rejects.toThrowError('ENOENT');
81+
});
82+
});

bin/cml/asset/publish.test.js

+1-80
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
const fs = require('fs');
21
const { exec } = require('../../../src/utils');
32

4-
describe('CML e2e', () => {
3+
describe('CML cli test', () => {
54
test('cml publish --help', async () => {
65
const output = await exec(`node ./bin/cml.js publish --help`);
76

@@ -29,82 +28,4 @@ describe('CML e2e', () => {
2928
--mime-type MIME type [string] [default: infer from the file contents]"
3029
`);
3130
});
32-
33-
test('cml publish assets/logo.png --md', async () => {
34-
const output = await exec(`node ./bin/cml.js publish assets/logo.png --md`);
35-
36-
expect(output.startsWith('![](')).toBe(true);
37-
});
38-
39-
test('cml publish assets/logo.png', async () => {
40-
const output = await exec(`node ./bin/cml.js publish assets/logo.png`);
41-
42-
expect(output.startsWith('https://')).toBe(true);
43-
});
44-
45-
test('cml publish assets/logo.pdf --md', async () => {
46-
const title = 'this is awesome';
47-
const output = await exec(
48-
`node ./bin/cml.js publish assets/logo.pdf --md --title '${title}'`
49-
);
50-
51-
expect(output.startsWith(`[${title}](`)).toBe(true);
52-
});
53-
54-
test('cml publish assets/logo.pdf', async () => {
55-
const output = await exec(`node ./bin/cml.js publish assets/logo.pdf`);
56-
57-
expect(output.startsWith('https://')).toBe(true);
58-
});
59-
60-
test('cml publish assets/test.svg --md', async () => {
61-
const title = 'this is awesome';
62-
const output = await exec(
63-
`node ./bin/cml.js publish assets/test.svg --md --title '${title}'`
64-
);
65-
66-
expect(output.startsWith('![](') && output.endsWith(`${title}")`)).toBe(
67-
true
68-
);
69-
});
70-
71-
test('cml publish assets/test.svg', async () => {
72-
const output = await exec(`node ./bin/cml.js publish assets/test.svg`);
73-
74-
expect(output.startsWith('https://')).toBe(true);
75-
});
76-
77-
test('cml publish assets/logo.pdf to file', async () => {
78-
const file = `cml-publish-test.md`;
79-
80-
await exec(`node ./bin/cml.js publish assets/logo.pdf --file ${file}`);
81-
82-
expect(fs.existsSync(file)).toBe(true);
83-
await fs.promises.unlink(file);
84-
});
85-
86-
test('cml publish assets/vega-lite.json', async () => {
87-
const output = await exec(
88-
`node ./bin/cml.js publish --mime-type=application/json assets/vega-lite.json`
89-
);
90-
91-
expect(output.startsWith('https://')).toBe(true);
92-
expect(output.includes('cml=json')).toBe(true);
93-
});
94-
95-
test('cml publish assets/test.svg in Gitlab storage', async () => {
96-
const { TEST_GITLAB_REPO: repo, TEST_GITLAB_TOKEN: token } = process.env;
97-
98-
const output = await exec(
99-
`node ./bin/cml.js publish --repo=${repo} --token=${token} --gitlab-uploads assets/test.svg`
100-
);
101-
102-
expect(output.startsWith('https://')).toBe(true);
103-
});
104-
105-
test('cml publish /nonexistent produces file error', async () => {
106-
await expect(
107-
exec('node ./bin/cml.js publish /nonexistent')
108-
).rejects.toThrowError('ENOENT');
109-
});
11031
});

bin/cml/check/create.e2e.test.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const { exec } = require('../../../src/utils');
2+
const fs = require('fs').promises;
3+
4+
describe('CML e2e', () => {
5+
const path = 'check.md';
6+
7+
afterEach(async () => {
8+
try {
9+
await fs.unlink(path);
10+
} catch (err) {}
11+
});
12+
13+
test('cml send-github-check', async () => {
14+
const report = `## Test Check Report`;
15+
16+
await fs.writeFile(path, report);
17+
process.env.GITHUB_ACTIONS &&
18+
(await exec(`node ./bin/cml.js send-github-check ${path}`));
19+
});
20+
21+
test('cml send-github-check failure with tile "CML neutral test"', async () => {
22+
const report = `## Hi this check should be neutral`;
23+
const title = 'CML neutral test';
24+
const conclusion = 'neutral';
25+
26+
await fs.writeFile(path, report);
27+
process.env.GITHUB_ACTIONS &&
28+
(await exec(
29+
`node ./bin/cml.js send-github-check ${path} --title "${title}" --conclusion "${conclusion}"`
30+
));
31+
});
32+
});

bin/cml/check/create.test.js

-29
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,6 @@
11
const { exec } = require('../../../src/utils');
2-
const fs = require('fs').promises;
32

43
describe('CML e2e', () => {
5-
const path = 'check.md';
6-
7-
afterEach(async () => {
8-
try {
9-
await fs.unlink(path);
10-
} catch (err) {}
11-
});
12-
13-
test('cml send-github-check', async () => {
14-
const report = `## Test Check Report`;
15-
16-
await fs.writeFile(path, report);
17-
process.env.GITHUB_ACTIONS &&
18-
(await exec(`node ./bin/cml.js send-github-check ${path}`));
19-
});
20-
21-
test('cml send-github-check failure with tile "CML neutral test"', async () => {
22-
const report = `## Hi this check should be neutral`;
23-
const title = 'CML neutral test';
24-
const conclusion = 'neutral';
25-
26-
await fs.writeFile(path, report);
27-
process.env.GITHUB_ACTIONS &&
28-
(await exec(
29-
`node ./bin/cml.js send-github-check ${path} --title "${title}" --conclusion "${conclusion}"`
30-
));
31-
});
32-
334
test('cml send-github-check --help', async () => {
345
const output = await exec(`node ./bin/cml.js send-github-check --help`);
356

bin/cml/comment/create.e2e.test.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const { exec } = require('../../../src/utils');
2+
const fs = require('fs').promises;
3+
4+
describe('Comment integration tests', () => {
5+
const path = 'comment.md';
6+
7+
afterEach(async () => {
8+
try {
9+
await fs.unlink(path);
10+
} catch (err) {}
11+
});
12+
13+
test('cml send-comment to specific repo', async () => {
14+
const {
15+
TEST_GITHUB_REPO: repo,
16+
TEST_GITHUB_TOKEN: token,
17+
TEST_GITHUB_SHA: sha
18+
} = process.env;
19+
20+
const report = `## Test Comment Report specific`;
21+
22+
await fs.writeFile(path, report);
23+
await exec(
24+
`node ./bin/cml.js send-comment --repo=${repo} --token=${token} --commit-sha=${sha} ${path}`
25+
);
26+
});
27+
28+
test('cml send-comment to current repo', async () => {
29+
const report = `## Test Comment`;
30+
31+
await fs.writeFile(path, report);
32+
await exec(`node ./bin/cml.js send-comment ${path}`);
33+
});
34+
35+
test('cml send-comment --publish to current repo', async () => {
36+
const report = `## Test Comment\n![](assets/logo.png)`;
37+
38+
await fs.writeFile(path, report);
39+
await exec(`node ./bin/cml.js send-comment --publish ${path}`);
40+
});
41+
});

bin/cml/comment/create.test.js

-38
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
const { exec } = require('../../../src/utils');
2-
const fs = require('fs').promises;
32

43
describe('Comment integration tests', () => {
5-
const path = 'comment.md';
6-
7-
afterEach(async () => {
8-
try {
9-
await fs.unlink(path);
10-
} catch (err) {}
11-
});
12-
134
test('cml send-comment --help', async () => {
145
const output = await exec(`node ./bin/cml.js send-comment --help`);
156

@@ -44,33 +35,4 @@ describe('Comment integration tests', () => {
4435
distinguish CML comments from others [boolean]"
4536
`);
4637
});
47-
48-
test('cml send-comment to specific repo', async () => {
49-
const {
50-
TEST_GITHUB_REPO: repo,
51-
TEST_GITHUB_TOKEN: token,
52-
TEST_GITHUB_SHA: sha
53-
} = process.env;
54-
55-
const report = `## Test Comment Report specific`;
56-
57-
await fs.writeFile(path, report);
58-
await exec(
59-
`node ./bin/cml.js send-comment --repo=${repo} --token=${token} --commit-sha=${sha} ${path}`
60-
);
61-
});
62-
63-
test('cml send-comment to current repo', async () => {
64-
const report = `## Test Comment`;
65-
66-
await fs.writeFile(path, report);
67-
await exec(`node ./bin/cml.js send-comment ${path}`);
68-
});
69-
70-
test('cml send-comment --publish to current repo', async () => {
71-
const report = `## Test Comment\n![](assets/logo.png)`;
72-
73-
await fs.writeFile(path, report);
74-
await exec(`node ./bin/cml.js send-comment --publish ${path}`);
75-
});
7638
});
File renamed without changes.

0 commit comments

Comments
 (0)