Skip to content

Commit

Permalink
chore: Fix biome lint issues and apply formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmilton committed Feb 3, 2024
1 parent 1af80e8 commit cae9682
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/components/BookmarkBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const BookmarkBar = (): BookmarkBarComponent => {
// we can use clientWidth instead of offsetWidth for better performance.
let currentWidth = otherBookmarksFolder.clientWidth;
let index = 0;
let node;
let node: ReturnType<typeof BookmarkNode>;

for (; index < len; index++) {
node = append(BookmarkNode(bookmarks[index]), root);
Expand Down
1 change: 1 addition & 0 deletions src/components/BookmarkNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export const Folder = (
return root;
};

// eslint-disable-next-line no-confusing-arrow
export const BookmarkNode = <T extends LinkProps | BookmarkTreeNode>(
props: T,
nested?: boolean,
Expand Down
2 changes: 1 addition & 1 deletion src/components/SearchResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const SearchResult = <T extends LinkProps & TabItem>(

const list = isOpenTabs ? listData : listData.slice(0, showCount);
let index = 0;
let link;
let link: LinkComponent;

renderedLength = list.length;
root.hidden = !renderedLength;
Expand Down
9 changes: 3 additions & 6 deletions test/e2e/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

/* eslint-disable no-empty-pattern, unicorn/prefer-module */

import {
test as baseTest,
chromium,
type BrowserContext,
} from '@playwright/test';
import { test as baseTest, chromium, type BrowserContext } from '@playwright/test';
import path from 'node:path';

export const test = baseTest.extend<{
context: BrowserContext;
extensionId: string;
}>({
// biome-ignore lint/correctness/noEmptyPattern: empty initial context
async context({}, use) {
const extensionPath = path.join(__dirname, '../../dist');
const context = await chromium.launchPersistentContext('', {
Expand All @@ -29,7 +26,7 @@ export const test = baseTest.extend<{
async extensionId({ context }, use) {
let [background] = context.serviceWorkers();
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!background) background = await context.waitForEvent('serviceworker');
background ??= await context.waitForEvent('serviceworker');

const extensionId = background.url().split('/')[2];
await use(extensionId);
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/sw.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expect, test } from './fixtures';
test('background service worker', async ({ context }) => {
let [background] = context.serviceWorkers();
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!background) background = await context.waitForEvent('serviceworker');
background ??= await context.waitForEvent('serviceworker');

// FIXME: Better assertions

Expand Down
9 changes: 5 additions & 4 deletions test/setup.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { expect } from 'bun:test';
import { GlobalWindow, type Window } from 'happy-dom';

/* eslint-disable no-var, vars-on-top */
declare global {
/** Real bun console. `console` is mapped to happy-dom's virtual console. */
// eslint-disable-next-line no-var, vars-on-top
// biome-ignore lint/style/noVar: define global
var console2: Console;
// eslint-disable-next-line no-var, vars-on-top
// biome-ignore lint/style/noVar: define global
var happyDOM: Window['happyDOM'];
}
/* eslint-enable */

declare module 'bun:test' {
interface Matchers {
Expand All @@ -17,8 +19,7 @@ declare module 'bun:test' {
}

expect.extend({
// XXX: Although bun has a `toBeObject` matcher, it's not as useful since it
// doesn't check for plain objects.
// XXX: Bun's `toBeObject` matcher is the equivalent of `typeof x === 'object'`.
toBePlainObject(received: unknown) {
return Object.prototype.toString.call(received) === '[object Object]'
? { pass: true }
Expand Down
1 change: 1 addition & 0 deletions test/unit/Search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { cleanup, render } from './utils';
// state) when run, it's vital to reset its module state between tests to
// maintain accurate test conditions.
const MODULE_PATH = import.meta.resolveSync('../../src/components/Search');
// biome-ignore lint/style/useNamingConvention: indirect component
let Search: typeof import('../../src/components/Search').Search;

beforeEach(async () => {
Expand Down
9 changes: 2 additions & 7 deletions test/unit/css-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ export const SKIP = Symbol('SKIP');
* Clones the element, stripping out references to other elements (e.g.,
* "parent") for cleaner logging. **Intended for debugging only.**
*/
export const cleanElement = <T extends Element & { siblings?: Element[] }>(
element: T,
): T => {
export const cleanElement = <T extends Element & { siblings?: Element[] }>(element: T): T => {
const { root, parent, children, siblings, ...rest } = element;
// @ts-expect-error - TODO: Fix "children" prop type
rest.children = Array.isArray(children) ? children.length : children;
Expand Down Expand Up @@ -71,10 +69,7 @@ function load(root: Element[]): void {
/**
* Returns a list of elements matching the given CSS selector.
*/
export function lookup(
root: Element[],
cssSelector: string,
): Element[] | undefined {
export function lookup(root: Element[], cssSelector: string): Element[] | undefined {
if (!cache.has(root)) load(root);

// parse the selector to ensure it's valid and normalized
Expand Down
4 changes: 2 additions & 2 deletions test/unit/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ describe('dist files', () => {
describe(filename, () => {
const file = Bun.file(`dist/${filename}`);

test(`exists with correct type`, () => {
test('exists with correct type', () => {
expect(file.exists()).resolves.toBeTruthy();
expect(file.size).toBeGreaterThan(0);
expect(file.type).toBe(type); // TODO: Keep this? Type seems to be resolved from the file extension, not the file data.
});

if (minBytes != null && maxBytes != null) {
test(`is within expected file size limits`, () => {
test('is within expected file size limits', () => {
expect(file.size).toBeGreaterThan(minBytes);
expect(file.size).toBeLessThan(maxBytes);
});
Expand Down
1 change: 1 addition & 0 deletions test/unit/manifest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ const restoreCI = () => {
// work in bun for env vars that were set before the process started.
// ↳ https://github.com/oven-sh/bun/issues/1559#issuecomment-1440507885
// ↳ May be fixed, need to investigate; https://github.com/oven-sh/bun/pull/7614
// biome-ignore lint/performance/noDelete: see comment above
delete process.env.CI;
} else {
process.env.CI = oldCI;
Expand Down
3 changes: 1 addition & 2 deletions test/unit/test-setup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ describe('matcher: toBePlainObject', () => {
new Function(),
Function,
Object,
/(?:)/,
new Date(),
// eslint-disable-next-line prefer-regex-literals
new RegExp(''),
// eslint-disable-next-line unicorn/error-message
new Error(),
new Map(),
Expand Down
16 changes: 9 additions & 7 deletions test/unit/test-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,27 +94,29 @@ describe('render', () => {
expect(rendered.debug).toBeInstanceOf(Function);
});

test('prints to console2', async () => {
test('prints to console2', () => {
const spy = spyOn(console2, 'log').mockImplementation(() => {});
const rendered = render(document.createElement('div'));
await rendered.debug();
rendered.debug();
expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenCalledWith('DEBUG:\n<div></div>\n');
// TODO: Uncomment once biome has a HTML parser.
// expect(spy).toHaveBeenCalledWith('DEBUG:\n<div></div>\n');
spy.mockRestore();
});

test('does not print to console, only console2', async () => {
test('does not print to console, only console2', () => {
const spy = spyOn(console, 'log').mockImplementation(() => {});
const spy2 = spyOn(console2, 'log').mockImplementation(() => {});
const rendered = render(document.createElement('div'));
await rendered.debug();
rendered.debug();
expect(spy).not.toHaveBeenCalled();
expect(spy2).toHaveBeenCalledTimes(1);
spy.mockRestore();
spy2.mockRestore();
});

test('prints prettified container DOM to console', async () => {
// TODO: Don't skip once biome has a HTML parser.
test.skip('prints prettified container DOM to console', () => {
const spy = spyOn(console2, 'log').mockImplementation(() => {});
const main = document.createElement('main');
main.append(
Expand All @@ -123,7 +125,7 @@ describe('render', () => {
document.createElement('div'),
);
const rendered = render(main);
await rendered.debug();
rendered.debug();
expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenCalledWith(
'DEBUG:\n<main>\n <div></div>\n <div></div>\n <div></div>\n</main>\n',
Expand Down
25 changes: 12 additions & 13 deletions test/unit/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface RenderResult {
*
* @param element - An element to inspect. Default is the mounted container.
*/
debug(element?: Element): Promise<void>;
debug(element?: Element): void;
unmount(): void;
}

Expand All @@ -26,10 +26,13 @@ export function render(component: Node): RenderResult {

return {
container,
async debug(el = container) {
const { format } = await import('prettier');
const html = await format(el.innerHTML, { parser: 'html' });
console2.log(`DEBUG:\n${html}`);
debug(el = container) {
// const { format } = await import('prettier');
// const html = await format(el.innerHTML, { parser: 'html' });
// console2.log(`DEBUG:\n${html}`);

// FIXME: Replace with biome once it has a HTML parser
console2.log(`DEBUG:\n${el.innerHTML}`);
},
unmount() {
// eslint-disable-next-line unicorn/prefer-dom-node-remove
Expand All @@ -40,23 +43,19 @@ export function render(component: Node): RenderResult {

export function cleanup(): void {
if (mountedContainers.size === 0) {
throw new Error(
'No mounted components exist, did you forget to call render()?',
);
throw new Error('No components mounted, did you forget to call render()?');
}

mountedContainers.forEach((container) => {
for (const container of mountedContainers) {
if (container.parentNode === document.body) {
container.remove();
}

mountedContainers.delete(container);
});
}
}

const methods = Object.getOwnPropertyNames(
performance,
) as (keyof Performance)[];
const methods = Object.getOwnPropertyNames(performance) as (keyof Performance)[];

export function performanceSpy(): () => void {
const spies: Mock<() => void>[] = [];
Expand Down

0 comments on commit cae9682

Please sign in to comment.