| 
									
										
										
										
											2019-05-23 22:08:37 +01:00
										 |  |  | const Tom = require('test-runner').Tom | 
					
						
							| 
									
										
										
										
											2017-07-07 23:52:48 +01:00
										 |  |  | const a = require('assert') | 
					
						
							| 
									
										
										
										
											2019-05-27 11:25:06 +01:00
										 |  |  | const WsCli = require('../lib/cli-app') | 
					
						
							| 
									
										
										
										
											2019-05-23 22:08:37 +01:00
										 |  |  | const fetch = require('node-fetch') | 
					
						
							| 
									
										
										
										
											2017-07-07 23:52:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-17 11:25:46 +01:00
										 |  |  | const tom = module.exports = new Tom('cli', { concurrency: 1 }) | 
					
						
							| 
									
										
										
										
											2017-07-07 23:52:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-17 11:25:46 +01:00
										 |  |  | tom.test('simple', async function () { | 
					
						
							| 
									
										
										
										
											2017-07-07 23:52:48 +01:00
										 |  |  |   const port = 7500 + this.index | 
					
						
							| 
									
										
										
										
											2019-05-27 11:25:06 +01:00
										 |  |  |   const cli = new WsCli({ logError: function () {} }) | 
					
						
							| 
									
										
										
										
											2019-06-17 11:25:46 +01:00
										 |  |  |   const server = cli.start([ '--port', `${port}` ]) | 
					
						
							| 
									
										
										
										
											2019-06-02 23:15:15 +01:00
										 |  |  |   const response = await fetch(`http://127.0.0.1:${port}/package.json`) | 
					
						
							| 
									
										
										
										
											2017-07-07 23:52:48 +01:00
										 |  |  |   server.close() | 
					
						
							| 
									
										
										
										
											2019-05-23 22:08:37 +01:00
										 |  |  |   a.strictEqual(response.status, 200) | 
					
						
							| 
									
										
										
										
											2017-07-07 23:52:48 +01:00
										 |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-17 11:25:46 +01:00
										 |  |  | tom.test('bad option', async function () { | 
					
						
							| 
									
										
										
										
											2018-01-17 22:42:46 +00:00
										 |  |  |   const exitCode = process.exitCode | 
					
						
							| 
									
										
										
										
											2019-05-27 11:25:06 +01:00
										 |  |  |   const cli = new WsCli({ logError: function () {} }) | 
					
						
							| 
									
										
										
										
											2019-06-17 11:25:46 +01:00
										 |  |  |   const server = cli.start([ '--should-fail' ]) | 
					
						
							| 
									
										
										
										
											2018-01-17 22:42:46 +00:00
										 |  |  |   if (!exitCode) process.exitCode = 0 | 
					
						
							| 
									
										
										
										
											2017-07-07 23:52:48 +01:00
										 |  |  |   a.strictEqual(server, undefined) | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-17 11:25:46 +01:00
										 |  |  | tom.test('--help', async function () { | 
					
						
							| 
									
										
										
										
											2019-05-27 11:25:06 +01:00
										 |  |  |   const cli = new WsCli({ log: function () {} }) | 
					
						
							| 
									
										
										
										
											2019-06-17 11:25:46 +01:00
										 |  |  |   cli.start([ '--help' ]) | 
					
						
							| 
									
										
										
										
											2017-07-07 23:52:48 +01:00
										 |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-17 11:25:46 +01:00
										 |  |  | tom.test('--version', async function () { | 
					
						
							| 
									
										
										
										
											2019-05-27 11:25:06 +01:00
										 |  |  |   let logMsg = '' | 
					
						
							|  |  |  |   const cli = new WsCli({ log: function (msg) { logMsg = msg } }) | 
					
						
							| 
									
										
										
										
											2019-06-17 11:25:46 +01:00
										 |  |  |   cli.start([ '--version' ]) | 
					
						
							| 
									
										
										
										
											2019-05-27 11:25:06 +01:00
										 |  |  |   const pkg = require('../package.json') | 
					
						
							|  |  |  |   a.strictEqual(logMsg.trim(), pkg.version) | 
					
						
							| 
									
										
										
										
											2017-07-07 23:52:48 +01:00
										 |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-17 11:25:46 +01:00
										 |  |  | tom.test('default-stack', async function () { | 
					
						
							| 
									
										
										
										
											2019-05-27 11:25:06 +01:00
										 |  |  |   let logMsg = '' | 
					
						
							|  |  |  |   const cli = new WsCli({ log: function (msg) { logMsg = msg } }) | 
					
						
							| 
									
										
										
										
											2019-06-17 11:25:46 +01:00
										 |  |  |   cli.start([ '--default-stack' ]) | 
					
						
							| 
									
										
										
										
											2019-06-02 23:15:15 +01:00
										 |  |  |   a.ok(/lws-static/.test(logMsg)) | 
					
						
							| 
									
										
										
										
											2017-07-07 23:52:48 +01:00
										 |  |  | }) |