From f66069f2e38ea89de67d649b3b0bb84cc726ed73 Mon Sep 17 00:00:00 2001 From: Westbrook Johnson Date: Thu, 5 May 2022 12:08:18 -0400 Subject: [PATCH] fix: move property management into update or willUpdate --- packages/base/src/sizedMixin.ts | 4 ++-- packages/field-label/src/FieldLabel.ts | 9 ++++----- test/benchmark/bench-runner.html | 3 ++- test/benchmark/cli.ts | 25 ++++++++++++++++++------- test/tsconfig.json | 5 ++++- 5 files changed, 30 insertions(+), 16 deletions(-) diff --git a/packages/base/src/sizedMixin.ts b/packages/base/src/sizedMixin.ts index 200a608bf2..5eaf2bd5ab 100644 --- a/packages/base/src/sizedMixin.ts +++ b/packages/base/src/sizedMixin.ts @@ -73,11 +73,11 @@ export function SizedMixin>( private _size: ElementSize | null = defaultSize; - protected firstUpdated(changes: PropertyValues): void { - super.firstUpdated(changes); + protected update(changes: PropertyValues): void { if (!this.hasAttribute('size') && !noDefaultSize) { this.setAttribute('size', this.size); } + super.update(changes); } } return SizedElement; diff --git a/packages/field-label/src/FieldLabel.ts b/packages/field-label/src/FieldLabel.ts index 7329394931..08263ef1a0 100644 --- a/packages/field-label/src/FieldLabel.ts +++ b/packages/field-label/src/FieldLabel.ts @@ -134,17 +134,16 @@ export class FieldLabel extends SizedMixin(SpectrumElement) { protected firstUpdated(changes: PropertyValues): void { super.firstUpdated(changes); + this.addEventListener('click', this.handleClick); + } + + protected willUpdate(changes: PropertyValues): void { if (!this.hasAttribute('id')) { this.setAttribute( 'id', `${this.tagName.toLowerCase()}-${FieldLabel.instanceCount++}` ); } - this.addEventListener('click', this.handleClick); - } - - protected updated(changes: PropertyValues): void { - super.updated(changes); if (changes.has('for') || changes.has('id')) { this.manageFor(); } diff --git a/test/benchmark/bench-runner.html b/test/benchmark/bench-runner.html index ec2e5a9427..425f749e02 100644 --- a/test/benchmark/bench-runner.html +++ b/test/benchmark/bench-runner.html @@ -23,8 +23,9 @@ const params = new URLSearchParams(window.location.search); const pack = params.get('package'); const bench = params.get('bench'); + const dir = params.get('dir'); window.tachometerStart = params.get('start'); - import(`../../packages/${pack}/test/benchmark/${bench}.js`); + import(`../../${dir}/${pack}/test/benchmark/${bench}.js`); diff --git a/test/benchmark/cli.ts b/test/benchmark/cli.ts index 8b466b97ec..ab671b8a0b 100644 --- a/test/benchmark/cli.ts +++ b/test/benchmark/cli.ts @@ -11,7 +11,7 @@ governing permissions and limitations under the License. */ import { main } from 'tachometer/lib/cli'; import { ConfigFile } from 'tachometer/lib/configfile'; -import { readdirSync, writeFileSync } from 'fs'; +import { existsSync, readdirSync, writeFileSync } from 'fs'; import { join as pathjoin } from 'path'; import * as commandLineArgs from 'command-line-args'; import * as commandLineUsage from 'command-line-usage'; @@ -163,7 +163,12 @@ $ node test/benchmark/cli -n 20 benchmarks: [], }; - const hasTests = readdirSync(pathjoin('packages', packageName)).find( + // Naively assume any change that doesn't exist is "packages" exists in "tools". + const monorepoDir = existsSync(pathjoin('packages', packageName)) + ? 'packages' + : 'tools'; + + const hasTests = readdirSync(pathjoin(monorepoDir, packageName)).find( (dirEntry) => dirEntry === 'test' ); @@ -172,7 +177,7 @@ $ node test/benchmark/cli -n 20 } const hasBenchmarks = readdirSync( - pathjoin('packages', packageName, 'test') + pathjoin(monorepoDir, packageName, 'test') ).find((dirEntry) => dirEntry === 'benchmark'); if (!hasBenchmarks) { @@ -180,7 +185,7 @@ $ node test/benchmark/cli -n 20 } const benchmarks = readdirSync( - pathjoin('packages', packageName, 'test', 'benchmark'), + pathjoin(monorepoDir, packageName, 'test', 'benchmark'), { withFileTypes: true } ) .filter( @@ -194,7 +199,12 @@ $ node test/benchmark/cli -n 20 * have yet to be published to NPM and skip. **/ const pjson = await import( - pathjoin(process.cwd(), 'packages', packageName, 'package.json') + pathjoin( + process.cwd(), + monorepoDir, + packageName, + 'package.json' + ) ); if (pjson.version === '0.0.1' && opts.compare !== 'none') { // eslint-disable-next-line no-console @@ -207,11 +217,12 @@ $ node test/benchmark/cli -n 20 if (opts.compare !== 'none') { config.benchmarks.push({ name: `${packageName}:${benchmark}`, - url: `test/benchmark/bench-runner.html?bench=${benchmark}&package=${packageName}&start=${start}`, + url: `test/benchmark/bench-runner.html?bench=${benchmark}&package=${packageName}&start=${start}&dir=${monorepoDir}`, packageVersions: { label: 'remote', dependencies: { '@spectrum-web-components/bundle': opts.compare, + '@spectrum-web-components/grid': opts.compare, lit: '^2.0.0', }, }, @@ -228,7 +239,7 @@ $ node test/benchmark/cli -n 20 } config.benchmarks.push({ name: `${packageName}:${benchmark}`, - url: `test/benchmark/bench-runner.html?bench=${benchmark}&package=${packageName}`, + url: `test/benchmark/bench-runner.html?bench=${benchmark}&package=${packageName}&dir=${monorepoDir}`, measurement: 'global', browser: { name: opts.browser, diff --git a/test/tsconfig.json b/test/tsconfig.json index dc42f33908..223e7fda4b 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -4,6 +4,9 @@ "outDir": "../", "rootDir": "../" }, - "include": ["../packages/*/test/benchmark/**/*.ts"], + "include": [ + "../packages/*/test/benchmark/**/*.ts", + "../tools/*/test/benchmark/**/*.ts" + ], "exclude": ["benchmark/cli.ts"] }