Skip to content

Commit

Permalink
fix: better config types
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Ferreiro Val committed Jun 17, 2019
1 parent 18e065c commit 59110c5
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 115 deletions.
7 changes: 1 addition & 6 deletions packages/@best/cli/src/run_best.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,10 @@ import path from 'path';
import micromatch from 'micromatch';
import { FrozenGlobalConfig, FrozenProjectConfig } from '@best/config';

const IGNORE_PATHS = [
'**/__benchmarks_results__/**',
'**/node_modules/**',
'**/__tests__/**'
];

async function getBenchmarkPaths(config: FrozenProjectConfig, globalConfig: FrozenGlobalConfig): Promise<string[]> {
const { testMatch, testPathIgnorePatterns, rootDir: cwd } = config;
const ignore = [...IGNORE_PATHS, ...testPathIgnorePatterns];
const ignore = [ ...testPathIgnorePatterns];
const results = await fg(testMatch, { onlyFiles: true, ignore, cwd });
return results.map((benchPath: string) => path.resolve(cwd, benchPath));
}
Expand Down
27 changes: 8 additions & 19 deletions packages/@best/config/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

import { resolveConfigPath, readConfigAndSetRootDir, ensureNoDuplicateConfigs } from './utils/resolve-config';
import { getGitInfo, GitInfo } from './utils/git';
import { normalizeConfig, normalizeRegexPattern, normalizeRootDirPattern } from './utils/normalize';
import { BestCliOptions, DefaultProjectOptions, FrozenProjectConfig, FrozenGlobalConfig, ProjectConfigs, ProjectConfigPlugin} from './internal-types';
import { normalizeConfig, normalizeRootDirPattern } from './utils/normalize';
import { BestCliOptions, NormalizedConfig, FrozenProjectConfig, FrozenGlobalConfig, ProjectConfigs, ProjectConfigPlugin} from './internal-types';
export { BestCliOptions, FrozenProjectConfig, FrozenGlobalConfig, ProjectConfigs, ProjectConfigPlugin };

function generateProjectConfigs(options: DefaultProjectOptions, isRoot: boolean, gitInfo?: GitInfo): { projectConfig: FrozenProjectConfig, globalConfig: FrozenGlobalConfig | undefined } {
function generateProjectConfigs(options: NormalizedConfig, isRoot: boolean, gitInfo?: GitInfo): { projectConfig: FrozenProjectConfig, globalConfig: FrozenGlobalConfig | undefined } {
let globalConfig: FrozenGlobalConfig | undefined;

if (isRoot) {
Expand All @@ -15,7 +15,6 @@ function generateProjectConfigs(options: DefaultProjectOptions, isRoot: boolean,

globalConfig = Object.freeze({
gitIntegration: options.gitIntegration,
detectLeaks: options.detectLeaks,
compareStats: options.compareStats,
externalStorage: options.externalStorage,
apiDatabase: options.apiDatabase,
Expand All @@ -24,32 +23,22 @@ function generateProjectConfigs(options: DefaultProjectOptions, isRoot: boolean,
rootProjectName: options.projectName,
nonFlagArgs: options.nonFlagArgs,
gitInfo: gitInfo,
outputMetricPattern: normalizeRegexPattern(options.outputMetricNames),
isInteractive: options.isInteractive,
// outputTotals: options.outputTotals,
// outputHistograms: options.outputHistograms,
// outputHistogramPattern: normalizeRegexPattern(options.outputHistogramNames),
// histogramQuantileRange: options.histogramQuantileRange,
// histogramMaxWidth: options.histogramMaxWidth,
// normalize: options.normalize,
// openPages: options.openPages,
});
}

const projectConfig: FrozenProjectConfig = Object.freeze({
cache: options.cache,
cacheDirectory: options.cacheDirectory,
useHttp: options.useHttp,
detectLeaks: options.detectLeaks,
displayName: options.displayName,
moduleDirectories: options.moduleDirectories,
moduleFileExtensions: options.moduleFileExtensions,
plugins: options.plugins,
rootDir: options.rootDir,
projectName: options.projectName,

benchmarkRunner: options.runnerConfig.alias || options.runner,
benchmarkRunnerConfig: options.runnerConfig.config || options.runnerConfig,
benchmarkRunner: options.runner,
benchmarkRunnerConfig: options.runnerConfig,
benchmarkEnvironment: options.benchmarkEnvironment,
benchmarkEnvironmentOptions: options.benchmarkEnvironmentOptions,
benchmarkMaxDuration: options.benchmarkMaxDuration,
Expand All @@ -59,16 +48,16 @@ function generateProjectConfigs(options: DefaultProjectOptions, isRoot: boolean,
benchmarkOutput: normalizeRootDirPattern(options.benchmarkOutput, options.rootDir),
benchmarkCustomAssets: normalizeRootDirPattern(options.benchmarkCustomAssets, options.rootDir),
testMatch: options.testMatch,
testPathIgnorePatterns: options.testPathIgnorePatterns || [],
testPathIgnorePatterns: options.testPathIgnorePatterns
});

return { globalConfig, projectConfig };
}

export async function readConfig(cliOptions: BestCliOptions, packageRoot: string, parentConfigPath?: string): Promise<{ configPath: string, globalConfig?: FrozenGlobalConfig, projectConfig: FrozenProjectConfig }> {
const configPath = resolveConfigPath(packageRoot, process.cwd());
const rawOptions = readConfigAndSetRootDir(configPath);
const options = normalizeConfig(rawOptions, cliOptions);
const userConfig = readConfigAndSetRootDir(configPath);
const options = normalizeConfig(userConfig, cliOptions);
let gitConfig;

// If we have a parent Config path, we are in a nested/project best config
Expand Down
35 changes: 18 additions & 17 deletions packages/@best/config/src/internal-types.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
import { GitInfo } from "./utils/git";

export interface RawBestConfig {
export interface UserBestConfig {
[key: string]: any;
rootDir: string;
benchmarkIterations? : number;
compareStats?: string[];

projectName: string;
nonFlagArgs: string[];
}

export interface RunnerConfig {
alias: string;
runner: string;
config: any;
config?: any;
}

export interface DefaultProjectOptions {
[key: string]: any,
export interface NormalizedConfig {
nonFlagArgs: string[];
cache: boolean,
cacheDirectory: string,
compareStats?: string[],
gitIntegration: boolean,
useHttp: boolean,
externalStorage?: string,
apiDatabase?: string,
isInteractive?: boolean,
openPages: boolean,
moduleDirectories: string[],
moduleFileExtensions: string[],
moduleNameMapper: { [moduleName:string]: string },
modulePathIgnorePatterns: string[],
projectName: string,
projects: string[],
plugins: ProjectConfigPlugin[],
runner: string,
runnerConfig: RunnerConfig,
runners?: RunnerConfig[],
runnerConfig: any,
benchmarkEnvironment: string,
benchmarkEnvironmentOptions: {[key:string]: string },
benchmarkMaxDuration: number,
Expand All @@ -35,14 +43,7 @@ export interface DefaultProjectOptions {
benchmarkOutput: string,
benchmarkCustomAssets: string,
testMatch: string[],
samplesQuantileThreshold: number,
normalize: boolean,
outputMetricNames: string,
outputTotals: boolean,
outputHistograms: boolean,
outputHistogramNames: string,
histogramQuantileRange: [number, number],
histogramMaxWidth: number,
testPathIgnorePatterns: string[],
rootDir: string
}

Expand All @@ -66,7 +67,6 @@ export interface BestCliOptions {
export interface GlobalConfig {
gitIntegration: boolean;
projects: string[];
detectLeaks: boolean;
nonFlagArgs: string[];
isInteractive? : boolean;
gitInfo: GitInfo;
Expand All @@ -76,6 +76,7 @@ export type ProjectConfigPlugin = string | [string, { [key : string]: any }]

export interface ProjectConfig {
benchmarkRunner: string;
benchmarkRunnerConfig: any;
benchmarkOutput: string;
benchmarkCustomAssets: string;
cacheDirectory: string;
Expand Down
35 changes: 21 additions & 14 deletions packages/@best/config/src/utils/defaults.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { cacheDirectory } from '@best/utils';
import { DefaultProjectOptions } from "../internal-types";

const defaultOptions: DefaultProjectOptions = {
const defaultOptions = {
cache: true,
gitIntegration: false,
cacheDirectory: cacheDirectory(),
useHttp: true,
openPages: false,
Expand All @@ -11,11 +11,13 @@ const defaultOptions: DefaultProjectOptions = {
moduleNameMapper: {},
modulePathIgnorePatterns: [],
runner: "default",
runnerConfig: {
runners: [{
alias: "default",
runner: '@best/runner-headless',
config: {}
},
runner: '@best/runner-headless'
}],
plugins: [],
projects: [],
runnerConfig: {},
benchmarkEnvironment: 'production',
benchmarkMaxDuration: 1000 * 15, // 15s
benchmarkMinIterations: 30,
Expand All @@ -25,30 +27,35 @@ const defaultOptions: DefaultProjectOptions = {
benchmarkEnvironmentOptions: {},
benchmarkCustomAssets: '<rootDir>/__benchmarks__/assets',
testMatch: ['**/__benchmarks__/**/*.benchmark.js'],
testPathIgnorePatterns: [
'**/__benchmarks_results__/**',
'**/node_modules/**',
'**/__tests__/**'
],

// Calculate statistics on entire distributions (including possible outliers).
samplesQuantileThreshold: 1,
// samplesQuantileThreshold: 1,

// Don't try to normalize distributions.
normalize: false,
// normalize: false,

// Show every metric (e.g. "duration" and "runDuration") in CLI output.
outputMetricNames: '*',
// outputMetricNames: '*',

// Don't show totals for each metric in a benchmark table.
outputTotals: false,
// outputTotals: false,

// Don't show histograms for each distribution in CLI output.
outputHistograms: false,
// outputHistograms: false,

// If showing histograms, show every one.
outputHistogramNames: '*',
// outputHistogramNames: '*',

// If histograms are shown, hide long tails by omitting the top and bottom 5%.
histogramQuantileRange: [0.05, 0.95],
// histogramQuantileRange: [0.05, 0.95],

// If histograms are shown, make them a limited number of characters wide.
histogramMaxWidth: 50,
// histogramMaxWidth: 50,

rootDir: process.cwd(),
};
Expand Down
Loading

0 comments on commit 59110c5

Please sign in to comment.