Skip to content

Commit

Permalink
Separate unit tests and integration (e2e) tests (#1207)
Browse files Browse the repository at this point in the history
  • Loading branch information
tasdomas authored Oct 6, 2022
1 parent 4880a40 commit 9cfa5ab
Show file tree
Hide file tree
Showing 19 changed files with 372 additions and 353 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ terraform.*
!terraform.test.js
crash.log
/build
/coverage
82 changes: 82 additions & 0 deletions bin/cml/asset/publish.e2e.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
const fs = require('fs');
const { exec } = require('../../../src/utils');

describe('CML e2e', () => {
test('cml publish assets/logo.png --md', async () => {
const output = await exec(`node ./bin/cml.js publish assets/logo.png --md`);

expect(output.startsWith('![](')).toBe(true);
});

test('cml publish assets/logo.png', async () => {
const output = await exec(`node ./bin/cml.js publish 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(
`node ./bin/cml.js publish assets/logo.pdf --md --title '${title}'`
);

expect(output.startsWith(`[${title}](`)).toBe(true);
});

test('cml publish assets/logo.pdf', async () => {
const output = await exec(`node ./bin/cml.js publish 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(
`node ./bin/cml.js publish 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(`node ./bin/cml.js publish 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(`node ./bin/cml.js publish assets/logo.pdf --file ${file}`);

expect(fs.existsSync(file)).toBe(true);
await fs.promises.unlink(file);
});

test('cml publish assets/vega-lite.json', async () => {
const output = await exec(
`node ./bin/cml.js publish --mime-type=application/json assets/vega-lite.json`
);

expect(output.startsWith('https://')).toBe(true);
expect(output.includes('cml=json')).toBe(true);
});

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(
`node ./bin/cml.js publish --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('node ./bin/cml.js publish /nonexistent')
).rejects.toThrowError('ENOENT');
});
});
81 changes: 1 addition & 80 deletions bin/cml/asset/publish.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const fs = require('fs');
const { exec } = require('../../../src/utils');

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

Expand Down Expand Up @@ -29,82 +28,4 @@ describe('CML e2e', () => {
--mime-type MIME type [string] [default: infer from the file contents]"
`);
});

test('cml publish assets/logo.png --md', async () => {
const output = await exec(`node ./bin/cml.js publish assets/logo.png --md`);

expect(output.startsWith('![](')).toBe(true);
});

test('cml publish assets/logo.png', async () => {
const output = await exec(`node ./bin/cml.js publish 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(
`node ./bin/cml.js publish assets/logo.pdf --md --title '${title}'`
);

expect(output.startsWith(`[${title}](`)).toBe(true);
});

test('cml publish assets/logo.pdf', async () => {
const output = await exec(`node ./bin/cml.js publish 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(
`node ./bin/cml.js publish 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(`node ./bin/cml.js publish 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(`node ./bin/cml.js publish assets/logo.pdf --file ${file}`);

expect(fs.existsSync(file)).toBe(true);
await fs.promises.unlink(file);
});

test('cml publish assets/vega-lite.json', async () => {
const output = await exec(
`node ./bin/cml.js publish --mime-type=application/json assets/vega-lite.json`
);

expect(output.startsWith('https://')).toBe(true);
expect(output.includes('cml=json')).toBe(true);
});

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(
`node ./bin/cml.js publish --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('node ./bin/cml.js publish /nonexistent')
).rejects.toThrowError('ENOENT');
});
});
32 changes: 32 additions & 0 deletions bin/cml/check/create.e2e.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const { exec } = require('../../../src/utils');
const fs = require('fs').promises;

describe('CML e2e', () => {
const path = 'check.md';

afterEach(async () => {
try {
await fs.unlink(path);
} catch (err) {}
});

test('cml send-github-check', async () => {
const report = `## Test Check Report`;

await fs.writeFile(path, report);
process.env.GITHUB_ACTIONS &&
(await exec(`node ./bin/cml.js send-github-check ${path}`));
});

test('cml send-github-check failure with tile "CML neutral test"', async () => {
const report = `## Hi this check should be neutral`;
const title = 'CML neutral test';
const conclusion = 'neutral';

await fs.writeFile(path, report);
process.env.GITHUB_ACTIONS &&
(await exec(
`node ./bin/cml.js send-github-check ${path} --title "${title}" --conclusion "${conclusion}"`
));
});
});
29 changes: 0 additions & 29 deletions bin/cml/check/create.test.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,6 @@
const { exec } = require('../../../src/utils');
const fs = require('fs').promises;

describe('CML e2e', () => {
const path = 'check.md';

afterEach(async () => {
try {
await fs.unlink(path);
} catch (err) {}
});

test('cml send-github-check', async () => {
const report = `## Test Check Report`;

await fs.writeFile(path, report);
process.env.GITHUB_ACTIONS &&
(await exec(`node ./bin/cml.js send-github-check ${path}`));
});

test('cml send-github-check failure with tile "CML neutral test"', async () => {
const report = `## Hi this check should be neutral`;
const title = 'CML neutral test';
const conclusion = 'neutral';

await fs.writeFile(path, report);
process.env.GITHUB_ACTIONS &&
(await exec(
`node ./bin/cml.js send-github-check ${path} --title "${title}" --conclusion "${conclusion}"`
));
});

test('cml send-github-check --help', async () => {
const output = await exec(`node ./bin/cml.js send-github-check --help`);

Expand Down
41 changes: 41 additions & 0 deletions bin/cml/comment/create.e2e.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const { exec } = require('../../../src/utils');
const fs = require('fs').promises;

describe('Comment integration tests', () => {
const path = 'comment.md';

afterEach(async () => {
try {
await fs.unlink(path);
} catch (err) {}
});

test('cml send-comment to specific repo', async () => {
const {
TEST_GITHUB_REPO: repo,
TEST_GITHUB_TOKEN: token,
TEST_GITHUB_SHA: sha
} = process.env;

const report = `## Test Comment Report specific`;

await fs.writeFile(path, report);
await exec(
`node ./bin/cml.js send-comment --repo=${repo} --token=${token} --commit-sha=${sha} ${path}`
);
});

test('cml send-comment to current repo', async () => {
const report = `## Test Comment`;

await fs.writeFile(path, report);
await exec(`node ./bin/cml.js send-comment ${path}`);
});

test('cml send-comment --publish to current repo', async () => {
const report = `## Test Comment\n![](assets/logo.png)`;

await fs.writeFile(path, report);
await exec(`node ./bin/cml.js send-comment --publish ${path}`);
});
});
38 changes: 0 additions & 38 deletions bin/cml/comment/create.test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
const { exec } = require('../../../src/utils');
const fs = require('fs').promises;

describe('Comment integration tests', () => {
const path = 'comment.md';

afterEach(async () => {
try {
await fs.unlink(path);
} catch (err) {}
});

test('cml send-comment --help', async () => {
const output = await exec(`node ./bin/cml.js send-comment --help`);

Expand Down Expand Up @@ -44,33 +35,4 @@ describe('Comment integration tests', () => {
distinguish CML comments from others [boolean]"
`);
});

test('cml send-comment to specific repo', async () => {
const {
TEST_GITHUB_REPO: repo,
TEST_GITHUB_TOKEN: token,
TEST_GITHUB_SHA: sha
} = process.env;

const report = `## Test Comment Report specific`;

await fs.writeFile(path, report);
await exec(
`node ./bin/cml.js send-comment --repo=${repo} --token=${token} --commit-sha=${sha} ${path}`
);
});

test('cml send-comment to current repo', async () => {
const report = `## Test Comment`;

await fs.writeFile(path, report);
await exec(`node ./bin/cml.js send-comment ${path}`);
});

test('cml send-comment --publish to current repo', async () => {
const report = `## Test Comment\n![](assets/logo.png)`;

await fs.writeFile(path, report);
await exec(`node ./bin/cml.js send-comment --publish ${path}`);
});
});
File renamed without changes.
Loading

0 comments on commit 9cfa5ab

Please sign in to comment.