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

chore: set log level to error in benchmarks to reduce log noise #26

Merged
merged 1 commit into from
Oct 31, 2024
Merged
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
23 changes: 15 additions & 8 deletions packages/beasties/test/beasties.bench.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import type { Options } from '../src/types'
import fs from 'node:fs'

import { join } from 'node:path'
import { fileURLToPath } from 'node:url'

import { bench, describe } from 'vitest'
import Beasties from '../src/index'

const fixtureDir = fileURLToPath(new URL('./src', import.meta.url))

const DEFAULT_BEASTIES_CONFIG: Partial<Options> = {
reduceInlineStyles: false,
logLevel: 'error',
} as const

function trim(s: TemplateStringsArray) {
return s[0]!
.trim()
Expand All @@ -16,7 +22,7 @@ function trim(s: TemplateStringsArray) {
describe('beasties', () => {
bench('basic Usage', async () => {
const beasties = new Beasties({
reduceInlineStyles: false,
...DEFAULT_BEASTIES_CONFIG,
path: '/',
})
const assets: Record<string, string> = {
Expand Down Expand Up @@ -45,7 +51,7 @@ describe('beasties', () => {

bench('run on HTML file', async () => {
const beasties = new Beasties({
reduceInlineStyles: false,
...DEFAULT_BEASTIES_CONFIG,
path: fixtureDir,
})

Expand All @@ -54,7 +60,7 @@ describe('beasties', () => {

bench('does not encode HTML', async () => {
const beasties = new Beasties({
reduceInlineStyles: false,
...DEFAULT_BEASTIES_CONFIG,
path: '/',
})
const assets: Record<string, string> = {
Expand All @@ -78,7 +84,7 @@ describe('beasties', () => {

bench('should keep existing link tag attributes in the noscript link', async () => {
const beasties = new Beasties({
reduceInlineStyles: false,
...DEFAULT_BEASTIES_CONFIG,
path: '/',
preload: 'media',
})
Expand All @@ -103,7 +109,7 @@ describe('beasties', () => {

bench('should keep existing link tag attributes', async () => {
const beasties = new Beasties({
reduceInlineStyles: false,
...DEFAULT_BEASTIES_CONFIG,
path: '/',
})
const assets: Record<string, string> = {
Expand All @@ -127,6 +133,7 @@ describe('beasties', () => {

bench('does not decode entities in HTML document', async () => {
const beasties = new Beasties({
...DEFAULT_BEASTIES_CONFIG,
path: '/',
})
const assets: Record<string, string> = {
Expand All @@ -150,7 +157,7 @@ describe('beasties', () => {
const mediaValidationHtml = fs.readFileSync(join(fixtureDir, 'media-validation.html'), 'utf-8')
bench('prevent injection via media attr', async () => {
const beasties = new Beasties({
reduceInlineStyles: false,
...DEFAULT_BEASTIES_CONFIG,
path: fixtureDir,
preload: 'media',
})
Expand All @@ -161,7 +168,7 @@ describe('beasties', () => {
const invalidPathHtml = fs.readFileSync(join(fixtureDir, 'subpath-validation.html'), 'utf-8')
bench('skip invalid path', async () => {
const beasties = new Beasties({
reduceInlineStyles: false,
...DEFAULT_BEASTIES_CONFIG,
path: fixtureDir,
})

Expand Down