Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move from const enums to consts #1645

Merged
merged 15 commits into from
Nov 5, 2024
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
1 change: 0 additions & 1 deletion benchmark/benchmarks/krausest/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export default defineConfig({
resolve: {
alias: {
'@glimmer-workspace/benchmark-env': '@glimmer-workspace/benchmark-env/index.ts',
'@glimmer/debug': packagePath('@glimmer/debug'),
'@glimmer/runtime': packagePath('@glimmer/runtime'),
'@/components': path.join(currentPath, 'lib', 'components'),
'@/utils': path.join(currentPath, 'lib', 'utils'),
Expand Down
6 changes: 5 additions & 1 deletion bin/build-verify.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ const FORBIDDEN = [
'CheckOr',
'CheckFunction',
'CheckObject',

'@glimmer/debug',
'@glimmer/constants',
'@glimmer/debug-util',
];

const IGNORED_DIRS = [`@glimmer/debug`];
const IGNORED_DIRS = [`@glimmer/debug`, `@glimmer/constants`, `@glimmer/debug-util`];

let files = await globby(resolve(currentDir, '../../packages/**/dist/**/index.js'), {
ignore: ['node_modules', '**/node_modules'],
Expand Down
8 changes: 7 additions & 1 deletion packages/@glimmer-workspace/build/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,13 @@ export function typescript(pkg, config) {
const EXTERNAL_OPTIONS = [
[
'is',
['tslib', '@glimmer/local-debug-flags', '@glimmer/debug', '@glimmer/debug-util'],
[
'tslib',
'@glimmer/local-debug-flags',
'@glimmer/constants',
'@glimmer/debug',
'@glimmer/debug-util',
],
'inline',
],
['is', ['@handlebars/parser', 'simple-html-tokenizer', 'babel-plugin-debug-macros'], 'external'],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import type {
COMMENT_NODE,
DOCUMENT_FRAGMENT_NODE,
DOCUMENT_NODE,
TEXT_NODE,
} from '@glimmer/constants';
import type {
Maybe,
Nullable,
Expand All @@ -10,8 +16,8 @@ import type {
SimpleNode,
SimpleText,
} from '@glimmer/interfaces';
import type { COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, TEXT_NODE } from '@glimmer/util';
import { clearElement, ELEMENT_NODE, INSERT_AFTER_BEGIN } from '@glimmer/util';
import { ELEMENT_NODE, INSERT_AFTER_BEGIN } from '@glimmer/constants';
import { clearElement } from '@glimmer/util';
import Serializer from '@simple-dom/serializer';
import voidMap from '@simple-dom/void-map';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Cursor, ElementBuilder, Environment, SimpleNode } from '@glimmer/interfaces';
import { COMMENT_NODE, ELEMENT_NODE } from '@glimmer/constants';
import { RehydrateBuilder } from '@glimmer/runtime';
import { COMMENT_NODE, ELEMENT_NODE } from '@glimmer/util';

export class DebugRehydrationBuilder extends RehydrateBuilder {
clearedNodes: SimpleNode[] = [];
Expand Down
156 changes: 120 additions & 36 deletions packages/@glimmer-workspace/integration-tests/lib/setup-harness.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,60 @@
/* eslint-disable no-console */
import type { Expand } from '@glimmer/interfaces';
import { debug } from '@glimmer/validator';
import { autoRegister } from 'js-reporters';
import { default as QUnit } from 'qunit';

export async function setupQunit() {
const qunit = await import('qunit');
const qunitLib: QUnit = await import('qunit');
await import('qunit/qunit/qunit.css');

const testing = Testing.withConfig(
{
id: 'smoke_tests',
label: 'Smoke Tests',
tooltip: 'Enable Smoke Tests',
},
{
id: 'ci',
label: 'CI Mode',
tooltip:
'CI mode emits tap output and makes tests run faster by sacrificing UI responsiveness',
},
{
id: 'enable_internals_logging',
label: 'Log Deep Internals',
tooltip: 'Logs internals that are used in the development of the trace logs',
},

{
id: 'enable_trace_logging',
label: 'Trace Logs',
tooltip: 'Trace logs emit information about the internal VM state',
},

{
id: 'enable_subtle_logging',
label: '+ Subtle',
tooltip:
'Subtle logs include unchanged information and other details not necessary for normal debugging',
},

{
id: 'enable_trace_explanations',
label: '+ Explanations',
tooltip: 'Also explain the trace logs',
}
);

const runner = autoRegister();
// @ts-expect-error qunit types don't expose "reporters"
const tap = qunit.reporters.tap;
tap.init(runner, { log: console.info });

QUnit.config.urlConfig.push({
id: 'smoke_tests',
label: 'Enable Smoke Tests',
tooltip: 'Enable Smoke Tests',
});

QUnit.config.urlConfig.push({
id: 'ci',
label: 'Enable CI Mode',
tooltip: 'CI mode makes tests run faster by sacrificing UI responsiveness',
testing.begin(() => {
if (testing.config.ci) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const tap = qunitLib.reporters.tap;
tap.init(runner, { log: console.info });
}
});

await Promise.resolve();
Expand All @@ -34,7 +68,7 @@ export async function setupQunit() {

console.log(`[HARNESS] ci=${hasFlag('ci')}`);

QUnit.testStart(() => {
testing.testStart(() => {
debug.resetTrackingTransaction?.();
});

Expand All @@ -52,44 +86,94 @@ export async function setupQunit() {
});

let start = performance.now();
qunit.testDone(async () => {
qunitLib.testDone(async () => {
let gap = performance.now() - start;
if (gap > 200) {
await pause();
start = performance.now();
}
});

qunit.moduleDone(pause);
qunitLib.moduleDone(pause);
}

// @ts-expect-error missing in types, does exist: https://api.qunitjs.com/callbacks/QUnit.on/#the-testend-event
QUnit.on('testEnd', (testEnd) => {
if (testEnd.status === 'failed') {
testEnd.errors.forEach((assertion: any) => {
console.error(assertion.stack);
// message: speedometer
// actual: 75
// expected: 88
// stack: at dmc.test.js:12
});
}
});

qunit.done(({ failed }) => {
if (failed > 0) {
console.log('[HARNESS] fail');
} else {
console.log('[HARNESS] done');
}
qunitLib.done(() => {
console.log('[HARNESS] done');
});

return {
smokeTest: hasFlag('smoke_test'),
};
}

class Testing<Q extends typeof QUnit> {
static withConfig<const C extends readonly UrlConfig[]>(...configs: C): Testing<WithConfig<C>> {
return new Testing(withConfig(...configs));
}

readonly #qunit: Q;

constructor(qunit: Q) {
this.#qunit = qunit;
}

get config(): Q['config'] {
return this.#qunit.config;
}

readonly begin = (begin: (details: QUnit.BeginDetails) => void | Promise<void>): void => {
this.#qunit.begin(begin);
};

readonly testStart = (
callback: (details: QUnit.TestStartDetails) => void | Promise<void>
): void => {
this.#qunit.testStart(callback);
};
}

function hasFlag(flag: string): boolean {
return hasSpecificFlag(flag);
}

function hasSpecificFlag(flag: string): boolean {
let location = typeof window !== 'undefined' && window.location;
return location && new RegExp(`[?&]${flag}`).test(location.search);
}

// eslint-disable-next-line unused-imports/no-unused-vars
function getSpecificFlag(flag: string): string | undefined {
let location = typeof window !== 'undefined' && window.location;
if (!location) {
return undefined;
}

const matches = new RegExp(`[?&]${flag}=([^&]*)`).exec(location.search);
return matches ? matches[1] : undefined;
}

interface UrlConfig {
id: string;
label?: string | undefined;
tooltip?: string | undefined;
value?: string | string[] | { [key: string]: string } | undefined;
}

type WithConfig<C extends readonly UrlConfig[]> = typeof QUnit & {
config: QUnit['config'] & {
[P in C[number]['id']]: string | undefined;
};
};

function withConfig<const C extends readonly UrlConfig[]>(...configs: C): Expand<WithConfig<C>> {
for (let config of configs) {
QUnit.config.urlConfig.push(config);
}

const index = QUnit.config.urlConfig.findIndex((c) => c.id === 'noglobals');
if (index !== -1) {
QUnit.config.urlConfig.splice(index, 1);
}

return QUnit as any;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Nullable, SimpleElement, SimpleNode } from '@glimmer/interfaces';
import type { EndTag, Token } from 'simple-html-tokenizer';
import { COMMENT_NODE, TEXT_NODE } from '@glimmer/constants';
import { castToSimple, unwrap } from '@glimmer/debug-util';
import { COMMENT_NODE, TEXT_NODE } from '@glimmer/util';
import { tokenize } from 'simple-html-tokenizer';

import { replaceHTML, toInnerHTML } from './dom/simple-utils';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { SimpleElement } from '@glimmer/interfaces';
import { NS_SVG } from '@glimmer/constants';
import { castToBrowser, checkNode, unwrap } from '@glimmer/debug-util';
import { NS_SVG, strip } from '@glimmer/util';
import { strip } from '@glimmer/util';

import { assertNodeTagName } from '../dom/assertions';
import { firstElementChild, getElementsByTagName } from '../dom/simple-utils';
Expand Down
1 change: 1 addition & 0 deletions packages/@glimmer-workspace/integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"simple-html-tokenizer": "^0.5.11"
},
"devDependencies": {
"@glimmer/constants": "workspace:*",
"@glimmer/debug-util": "workspace:*",
"@glimmer/local-debug-flags": "workspace:*",
"@types/js-reporters": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { SimpleElement } from '@glimmer/interfaces';
import { NS_SVG } from '@glimmer/constants';
import { castToBrowser, expect } from '@glimmer/debug-util';
import { normalizeProperty } from '@glimmer/runtime';
import { NS_SVG } from '@glimmer/util';

import { assertingElement, hasAttribute, jitSuite, RenderTest, test, tracked } from '..';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Dict, Nullable, SimpleElement } from '@glimmer/interfaces';
import { COMMENT_NODE, ELEMENT_NODE } from '@glimmer/constants';
import { castToBrowser, castToSimple, expect } from '@glimmer/debug-util';
import { COMMENT_NODE, ELEMENT_NODE, isObject, LOCAL_LOGGER } from '@glimmer/util';
import { isObject, LOCAL_LOGGER } from '@glimmer/util';

import type { ComponentBlueprint, Content } from '..';

Expand Down Expand Up @@ -101,7 +102,7 @@ abstract class AbstractChaosMonkeyTest extends RenderTest {
}

if (shouldLog) {
LOCAL_LOGGER.log(
LOCAL_LOGGER.debug(
`${removedNodeDisplay} was removed;\noriginal: ${original}\nupdated: ${element.innerHTML}`
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { SimpleElement, SimpleNode } from '@glimmer/interfaces';
import type { SafeString } from '@glimmer/runtime';
import { NS_SVG } from '@glimmer/util';
import { NS_SVG } from '@glimmer/constants';

import type { RenderTestConstructor } from '..';
import type RenderDelegate from '../lib/render-delegate';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { SimpleElement } from '@glimmer/interfaces';
import { NS_HTML, NS_SVG, NS_XLINK } from '@glimmer/util';
import { NS_HTML, NS_SVG, NS_XLINK } from '@glimmer/constants';

import { assertNodeTagName, jitSuite, RenderTest, test } from '..';
import { assert } from './support';
Expand Down
2 changes: 1 addition & 1 deletion packages/@glimmer/compiler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export {
s,
unicode,
} from './lib/builder/builder';
export { Builder, type BuilderStatement } from './lib/builder/builder-interface';
export { type BuilderStatement } from './lib/builder/builder-interface';
export { defaultId, precompile, precompileJSON, type PrecompileOptions } from './lib/compiler';

// exported only for tests!
Expand Down
Loading
Loading