Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/stress-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
"version": "1.0.0",
"private": true,
"main": "index.js",
"type": "module",
"license": "MIT",
"scripts": {
"stress-test": "ts-node --project tsconfig.scripts.json ./scripts/stressTest.ts",
"stress-test": "ts-node-esm --project tsconfig.scripts.json ./scripts/stressTest.ts",
"type-check": "tsc -b tsconfig.type.json"
},
"dependencies": {
Expand Down
11 changes: 6 additions & 5 deletions apps/stress-test/scripts/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { CLIBuildOptions } from '../utils/types';

import { exec } from 'child_process';
import { promisify } from 'util';
import configureYargs from '../utils/configureYargs';
import * as webpack from 'webpack';

const webpackConfig = require('../../webpack/webpack.config');
import configureYargs from '../utils/configureYargs.js';
import webpack from 'webpack';
import webpackConfig from '../../webpack/webpack.config.js';
import { buildDefaultFixtures } from '../utils/fixtures.js';

const execAsync = promisify(exec);

Expand Down Expand Up @@ -82,11 +82,12 @@ const api: yargs.CommandModule = {
buildDeps: argv.buildDeps as boolean,
};

buildDefaultFixtures();

run(args).then(() => {
console.log('Build complete!');
});
},
};

export default api;
// export { api };
47 changes: 47 additions & 0 deletions apps/stress-test/scripts/commands/buildFixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import * as yargs from 'yargs';
import { CLIBuildFixtureOptions } from '../utils/types';
import configureYargs from '../utils/configureYargs.js';
import { buildTreeFixture, cleanFixtures, isReservedName, reservedNames } from '../utils/fixtures.js';

type BuildFixture = (options: CLIBuildFixtureOptions) => void;

const command = 'build-fixture';

const buildFixture: BuildFixture = ({ type, name, options }) => {
if (type === 'tree') {
buildTreeFixture(name, options);
}
};

const api: yargs.CommandModule = {
command,
describe: 'Builds a test fixture.',
builder: y => {
return configureYargs(command, y);
},
handler: argv => {
const { $0, _, ...options } = argv;

const opts = options as CLIBuildFixtureOptions;

if (opts.clean) {
cleanFixtures();
} else {
if (!opts.name) {
throw new Error(`"name" is required.`);
} else if (!opts.options) {
throw new Error(`"options" is required.`);
}

if (isReservedName(opts.name)) {
throw new Error(
`"${opts.name}" is a reserved name. Please using a name other than ${reservedNames.map(n => n + '*')}`,
);
}

buildFixture(opts);
}
},
};

export default api;
6 changes: 3 additions & 3 deletions apps/stress-test/scripts/commands/buildTestConfig.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as yargs from 'yargs';
import { CLIBuildTestConfigOptions, ConfigResult, TestOptions } from '../utils/types';

import * as fs from 'fs-extra';
import fs from 'fs-extra';
import * as path from 'path';

import { getConfigDir, getResultsDir, ensureClean } from '../utils/paths';
import configureYargs from '../utils/configureYargs';
import { getConfigDir, getResultsDir, ensureClean } from '../utils/paths.js';
import configureYargs from '../utils/configureYargs.js';
import * as querystring from 'querystring';

type BuildTestConfig = (options: CLIBuildTestConfigOptions) => ConfigResult[];
Expand Down
12 changes: 7 additions & 5 deletions apps/stress-test/scripts/commands/dev.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as yargs from 'yargs';
import { CLIDevOptions } from '../utils/types';

import * as webpack from 'webpack';
import * as WebpackDevServer from 'webpack-dev-server';

import configureYargs from '../utils/configureYargs';
const webpackConfig = require('../../webpack/webpack.config');
import webpack from 'webpack';
import WebpackDevServer from 'webpack-dev-server';
import configureYargs from '../utils/configureYargs.js';
import webpackConfig from '../../webpack/webpack.config.js';
import { buildDefaultFixtures } from '../utils/fixtures.js';

const command = 'dev';

Expand Down Expand Up @@ -47,6 +47,8 @@ const api: yargs.CommandModule = {
mode: argv.mode as CLIDevOptions['mode'],
};

buildDefaultFixtures();

runServer(args);
},
};
Expand Down
6 changes: 3 additions & 3 deletions apps/stress-test/scripts/commands/processResults.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as yargs from 'yargs';
import { CLIProcessResultsOptions, ProcessedBrowserData, TachometerBenchmark } from '../utils/types';
import * as fs from 'fs-extra';
import fs from 'fs-extra';
import * as path from 'path';
import configureYargs from '../utils/configureYargs';
import { getResultsDir, readDirJson } from '../utils/paths';
import configureYargs from '../utils/configureYargs.js';
import { getResultsDir, readDirJson } from '../utils/paths.js';

const command = 'process-results';

Expand Down
13 changes: 8 additions & 5 deletions apps/stress-test/scripts/commands/run.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as yargs from 'yargs';
import { CLIBuildTestConfigOptions, CLIRunOptions, CLIServerOptions, ConfigResult } from '../utils/types';
import configureYargs from '../utils/configureYargs';
import { startServer, stopServer } from '../utils/server';
import runTachometer from '../utils/tachometer';
import processResults from './processResults';
import { buildTestConfig } from './buildTestConfig';
import configureYargs from '../utils/configureYargs.js';
import { startServer, stopServer } from '../utils/server.js';
import runTachometer from '../utils/tachometer.js';
import processResults from './processResults.js';
import { buildTestConfig } from './buildTestConfig.js';
import { buildDefaultFixtures } from '../utils/fixtures.js';

const command = 'run';

Expand All @@ -31,6 +32,8 @@ const api: yargs.CommandModule = {
return configureYargs(command, y);
},
handler: async argv => {
buildDefaultFixtures();

const { $0, _, ...rest } = argv;
const args = (rest as unknown) as CLIRunOptions;
await handler(args);
Expand Down
4 changes: 2 additions & 2 deletions apps/stress-test/scripts/commands/runServer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as yargs from 'yargs';

import configureYargs from '../utils/configureYargs';
import { startServer } from '../utils/server';
import configureYargs from '../utils/configureYargs.js';
import { startServer } from '../utils/server.js';
import { CLIServerOptions } from '../utils/types';

const command = 'serve';
Expand Down
8 changes: 4 additions & 4 deletions apps/stress-test/scripts/commands/runTachometer.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as yargs from 'yargs';
import { CLITachometerOptions, ConfigResult } from '../utils/types';
import * as fs from 'fs-extra';
import fs from 'fs-extra';
import * as path from 'path';

import configureYargs from '../utils/configureYargs';
import { getConfigDir, getResultsDir, readDirJson } from '../utils/paths';
import runTachometer from '../utils/tachometer';
import configureYargs from '../utils/configureYargs.js';
import { getConfigDir, getResultsDir, readDirJson } from '../utils/paths.js';
import runTachometer from '../utils/tachometer.js';

const command = 'tachometer';

Expand Down
18 changes: 10 additions & 8 deletions apps/stress-test/scripts/stressTest.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as yargs from 'yargs';
import build from './commands/build';
import buildTestConfig from './commands/buildTestConfig';
import dev from './commands/dev';
import processResults from './commands/processResults';
import run from './commands/run';
import runServer from './commands/runServer';
import runTachometer from './commands/runTachometer';
import yargs from 'yargs';
import build from './commands/build.js';
import buildTestConfig from './commands/buildTestConfig.js';
import dev from './commands/dev.js';
import processResults from './commands/processResults.js';
import run from './commands/run.js';
import runServer from './commands/runServer.js';
import runTachometer from './commands/runTachometer.js';
import buildFixture from './commands/buildFixture.js';

yargs
.usage('Usage: $0 <cmd> [options]')
Expand All @@ -16,6 +17,7 @@ yargs
.command(run)
.command(runServer)
.command(runTachometer)
.command(buildFixture)
.demandCommand()
.help()
.parse();
39 changes: 38 additions & 1 deletion apps/stress-test/scripts/utils/configureYargs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as yargs from 'yargs';
import { getBrowsers } from './getBrowsers';
import { getBrowsers } from './getBrowsers.js';

type YargsOptions = Record<string, yargs.Options>;
type Configure = (y: yargs.Argv, options: YargsOptions) => void;
Expand Down Expand Up @@ -79,6 +79,31 @@ const cliOptions = {
describe: 'Open the dev server in a new browser window.',
default: false,
},
type: {
describe: 'Type of fixture to build.',
default: 'tree',
},
name: {
describe: 'Name of the fixture.',
},
options: {
describe: 'Options for building the fixture. E.g., minBreadth=1 maxBreadth=20',
coerce: (arg: string[]) => {
return arg.reduce((map: { [key: string]: string }, current) => {
const [key, value] = current.split('=');
if (!key || !value) {
throw new Error(`Invalid test option. Got ${current}. Expected the form "key=value".`);
}

map[key] = value;
return map;
}, {});
},
},
clean: {
describe: 'Cleans fixtures.',
default: false,
},
};

const configure: Configure = (y, options) => {
Expand All @@ -91,6 +116,7 @@ const configure: Configure = (y, options) => {
case 'targets':
case 'test-options':
case 'renderers':
case 'options':
_y = _y.array(option);
break;

Expand All @@ -107,6 +133,7 @@ const configure: Configure = (y, options) => {
case 'verbose':
case 'build-deps':
case 'open':
case 'clean':
_y = _y.boolean(option);
break;

Expand All @@ -117,6 +144,10 @@ const configure: Configure = (y, options) => {
case 'mode':
_y = _y.choices(option, ['production', 'development']);
break;

case 'type':
_y = _y.choices(option, ['tree']);
break;
}
});
};
Expand Down Expand Up @@ -209,6 +240,12 @@ const configureYargs: CongfigureYargs = (command, y) => {
configure(y, { mode, open, 'griffel-mode': griffelMode });
break;
}

case 'build-fixture': {
const { type, name, options, clean } = cliOptions;
configure(y, { type, name, options, clean });
break;
}
}

return y;
Expand Down
Loading