Skip to content

Commit

Permalink
test: CLI - add success case
Browse files Browse the repository at this point in the history
  • Loading branch information
vio committed Aug 25, 2022
1 parent 7af3841 commit 2d9dfbf
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/cli.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
const http = require('http');
const { exec } = require('child_process');

const MOCK_RESULT = {
res: {
job: {
internalBuildNumber: 1,
},
},
info: {
message: {
txt: 'Hello world!',
},
},
};

const MOCK_SERVER_PORT = 5998;

describe('CLI', () => {
test('should return error if config is missing', (done) => {
exec('./bin/index.js', (error, stdout, sterr) => {
Expand All @@ -21,4 +37,25 @@ describe('CLI', () => {
done();
});
});

test('should run agent successfully', (done) => {
const server = http.createServer((req, res) => {
res.write(JSON.stringify(MOCK_RESULT));
res.end();
}).listen(MOCK_SERVER_PORT);

exec(
`cd test/cli/valid-data &&
RELATIVE_CI_ENDPOINT=http://localhost:${MOCK_SERVER_PORT}/save \
RELATIVE_CI_SLUG=org/project \
RELATIVE_CI_KEY=abc123 \
../../../bin/index.js
`,
(_, stdout, sterr) => {
expect(stdout).toContain('Job #1 done.');
server.close();
done();
},
);
});
});
5 changes: 5 additions & 0 deletions test/cli/valid-data/relativeci.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
webpack: {
stats: './webpack-stats.json',
},
};
30 changes: 30 additions & 0 deletions test/cli/valid-data/webpack-stats.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"assets": [
{
"name": "main.js",
"size": 28
}
],
"chunks": [
{
"id": 179,
"entry": true,
"initial": true,
"files": [
"main.js"
],
"names": [
"main"
]
}
],
"modules": [
{
"name": "./src/index.js",
"size": 29,
"chunks": [
179
]
}
]
}

0 comments on commit 2d9dfbf

Please sign in to comment.