diff --git a/test/cli.test.js b/test/cli.test.js index f7ef09ec..4f9cf3d1 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -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) => { @@ -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(); + }, + ); + }); }); diff --git a/test/cli/valid-data/relativeci.config.js b/test/cli/valid-data/relativeci.config.js new file mode 100644 index 00000000..bbbb7f17 --- /dev/null +++ b/test/cli/valid-data/relativeci.config.js @@ -0,0 +1,5 @@ +module.exports = { + webpack: { + stats: './webpack-stats.json', + }, +}; diff --git a/test/cli/valid-data/webpack-stats.json b/test/cli/valid-data/webpack-stats.json new file mode 100644 index 00000000..c90fb19d --- /dev/null +++ b/test/cli/valid-data/webpack-stats.json @@ -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 + ] + } + ] +}