Skip to content

Commit

Permalink
fix(cli): merging
Browse files Browse the repository at this point in the history
  • Loading branch information
lynchbomb committed Oct 25, 2019
1 parent 79ba9bc commit c4ee0f2
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 45 deletions.
51 changes: 26 additions & 25 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,17 @@
https://github.com/TracerBench/tracerbench/blob/master/README.md

<!-- toc -->

- [TracerBench Core](#tracerbench-core)
- [Usage](#usage)
- [Optional Config](#optional-config)
- [Example Travis-CI Integration](#example-travis-ci-integration)
- [FAQ](#faq)
- [Commands](#commands)
<!-- tocstop -->
* [TracerBench Core](#tracerbench-core)
* [Usage](#usage)
* [Optional Config](#optional-config)
* [Example Travis-CI Integration](#example-travis-ci-integration)
* [FAQ](#faq)
* [Commands](#commands)
<!-- tocstop -->

# Usage

<!-- usage -->

```sh-session
$ npm install -g tracerbench
$ tracerbench COMMAND
Expand All @@ -33,7 +31,6 @@ USAGE
$ tracerbench COMMAND
...
```

<!-- usagestop -->

# Optional Config
Expand Down Expand Up @@ -193,17 +190,16 @@ s?: TRACE_EVENT_SCOPE;
# Commands

<!-- commands -->
* [`tracerbench `](#tracerbench-)
* [`tracerbench compare`](#tracerbench-compare)
* [`tracerbench compare:analyze RESULTSFILE`](#tracerbench-compareanalyze-resultsfile)
* [`tracerbench help [COMMAND]`](#tracerbench-help-command)
* [`tracerbench marker-timings`](#tracerbench-marker-timings)
* [`tracerbench record-har`](#tracerbench-record-har)
* [`tracerbench report`](#tracerbench-report)
* [`tracerbench trace`](#tracerbench-trace)

- [`tracerbench`](#tracerbench-)
- [`tracerbench compare`](#tracerbench-compare)
- [`tracerbench compare:analyze RESULTSFILE`](#tracerbench-compareanalyze-resultsfile)
- [`tracerbench help [COMMAND]`](#tracerbench-help-command)
- [`tracerbench marker-timings`](#tracerbench-marker-timings)
- [`tracerbench record-har`](#tracerbench-record-har)
- [`tracerbench report`](#tracerbench-report)
- [`tracerbench trace`](#tracerbench-trace)

## `tracerbench`
## `tracerbench `

Generates a HAR file from a URL.

Expand All @@ -224,6 +220,8 @@ OPTIONS
--url=url (required) URL to visit for record-har, timings & trace commands
```

_See code: [dist/src/commands/index.ts](https://github.com/TracerBench/tracerbench/tree/master/packages/cli/blob/v2.3.0/dist/src/commands/index.ts)_

## `tracerbench compare`

Compare the performance delta between an experiment and control
Expand All @@ -234,14 +232,14 @@ USAGE
OPTIONS
--browserArgs=browserArgs
(required) [default:
(required) [default:
--crash-dumps-dir=./tmp,--disable-background-timer-throttling,--disable-dev-shm-usage,--disable-cache,--disable-v8-i
dle-tasks,--disable-breakpad,--disable-notifications,--disable-hang-monitor,--safebrowsing-disable-auto-update,--ign
ore-certificate-errors,--v8-cache-options=none] (Default Recommended) Additional chrome flags for the TracerBench
ore-certificate-errors,--v8-cache-options=none] (Default Recommended) Additional chrome flags for the TracerBench
render benchmark. TracerBench includes many non-configurable defaults in this category.
--config=config
Specify an alternative directory rather than the project root for the tbconfig.json. This explicit config will
Specify an alternative directory rather than the project root for the tbconfig.json. This explicit config will
overwrite all.
--controlURL=controlURL
Expand Down Expand Up @@ -320,6 +318,8 @@ OPTIONS
tracerbench results
```

_See code: [dist/src/commands/compare/analyze.ts](https://github.com/TracerBench/tracerbench/tree/master/packages/cli/blob/v2.3.0/dist/src/commands/compare/analyze.ts)_

## `tracerbench help [COMMAND]`

display help for tracerbench
Expand Down Expand Up @@ -356,6 +356,8 @@ OPTIONS
--url=url (required) URL to visit for record-har, timings & trace commands
```

_See code: [dist/src/commands/marker-timings.ts](https://github.com/TracerBench/tracerbench/tree/master/packages/cli/blob/v2.3.0/dist/src/commands/marker-timings.ts)_

## `tracerbench record-har`

Generates a HAR file from a URL.
Expand All @@ -377,7 +379,7 @@ OPTIONS
--url=url (required) URL to visit for record-har, timings & trace commands
```

_See code: [dist/src/commands/marker-timings.ts](https://github.com/TracerBench/tracerbench/tree/master/packages/cli/blob/v2.3.0/dist/src/commands/marker-timings.ts)_
_See code: [dist/src/commands/record-har.ts](https://github.com/TracerBench/tracerbench/tree/master/packages/cli/blob/v2.3.0/dist/src/commands/record-har.ts)_

## `tracerbench report`

Expand Down Expand Up @@ -435,5 +437,4 @@ OPTIONS
```

_See code: [dist/src/commands/trace.ts](https://github.com/TracerBench/tracerbench/tree/master/packages/cli/blob/v2.3.0/dist/src/commands/trace.ts)_

<!-- commandsstop -->
3 changes: 0 additions & 3 deletions packages/cli/src/command-config/tb-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,4 @@ export default abstract class TBBaseCommand extends Command {
constructor(argv: string[], config: IConfig) {
super(argv, config);
}
public async init() {
//
}
}
19 changes: 8 additions & 11 deletions packages/cli/src/commands/record-har.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Command } from '@oclif/command';
import { readJson, writeFileSync } from 'fs-extra';
import * as path from 'path';
import { resolve, join } from 'path';
import { setGracefulCleanup, dirSync } from 'tmp';
import { recordHARClient } from '@tracerbench/core';

import { TBBaseCommand } from '../command-config';
import { dest, url, cookiespath, filename, marker } from '../helpers/flags';

setGracefulCleanup();

export default class RecordHAR extends Command {
export default class RecordHAR extends TBBaseCommand {
public static description = 'Generates a HAR file from a URL.';
public static flags = {
url: url({ required: true, default: undefined }),
Expand All @@ -23,7 +23,7 @@ export default class RecordHAR extends Command {
const { url, dest, cookiespath, filename, marker } = flags;

// grab the auth cookies
const cookies = await readJson(path.resolve(cookiespath));
const cookies = await readJson(resolve(cookiespath));

// record the actual HAR and return the archive file
const harArchive = await recordHARClient(
Expand All @@ -33,14 +33,11 @@ export default class RecordHAR extends Command {
marker
);

writeFileSync(
path.join(dest, `${filename}.har`),
JSON.stringify(harArchive)
);
const harPath = join(dest, `${filename}.har`);

this.log(
`HAR recorded and available here: ${path.join(dest, filename)}.har`
);
writeFileSync(harPath, JSON.stringify(harArchive));

this.log(`HAR recorded and available here: ${harPath}`);
}
}

Expand Down
14 changes: 13 additions & 1 deletion packages/cli/test/commands/record-har.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { test } from '@oclif/test';
import { IArchive } from '@tracerbench/core';
import { expect, assert } from 'chai';
import { readJSONSync } from 'fs-extra';
import { join } from 'path';
import RecordHAR from '../../src/commands/record-har';
import { COOKIES, TB_RESULTS_FOLDER, URL } from '../test-helpers';

Expand All @@ -21,8 +24,17 @@ describe('record-har', () => {
'--filename',
FILENAME,
]);

const harFile = join(TB_RESULTS_FOLDER, `${FILENAME}.har`);
const harJSON: IArchive = readJSONSync(harFile);

expect(ctx.stdout).to.contain(`HAR recorded and available here:`);
assert.exists(`${TB_RESULTS_FOLDER}/${FILENAME}.har`);
expect(harJSON.log.entries.length).to.be.gt(1);
expect(harJSON.log.entries[0].request.url).to.contain(`${URL}`);

assert.exists(harFile);
assert.equal(harJSON.log.creator.name, 'TracerBench');
assert.equal(harJSON.log.entries[0].response.status, 200);
}
);
});
File renamed without changes.
2 changes: 0 additions & 2 deletions packages/cli/test/mocha.opts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@
--reporter spec
--timeout 60000
--file ./test/setup.ts
--file ./test/commands/record-har.ts
--file ./test/commands/trace.ts
4 changes: 2 additions & 2 deletions packages/cli/test/tbconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"$schema": "https://github.com/raw/TracerBench/tracerbench/master/packages/cli/tb-schema.json",
"extends": "./tbconfig_base.json",
}
"extends": "./tbconfig_base.json"
}
2 changes: 1 addition & 1 deletion packages/cli/test/test-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const URL = 'https://www.tracerbench.com';
export const COMPARE_JSON = resolve(
join(process.cwd(), '/test/fixtures/results/compare.json')
);
export const TRACE = resolve(join(process.cwd(), '/test/fixtures/trace.json'));

export interface FileStructure {
[key: string]: string | FileStructure;
Expand Down Expand Up @@ -58,4 +59,3 @@ export function generateFileStructure(
}
});
}
export const TRACE = resolve(join(process.cwd(), '/test/fixtures/trace.json'));

0 comments on commit c4ee0f2

Please sign in to comment.