Skip to content

Commit

Permalink
fix: more result tyeps
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Ferreiro Val committed Jun 19, 2019
1 parent 57223c0 commit ea90ae3
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 31 deletions.
6 changes: 1 addition & 5 deletions packages/@best/cli/src/run_best.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ async function buildBundleBenchmarks(benchmarksTests: { config: FrozenProjectCon
return benchmarkBuilds;
}

async function runBundleBenchmarks(benchmarksBuilds: BuildConfig[], runnerLogStream: RunnerOutputStream) {
return runBenchmarks(benchmarksBuilds, runnerLogStream);
}

function hasMatches(benchmarksTests: { config: FrozenProjectConfig, matches: string[] }[]) {
return benchmarksTests.some(({ matches }) => matches.length);
}
Expand All @@ -93,7 +89,7 @@ export async function runBest(globalConfig: FrozenGlobalConfig, configs: FrozenP

const runnerLogStream = new RunnerOutputStream(benchmarksBuilds, outputStream, globalConfig.isInteractive);
runnerLogStream.init();
const benchmarkBundleResults = await runBundleBenchmarks(benchmarksBuilds, runnerLogStream);
const benchmarkBundleResults = await runBenchmarks(benchmarksBuilds, runnerLogStream);
runnerLogStream.finish();

await analyzeBenchmarks(benchmarkBundleResults);
Expand Down
13 changes: 2 additions & 11 deletions packages/@best/runner-abstract/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { RunnerOutputStream } from "@best/console-stream";
import { FrozenGlobalConfig, FrozenProjectConfig, BenchmarkInfo, BenchmarkRuntimeConfig, BenchmarkResultsSnapshot, BrowserConfig, EnvironmentConfig } from '@best/types';

export default abstract class AbstractRunner {
abstract async run({ benchmarkEntry }: BenchmarkInfo, projectConfig: FrozenProjectConfig, globalConfig: FrozenGlobalConfig, runnerLogStream: RunnerOutputStream): Promise<BenchmarkResultsSnapshot>;
abstract async run(benchmarkInfo: BenchmarkInfo, projectConfig: FrozenProjectConfig, globalConfig: FrozenGlobalConfig, runnerLogStream: RunnerOutputStream): Promise<BenchmarkResultsSnapshot>;

initializeServer(benchmarkEntry: string, useHttp: boolean): Promise<{ terminate:Function, url: string }> {
if (!useHttp) {
Expand Down Expand Up @@ -41,15 +41,8 @@ export default abstract class AbstractRunner {
};
}

async getHardwareSpec() {
async getEnvironment(browser: BrowserConfig, projectConfig: FrozenProjectConfig, globalConfig: FrozenGlobalConfig): Promise<EnvironmentConfig> {
const { system, cpu, os, load } = await getSystemInfo();
return {
hardware: { system, cpu, os },
container: { load }
}
}

async normalizeEnvironment(browser: BrowserConfig, projectConfig: FrozenProjectConfig, globalConfig: FrozenGlobalConfig): Promise<EnvironmentConfig> {
const {
benchmarkOnClient,
benchmarkRunner,
Expand All @@ -58,8 +51,6 @@ export default abstract class AbstractRunner {
projectName,
} = projectConfig;

const { system, cpu, os, load } = await getSystemInfo();

return {
hardware: { system, cpu, os },
container: { load },
Expand Down
3 changes: 3 additions & 0 deletions packages/@best/runner-headless/src/headless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,7 @@ export default class HeadlessBrowser {

return result;
}
version() {
return this.browser ? this.browser.version(): Promise.resolve('unknown');
}
}
7 changes: 5 additions & 2 deletions packages/@best/runner-headless/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const UPDATE_INTERVAL = 300;

export default class Runner extends AbstractRunner {

async run({ benchmarkEntry }: BenchmarkInfo, projectConfig: FrozenProjectConfig, globalConfig: FrozenGlobalConfig, runnerLogStream: RunnerOutputStream): Promise<BenchmarkResultsSnapshot> {
async run(benchmarkInfo: BenchmarkInfo, projectConfig: FrozenProjectConfig, globalConfig: FrozenGlobalConfig, runnerLogStream: RunnerOutputStream): Promise<BenchmarkResultsSnapshot> {
const { benchmarkEntry } = benchmarkInfo;
const { useHttp } = projectConfig;
const runtimeOptions = this.getRuntimeOptions(projectConfig);
const state = this.initializeBenchmarkState();
Expand All @@ -19,7 +20,9 @@ export default class Runner extends AbstractRunner {
await browser.initialize();
runnerLogStream.onBenchmarkStart(benchmarkEntry);
const { results } = await this.runIterations(browser, state, runtimeOptions, runnerLogStream);
return { results };
const version = await browser.version();
const environment = await this.getEnvironment({ version }, projectConfig, globalConfig);
return { results, environment, benchmarkInfo };

} catch (e) {
runnerLogStream.onBenchmarkError(benchmarkEntry);
Expand Down
17 changes: 5 additions & 12 deletions packages/@best/runner/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { BuildConfig } from "@best/types";
import { BuildConfig, BenchmarkInfo, BenchmarkResultsSnapshot } from "@best/types";
import { RunnerOutputStream } from "@best/console-stream";
import AbstractRunner from "@best/runner-abstract";

interface ConcreteRunner extends AbstractRunner {
new(config?: any): ConcreteRunner;
}

export async function runBenchmark(benchmarkBuild: BuildConfig, runnerLogStream: RunnerOutputStream) {
export async function runBenchmark(benchmarkBuild: BuildConfig, runnerLogStream: RunnerOutputStream): Promise<BenchmarkResultsSnapshot> {
const { benchmarkName, benchmarkEntry, benchmarkFolder, benchmarkSignature, projectConfig, globalConfig } = benchmarkBuild;
const { benchmarkRunner } = projectConfig;
let RunnerCtor: ConcreteRunner, runnerInstance: ConcreteRunner;
Expand All @@ -25,18 +25,11 @@ export async function runBenchmark(benchmarkBuild: BuildConfig, runnerLogStream:
throw new Error(`Runner "${benchmarkRunner}" does not expose a constructor.`);
}

const benchmarkBundle = { benchmarkName, benchmarkEntry, benchmarkFolder, benchmarkSignature };
const results: any = await runnerInstance.run(benchmarkBundle, projectConfig, globalConfig, runnerLogStream);

results.benchmarkSignature = benchmarkSignature;
results.benchmarkName = benchmarkName;
results.benchmarkEntry = benchmarkEntry;
results.projectConfig = projectConfig;

return results;
const benchmarkInfo: BenchmarkInfo = { benchmarkName, benchmarkEntry, benchmarkFolder, benchmarkSignature };
return runnerInstance.run(benchmarkInfo, projectConfig, globalConfig, runnerLogStream);
}

export async function runBenchmarks(benchmarksBuilds: BuildConfig[], messager: RunnerOutputStream) {
export async function runBenchmarks(benchmarksBuilds: BuildConfig[], messager: RunnerOutputStream): Promise<BenchmarkResultsSnapshot[]> {
const results = [];
for (const benchmarkBuild of benchmarksBuilds) {
const benchmarkResults = await runBenchmark(benchmarkBuild, messager);
Expand Down
4 changes: 4 additions & 0 deletions packages/@best/types/src/benchmark.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { EnvironmentConfig } from "./config";

export interface BenchmarkInfo {
benchmarkName: string;
benchmarkEntry: string;
Expand Down Expand Up @@ -47,6 +49,8 @@ export interface BenchmarkResults {

export interface BenchmarkResultsSnapshot {
results: BenchmarkResultNode[];
environment: EnvironmentConfig;
benchmarkInfo: BenchmarkInfo;
}

export interface BenchmarkResultsState {
Expand Down
2 changes: 1 addition & 1 deletion packages/@best/types/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export interface BuildConfig {
}

export interface BrowserConfig {
version: number;
version: string;
name?: string;
config?: { [key: string]: any }
}
Expand Down

0 comments on commit ea90ae3

Please sign in to comment.