Skip to content

Commit

Permalink
Bump dev deps, use @typescript-eslint type checked style preset (#4313)
Browse files Browse the repository at this point in the history
  • Loading branch information
fb55 authored Dec 23, 2024
1 parent 3c10048 commit 5f4e84b
Show file tree
Hide file tree
Showing 18 changed files with 262 additions and 243 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@
"extends": [
"plugin:expect-type/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-type-checked",
"plugin:@typescript-eslint/stylistic-type-checked",
"prettier"
],
"parserOptions": {
Expand Down
33 changes: 17 additions & 16 deletions benchmark/benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ const benchmarkFilter = filterIndex >= 0 ? process.argv[filterIndex] : '';

const cheerioOnly = process.argv.includes('--cheerio-only');

interface SuiteOptions<T> {
test($: CheerioAPI, data: T): void;
setup($: CheerioAPI): T;
}
type SuiteOptions<T> = T extends void
? {
test(this: void, $: CheerioAPI): void;
setup?: (this: void, $: CheerioAPI) => T;
}
: {
test(this: void, $: CheerioAPI, data: T): void;
setup(this: void, $: CheerioAPI): T;
};

async function benchmark<T>(
async function benchmark<T = void>(
name: string,
fileName: string,
options: SuiteOptions<T>,
Expand All @@ -40,7 +45,7 @@ async function benchmark<T>(

// Add Cheerio test
const $ = load(markup);
const setupData: T = setup($);
const setupData = setup?.($) as T;

bench.add('cheerio', () => {
test($, setupData);
Expand All @@ -52,23 +57,20 @@ async function benchmark<T>(

jQueryScript.runInContext(dom.getInternalVMContext());

const setupData: T = setup(dom.window['$']);
const setupData = setup?.(dom.window['$'] as CheerioAPI) as T;

bench.add('jsdom', () => test(dom.window['$'], setupData));
bench.add('jsdom', () => test(dom.window['$'] as CheerioAPI, setupData));
}

await bench.warmup(); // Make results more reliable, ref: https://github.com/tinylibs/tinybench/pull/50
await bench.run();

console.table(bench.table());
}

await benchmark<void>('Select all', 'jquery.html', {
setup() {},
await benchmark('Select all', 'jquery.html', {
test: ($) => $('*').length,
});
await benchmark<void>('Select some', 'jquery.html', {
setup() {},
await benchmark('Select some', 'jquery.html', {
test: ($) => $('li').length,
});

Expand Down Expand Up @@ -116,7 +118,7 @@ await benchmark<Cheerio<Element>>('manipulation - remove', 'jquery.html', {
},
});

await benchmark<void>('manipulation - replaceWith', 'jquery.html', {
await benchmark('manipulation - replaceWith', 'jquery.html', {
setup($) {
$('body').append('<div id="foo">');
},
Expand Down Expand Up @@ -147,8 +149,7 @@ await benchmark<Cheerio<Element>>('manipulation - html render', 'jquery.html', {

const HTML_INDEPENDENT_MARKUP =
'<div class="foo"><div id="bar">bat<hr>baz</div> </div>'.repeat(6);
await benchmark<void>('manipulation - html independent', 'jquery.html', {
setup() {},
await benchmark('manipulation - html independent', 'jquery.html', {
test: ($) => $(HTML_INDEPENDENT_MARKUP).html(),
});
await benchmark<Cheerio<Element>>('manipulation - text', 'jquery.html', {
Expand Down
Loading

0 comments on commit 5f4e84b

Please sign in to comment.