Skip to content

Commit

Permalink
chore: house keeping
Browse files Browse the repository at this point in the history
  • Loading branch information
nonzzz committed Dec 6, 2024
1 parent 8b5d106 commit 04874d9
Show file tree
Hide file tree
Showing 12 changed files with 487 additions and 2,064 deletions.
5 changes: 3 additions & 2 deletions __tests__/compress.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { InputType } from 'zlib'
import { expect, test } from 'vitest'
import type { InputType } from 'zlib'
import { compress, ensureAlgorithm } from '../src/compress'
import type { Algorithm } from '../src/interface'

Expand All @@ -9,7 +9,8 @@ const mockCompress = async (userAlgorithm: Algorithm, buf: InputType) => {
}

test('compress with error', async () => {
expect(mockCompress('gzip', 123 as any)).rejects.toThrowError(
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
await expect(mockCompress('gzip', 123 as any)).rejects.toThrowError(
'The "chunk" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received type number (123)'
)
})
2 changes: 1 addition & 1 deletion __tests__/fixtures/dynamic/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import './style.css'

import('./code').then(({ result }) => {
console.log(result)
})
}).catch(console.error)
31 changes: 2 additions & 29 deletions dprint.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,4 @@
{
"typescript": {
"semiColons": "asi",
"indentWidth": 2,
"quoteStyle": "preferSingle",
"useTabs": false,
"trailingCommas": "never",
"module.sortImportDeclarations": "maintain",
"importDeclaration.sortNamedImports": "maintain",
"operatorPosition": "maintain",
"functionDeclaration.spaceBeforeParentheses": false
},
"json": {
},
"markdown": {
},
"toml": {
},
"excludes": [
"**/node_modules",
"**/*-lock.json",
"pnpm-lock.yaml"
],
"plugins": [
"https://plugins.dprint.dev/typescript-0.91.1.wasm",
"https://plugins.dprint.dev/json-0.19.3.wasm",
"https://plugins.dprint.dev/markdown-0.17.1.wasm",
"https://plugins.dprint.dev/toml-0.6.2.wasm",
"https://plugins.dprint.dev/g-plane/pretty_yaml-v0.5.0.wasm"
]
"lineWidth": 140,
"extends": "https://dprint.nonzzz.moe/dprint.json"
}
25 changes: 12 additions & 13 deletions e2e/e2e.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import path from 'path'
import http from 'http'
import { expect, test } from 'vitest'
import sirv from 'sirv'
import path from 'path'
import { chromium } from 'playwright'
import type { Page } from 'playwright'
import sirv from 'sirv'
import { expect, test } from 'vitest'
import { compression } from '../src'

import type { Vite2Instance } from './vite2/interface'
import type { Vite3Instance } from './vite3/interface'
import type { Vite4Instance } from './vite4/interface'
import type { Vite5Instance } from './vite5/interface'
import type { Vite6Instance } from './vite6/interface'

type ViteInstance = Vite2Instance | Vite3Instance | Vite4Instance | Vite5Instance | Vite6Instance
type ViteInstance = Vite2Instance | Vite3Instance | Vite4Instance | Vite5Instance

type Server = http.Server & {
ip: string
Expand Down Expand Up @@ -40,7 +39,7 @@ function prepareAssets(taskName: string, options: TestOptions) {
outDir: path.join(defaultWd, 'dist', taskName)
},
logLevel: 'silent',
plugins: [compression({ ...compressOption, include: [/\.(js)$/, /\.(css)$/] }) as any]
plugins: [compression({ ...compressOption, include: [/\.(js)$/, /\.(css)$/] })]
})
}

Expand All @@ -49,7 +48,7 @@ function createServer(taskName: string) {
const publicPath = path.join(defaultWd, 'dist', taskName)
const assets = sirv(publicPath, { gzip: true })

const handleRequest = async (req: http.IncomingMessage, res: http.ServerResponse) => {
const handleRequest = (req: http.IncomingMessage, res: http.ServerResponse) => {
assets(req, res, () => {
res.statusCode = 404
res.end(`404 Not Found: ${req.url}`)
Expand All @@ -58,7 +57,7 @@ function createServer(taskName: string) {
server.on('request', handleRequest)
createGetter(server, 'ip', () => {
const address = server.address()
if (typeof address === 'string') return address
if (typeof address === 'string') { return address }
return `http://127.0.0.1:${address.port}`
})
server.listen(0)
Expand All @@ -69,12 +68,12 @@ async function createChromeBrowser(server: Server) {
const browser = await chromium.launch()
const page = await browser.newPage()
const localUrl = server.ip
page.goto(localUrl)
await page.goto(localUrl)

return { page }
}

async function expectTestCase(taskName: string, page: Awaited<Page>) {
function expectTestCase(taskName: string, page: Awaited<Page>) {
const expect1 = new Promise((resolve) => {
page.on('console', (message) => resolve(message.text()))
})
Expand All @@ -88,12 +87,12 @@ async function expectTestCase(taskName: string, page: Awaited<Page>) {
})

test(`${taskName} page first load`, async () => {
expect(expect1).resolves.toBe('load main process')
await expect(expect1).resolves.toBe('load main process')
})
test(`${taskName} insert line`, async () => {
await page.click('.button--insert')
await page.waitForSelector('text=p-1', { timeout: 5000 })
expect(expect2).resolves.toBe('append child')
await expect(expect2).resolves.toBe('append child')
})
}

Expand All @@ -102,5 +101,5 @@ export async function runTest(taskName: string, options: TestOptions) {
await new Promise((resolve) => setTimeout(resolve, 5000))
const { server } = createServer(taskName)
const { page } = await createChromeBrowser(server)
await expectTestCase(taskName, page)
expectTestCase(taskName, page)
}
4 changes: 2 additions & 2 deletions e2e/fixture/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import './theme.css'

const insertButton = document.querySelector('.button--insert') as HTMLButtonElement
const insertButton = document.querySelector('.button--insert')

insertButton.addEventListener('click', () => {
import('./dynamic').then((module) => module.insertChildToLines())
import('./dynamic').then((module) => module.insertChildToLines()).catch(console.error)
console.log('append child')
})

Expand Down
9 changes: 8 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
const { nonzzz } = require('eslint-config-kagura')

module.exports = nonzzz({ ts: true }, { ignores: ['dist', 'node_modules'] })
module.exports = nonzzz({ typescript: true }, {
ignores: [
'**/node_modules',
'**/dist',
'**/components.d.ts',
'**/analysis'
]
})
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
"@types/node": "^20.14.9",
"@vitest/coverage-v8": "^2.0.3",
"dprint": "^0.46.3",
"eslint": "^8.57.0",
"eslint-config-kagura": "^2.1.1",
"jiek": "^1.1.3",
"eslint": "^9.16.0",
"eslint-config-kagura": "^3.0.1",
"jiek": "^1.0.14",
"memdisk": "^1.2.1",
"playwright": "^1.32.3",
"sirv": "^2.0.3",
Expand Down
Loading

0 comments on commit 04874d9

Please sign in to comment.