diff --git a/examples/best-agent/index.js b/examples/best-agent/index.js new file mode 100644 index 00000000..aa38ad1e --- /dev/null +++ b/examples/best-agent/index.js @@ -0,0 +1,2 @@ +const AGENT = require('best-agent'); +AGENT.run(); diff --git a/examples/best-agent/package.json b/examples/best-agent/package.json new file mode 100644 index 00000000..222519ae --- /dev/null +++ b/examples/best-agent/package.json @@ -0,0 +1,25 @@ +{ + "name": "best-agent-example", + "version": "0.4.0", + "private": true, + "description": "Best agent example", + "scripts": { + "start": "best-agent" + }, + "keywords": [ + "lwc", + "agent", + "benchmark", + "perf", + "testing" + ], + "author": "LWC Team", + "homepage": "https://github.com/salesforce/best", + "repository": { + "type": "git", + "url": "https://github.com/salesforce/best" + }, + "dependencies": { + "best-agent": "0.4.0" + } +} diff --git a/examples/simple_benchmark/best.config.js b/examples/simple_benchmark/best.config.js index cbabe40d..7cedf69b 100644 --- a/examples/simple_benchmark/best.config.js +++ b/examples/simple_benchmark/best.config.js @@ -3,6 +3,7 @@ module.exports = { benchmarkOnClient: true, useMacroTaskAfterBenchmark: false, benchmarkRunner: '@best/runner-headless', + // benchmarkRunner: '@best/runner-remote', // This is for running @best/runner-remote // "benchmarkRunnerConfig": { diff --git a/package.json b/package.json index 4ebbf650..58e13bbb 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "watch": "yarn build && node ./scripts/watch.js", "test": "jest --config jest.config.json", "perf": "best --externalStorage=@best/store-aws", - "start": "cd examples/best-frontend && yarn serve", + "start": "node scripts/start.js", "web:watch": "lerna exec --scope @best/frontend 'yarn watch'", "web:watch:s3": "STORE_PLUGIN=@best/store-aws lerna exec --scope @best/frontend 'yarn watch'", "release": "yarn prepare && lerna publish --exact --force-publish=* --registry='https://npm.lwcjs.org' && yarn changelog", diff --git a/packages/best-agent/package.json b/packages/best-agent/package.json index 473a85b1..f63b8cfe 100644 --- a/packages/best-agent/package.json +++ b/packages/best-agent/package.json @@ -6,7 +6,7 @@ "Best", "LWC" ], - "main": "build/index.js", + "main": "build/cli/index.js", "module": "src/index.js", "dependencies": { "@best/runner": "0.4.0", diff --git a/packages/best-agent/src/cli/index.js b/packages/best-agent/src/cli/index.js index d6701720..7645d886 100644 --- a/packages/best-agent/src/cli/index.js +++ b/packages/best-agent/src/cli/index.js @@ -1,7 +1,7 @@ import express from 'express'; import { Server } from 'http'; import { runAgent } from '../agent-service'; -const PORT = process.env.port || 5000; +const PORT = process.env.PORT || 5000; export function run() { const app = express(); diff --git a/packages/best-agent/src/client.js b/packages/best-agent/src/client.js index 01306880..a4adc989 100644 --- a/packages/best-agent/src/client.js +++ b/packages/best-agent/src/client.js @@ -24,16 +24,19 @@ const LOADER_CONFIG = { function initializeForwarder(config, socket, logger) { return { - onBenchmarkStart(benchmarkName) { - logger(`STATUS: running_benchmark (${benchmarkName})`); - socket.emit('running_benchmark_start', benchmarkName); + onBenchmarkStart(benchmarkName, projectName) { + logger(`STATUS: running_benchmark ${benchmarkName} (${projectName})`); + socket.emit('running_benchmark_start', benchmarkName, projectName); }, updateBenchmarkProgress(state, opts) { socket.emit('running_benchmark_update', { state, opts }); }, - onBenchmarkEnd(benchmarkName) { - logger(`STATUS: finished_benchmark (${benchmarkName})`); - socket.emit('running_benchmark_end', benchmarkName); + onBenchmarkEnd(benchmarkName, projectName) { + logger(`STATUS: finished_benchmark ${benchmarkName} (${projectName})`); + socket.emit('running_benchmark_end', benchmarkName, projectName); + }, + onBenchmarkError(benchmarkName, projectName) { + socket.emit('running_benchmark_error', benchmarkName, projectName); }, }; } diff --git a/packages/best-runner-headless/src/__tests__/runner-headless.spec.js b/packages/best-runner-headless/src/__tests__/runner-headless.spec.js index 0b95911e..1cae16b6 100644 --- a/packages/best-runner-headless/src/__tests__/runner-headless.spec.js +++ b/packages/best-runner-headless/src/__tests__/runner-headless.spec.js @@ -17,7 +17,6 @@ const MOCK_MESSAGER = { updateBenchmarkProgress() {}, onBenchmarkEnd() {}, onBenchmarkError() {} - }; describe('run', () => { diff --git a/packages/best-runner-remote/src/index.js b/packages/best-runner-remote/src/index.js index 97b2a1a6..171582b7 100644 --- a/packages/best-runner-remote/src/index.js +++ b/packages/best-runner-remote/src/index.js @@ -34,8 +34,8 @@ function proxifyRunner(benchmarkEntryBundle, runnerConfig, projectConfig, global }); }); - socket.on('running_benchmark_start', benchName => { - messager.onBenchmarkStart(benchName, { + socket.on('running_benchmark_start', (benchName, projectName) => { + messager.onBenchmarkStart(benchName, projectName, { displayPath: `${host}/${benchName}`, }); }); @@ -43,8 +43,8 @@ function proxifyRunner(benchmarkEntryBundle, runnerConfig, projectConfig, global socket.on('running_benchmark_update', ({ state, opts }) => { messager.updateBenchmarkProgress(state, opts); }); - socket.on('running_benchmark_end', benchName => { - messager.onBenchmarkEnd(benchName); + socket.on('running_benchmark_end', (benchName, projectName) => { + messager.onBenchmarkEnd(benchName, projectName); }); // socket.on('disconnect', (s) => { diff --git a/scripts/start.js b/scripts/start.js new file mode 100644 index 00000000..e0302d5f --- /dev/null +++ b/scripts/start.js @@ -0,0 +1,9 @@ +const BEST_SERVICE_TYPE = process.env.BEST_SERVICE_TYPE || 'frontend'; + +console.log(`Initializing ${BEST_SERVICE_TYPE}`); + +if (BEST_SERVICE_TYPE === 'frontend') { + require('best-frontend-example'); +} else if (BEST_SERVICE_TYPE === 'agent') { + require('best-agent').run(); +}