Skip to content

Commit 4a63a34

Browse files
authored
Version 1.0.0-pre.1 (#2)
* WIP commit. Totes doesnt work because I have a variable being returned before it is assigned in the start function. * Now koa-karma-proxy promises the servers and their ports. * Updated the CLI. Next job is to add argument flags/options. * WIP commit trying to get karma tests to actually run with the koa-karma-proxy-cli... something isn't picking up. * Upgraded koa-proxy to the one that doesn't include a .git/index file. * WIP got the CLI working as desired with a --proxyFile argument too. * Make the test scripts better. * WIP added license header to files and .clang-format file. * Add .travis.yml * Renamed koa-karma-proxy.ts to karma-proxy.ts and koa-karma-proxy-cli.ts to cli.ts etc. * Added a random factor to exponential back-off to avoid port binding races on parallel test runs. * Renamed upsFactor to upstreamProxyServerFactory * Refining and tightening up the port stuff and layout of the start function. * Got the middleware working again. Phew. * Add some documentation to karma.proxy.js * Updated README to show --proxyFile and also how to await ports from the start method. * Added comments for public stuff. * WIP
1 parent 3c87e2d commit 4a63a34

18 files changed

+3847
-11
lines changed

.clang-format

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
BasedOnStyle: Google
2+
AlignAfterOpenBracket: AlwaysBreak
3+
AllowAllParametersOfDeclarationOnNextLine: false
4+
AllowShortBlocksOnASingleLine: false
5+
AllowShortCaseLabelsOnASingleLine: false
6+
AllowShortFunctionsOnASingleLine: None
7+
AllowShortIfStatementsOnASingleLine: false
8+
AllowShortLoopsOnASingleLine: false
9+
BinPackArguments: false
10+
# This breaks async functions sometimes, see
11+
# https://github.com/Polymer/polymer-analyzer/pull/393
12+
# BinPackParameters: false

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
lib/

.travis.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
language: node_js
2+
node_js:
3+
- "node"
4+
dist: xenial
5+
cache:
6+
directories:
7+
- node_modules
8+
script:
9+
- npm run build
10+
- npm test

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
6+
and this project adheres to [Semantic Versioning](http://semver.org/).
7+
8+
<!--
9+
PRs should document their user-visible changes (if any) in the
10+
Unreleased section, uncommenting the header as necessary.
11+
-->
12+
13+
<!-- ## Unreleased -->
14+
<!-- Add new unreleased items here -->

LICENSE

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2019 The Polymer Authors. All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
* Redistributions of source code must retain the above copyright notice, this
9+
list of conditions and the following disclaimer.
10+
11+
* Redistributions in binary form must reproduce the above copyright notice,
12+
this list of conditions and the following disclaimer in the documentation
13+
and/or other materials provided with the distribution.
14+
15+
* Neither the name of the copyright holder nor the names of its
16+
contributors may be used to endorse or promote products derived from
17+
this software without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29+

README.md

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ module.exports = (karma) => new Koa()
3737
.use(karma);
3838
```
3939
40-
Use the `koa-karma-proxy` wrapper exactly as you'd use `karma` executable:
40+
Use the `karma-proxy` wrapper script exactly as you'd use `karma` executable:
4141
4242
```sh
43-
$ npx koa-karma-proxy start
43+
$ npx karma-proxy start
4444
```
4545
4646
This will:
@@ -51,22 +51,33 @@ This will:
5151
4. wait for karma to confirm the port it is listening on.
5252
5. configure the proxy middleware to start directing requests to karma.
5353
54+
If you want to name your `karma.proxy.js` file differently or put it somewhere else, use the `--proxyFile` command-line argument to specify it like:
55+
56+
```sh
57+
$ npx karma-proxy start --proxyFile ./lib/my-proxy.js
58+
```
59+
5460
## Advanced Usage
5561
56-
You don't have to use `koa-karma-proxy` as an executable from the command-line. It exposes everything you need to leverage within your own code:
62+
You don't have to use `karma-proxy` as an executable from the command-line. It exposes everything you need to leverage within your own code:
5763
5864
```ts
5965
const Koa = require('koa');
6066
const mount = require('koa-mount');
6167
const {join} = require('path');
62-
const {karmaProxy} = require('koa-karma-proxy');
68+
const {start} = require('koa-karma-proxy');
6369
const {nodeResolve} = require('koa-node-resolve');
6470

65-
karmaProxy.start((karma) => new Koa()
66-
.use(mount('/base', nodeResolve())
67-
.use(karma), {
68-
// Karma config options
69-
configFile: join(__dirname, '../karma.conf.js'),
70-
singleRun: true
71-
});
71+
(async () => {
72+
const {upstreamProxyPort, karmaPort} =
73+
await start((karma) => new Koa()
74+
.use(mount('/base', nodeResolve())
75+
.use(karma), {
76+
// Karma config options
77+
configFile: join(__dirname, '../karma.conf.js'),
78+
singleRun: true
79+
});
80+
console.log(`Upstream Port ${upstreamProxyPort}`);
81+
console.log(`Karma Port ${karmaPort}`);
82+
})();
7283
```

0 commit comments

Comments
 (0)