|
| 1 | +command = require '../lib/command' |
| 2 | +should = require 'should' |
| 3 | + |
| 4 | +describe 'CLI argument parsing', -> |
| 5 | + |
| 6 | + it 'should create server with configuration options', -> |
| 7 | + result = command.createServerFromArgs(['--port', '45001']) |
| 8 | + result.server.config.port.should.equal(45001) |
| 9 | + result.server.config.host.should.equal('localhost') |
| 10 | + result.server.config.debug.should.equal(false) |
| 11 | + result.server.config.usePolling.should.equal(false) |
| 12 | + result.server.config.delay.should.equal(0) |
| 13 | + result.server.config.originalPath.should.equal('') |
| 14 | + result.server.config.cors.should.equal(false) |
| 15 | + result.server.config.corp.should.equal(false) |
| 16 | + result.path.should.be.an.Array() |
| 17 | + |
| 18 | + it 'should parse port option correctly', -> |
| 19 | + result = command.createServerFromArgs(['--port', '8080']) |
| 20 | + result.server.config.port.should.equal(8080) |
| 21 | + |
| 22 | + it 'should parse short port option correctly', -> |
| 23 | + result = command.createServerFromArgs(['-p', '45003']) |
| 24 | + result.server.config.port.should.equal(45003) |
| 25 | + |
| 26 | + it 'should parse host option correctly', -> |
| 27 | + result = command.createServerFromArgs(['--bind', '0.0.0.0']) |
| 28 | + result.server.config.host.should.equal('0.0.0.0') |
| 29 | + |
| 30 | + it 'should parse short host option correctly', -> |
| 31 | + result = command.createServerFromArgs(['-b', '127.0.0.1']) |
| 32 | + result.server.config.host.should.equal('127.0.0.1') |
| 33 | + |
| 34 | + it 'should parse debug flag correctly', -> |
| 35 | + result = command.createServerFromArgs(['--debug']) |
| 36 | + result.server.config.debug.should.equal(true) |
| 37 | + |
| 38 | + it 'should parse short debug flag correctly', -> |
| 39 | + result = command.createServerFromArgs([ '-d']) |
| 40 | + result.server.config.debug.should.equal(true) |
| 41 | + |
| 42 | + it 'should parse exts option correctly', -> |
| 43 | + result = command.createServerFromArgs(['--exts', 'html,css,js']) |
| 44 | + result.server.config.exts.should.eql(['html', 'css', 'js']) |
| 45 | + |
| 46 | + it 'should parse short exts option correctly', -> |
| 47 | + result = command.createServerFromArgs(['-e', 'md,txt']) |
| 48 | + result.server.config.exts.should.eql(['md', 'txt']) |
| 49 | + |
| 50 | + it 'should parse extraExts option correctly', -> |
| 51 | + result = command.createServerFromArgs(['--extraExts', 'scss,less']) |
| 52 | + expectedExts = ['scss', 'less', 'html', 'css', 'js', 'png', 'gif', 'jpg', 'php', 'php5', 'py', 'rb', 'erb', 'coffee'] |
| 53 | + result.server.config.exts.should.eql(expectedExts) |
| 54 | + |
| 55 | + it 'should parse short extraExts option correctly', -> |
| 56 | + result = command.createServerFromArgs(['-ee', 'vue']) |
| 57 | + expectedExts = ['vue', 'html', 'css', 'js', 'png', 'gif', 'jpg', 'php', 'php5', 'py', 'rb', 'erb', 'coffee'] |
| 58 | + result.server.config.exts.should.eql(expectedExts) |
| 59 | + |
| 60 | + it 'should parse filesToReload option correctly', -> |
| 61 | + result = command.createServerFromArgs(['--filesToReload', 'index.html,app.js']) |
| 62 | + result.server.config.filesToReload.should.eql(['index.html', 'app.js']) |
| 63 | + |
| 64 | + it 'should parse short filesToReload option correctly', -> |
| 65 | + result = command.createServerFromArgs(['-f', 'config.json']) |
| 66 | + result.server.config.filesToReload.should.eql(['config.json']) |
| 67 | + |
| 68 | + it 'should parse usepolling flag correctly', -> |
| 69 | + result = command.createServerFromArgs(['--usepolling']) |
| 70 | + result.server.config.usePolling.should.equal(true) |
| 71 | + |
| 72 | + it 'should parse short usepolling flag correctly', -> |
| 73 | + result = command.createServerFromArgs(['-u']) |
| 74 | + result.server.config.usePolling.should.equal(true) |
| 75 | + |
| 76 | + it 'should parse wait option correctly', -> |
| 77 | + result = command.createServerFromArgs(['--wait', '1000']) |
| 78 | + result.server.config.delay.should.equal(1000) |
| 79 | + |
| 80 | + it 'should parse short wait option correctly', -> |
| 81 | + result = command.createServerFromArgs(['-w', '500']) |
| 82 | + result.server.config.delay.should.equal(500) |
| 83 | + |
| 84 | + it 'should parse originalpath option correctly', -> |
| 85 | + result = command.createServerFromArgs(['--originalpath', 'http://example.com']) |
| 86 | + result.server.config.originalPath.should.equal('http://example.com') |
| 87 | + |
| 88 | + it 'should parse short originalpath option correctly', -> |
| 89 | + result = command.createServerFromArgs(['-op', 'http://localhost:3000']) |
| 90 | + result.server.config.originalPath.should.equal('http://localhost:3000') |
| 91 | + |
| 92 | + it 'should parse corp flag correctly', -> |
| 93 | + result = command.createServerFromArgs(['--corp']) |
| 94 | + result.server.config.corp.should.equal(true) |
| 95 | + |
| 96 | + it 'should parse short corp flag correctly', -> |
| 97 | + result = command.createServerFromArgs(['-cp']) |
| 98 | + result.server.config.corp.should.equal(true) |
| 99 | + |
| 100 | + it 'should parse cors option correctly', -> |
| 101 | + result = command.createServerFromArgs(['--cors', 'http://localhost:8080']) |
| 102 | + result.server.config.cors.should.equal('http://localhost:8080') |
| 103 | + |
| 104 | + it 'should parse short cors option correctly', -> |
| 105 | + result = command.createServerFromArgs(['-cs', '*']) |
| 106 | + result.server.config.cors.should.equal('*') |
| 107 | + |
| 108 | + |
| 109 | + it 'should parse exclusions option correctly', -> |
| 110 | + result = command.createServerFromArgs(['--port', '45025', '--exclusions', '\\.tmp,\\.log']) |
| 111 | + result.server.config.exclusions.should.have.length(5) # 2 user + 3 defaults |
| 112 | + result.server.config.exclusions[0].should.be.an.instanceOf(RegExp) |
| 113 | + result.server.config.exclusions[1].should.be.an.instanceOf(RegExp) |
| 114 | + |
| 115 | + it 'should parse short exclusions option correctly', -> |
| 116 | + result = command.createServerFromArgs(['--port', '45026', '-x', 'node_modules']) |
| 117 | + result.server.config.exclusions.should.have.length(4) # 1 user + 3 defaults |
| 118 | + result.server.config.exclusions[0].should.be.an.instanceOf(RegExp) |
| 119 | + |
| 120 | + it 'should handle multiple options correctly', -> |
| 121 | + result = command.createServerFromArgs(['-p', '8080', '-d', '--cors', '*', '--exts', 'html,js']) |
| 122 | + result.server.config.port.should.equal(8080) |
| 123 | + result.server.config.debug.should.equal(true) |
| 124 | + result.server.config.cors.should.equal('*') |
| 125 | + result.server.config.exts.should.eql(['html', 'js']) |
| 126 | + |
| 127 | + it 'should handle path argument correctly', -> |
| 128 | + result = command.createServerFromArgs(['./src']) |
| 129 | + result.path.should.be.an.Array() |
| 130 | + result.path[0].should.match(/\/src$/) |
| 131 | + |
| 132 | + it 'should handle multiple comma-separated paths correctly', -> |
| 133 | + result = command.createServerFromArgs(['./src,./public']) |
| 134 | + result.path.should.have.length(2) |
| 135 | + result.path[0].should.match(/\/src$/) |
| 136 | + result.path[1].should.match(/\/public$/) |
| 137 | + |
| 138 | + it 'should use default port when no port specified', -> |
| 139 | + result = command.createServerFromArgs([]) |
| 140 | + result.server.config.port.should.equal(35729) |
0 commit comments