diff --git a/package.json b/package.json index 69e03173..41234757 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,6 @@ "fast-glob": "^3.2.7", "fast-json-stable-stringify": "^2.1.0", "fs-extra": "^11.1.0", - "jest-serializer-path": "^0.1.15", "klaw": "^4.0.1", "lint-staged": "^11.0.0", "minimist": "^1.2.5", diff --git a/playground/serializers.ts b/playground/serializers.ts index fde6fb6f..43fa7c8b 100644 --- a/playground/serializers.ts +++ b/playground/serializers.ts @@ -1,41 +1,25 @@ -import os from 'os' +import type { SnapshotSerializer } from 'vitest' -const winNewLineReg = /\/r\/n/gim -const winSepReg = /\\/g - -function doesUseDoubleSlashAsPath(val: string) { - return val.includes('//vite-plugin-checker//') +function normalizePaths(val: string) { + return val + .replace(/\\/gim, '/') // replace slashes + .replace(/\/\//gim, '/') // replace slashes + .replace(/[a-zA-Z]:\//gim, '/') // Remove win32 drive letters, C:\ -> \ } -export const normalizeWindowsLogSerializer = { - print(val: string, serialize) { - let result = val - if (os.platform() === 'win32') { - result = result.replaceAll(winNewLineReg, '/n') - result = result.replaceAll(process.cwd().replace(winSepReg, '/'), '') +function createResult(val: string) { + const cwd = normalizePaths(process.cwd()) - if (doesUseDoubleSlashAsPath(result)) { - result = result.replaceAll( - `//a//vite-plugin-checker//vite-plugin-checker//playground-temp`, - '/playground-temp' - ) - result = result.split('//').join('/') - } - } + return normalizePaths(val) + .replaceAll(cwd, '') + .replace(/\/r\/n/gim, '/n') +} - return serialize(result) +export const normalizeLogSerializer: SnapshotSerializer = { + print(val: string, print) { + return print(createResult(val)) }, test(val) { - if (typeof val !== 'string') return false - - if ( - (os.platform() === 'win32' && - (val.includes(process.cwd().replace(winSepReg, '/')) || winNewLineReg.test(val))) || - doesUseDoubleSlashAsPath(val) - ) { - return true - } - - return false + return typeof val === 'string' && val && createResult(val) !== val }, } diff --git a/playground/vitestSetup.ts b/playground/vitestSetup.ts index b0bcfeb3..b71e4c45 100644 --- a/playground/vitestSetup.ts +++ b/playground/vitestSetup.ts @@ -1,6 +1,5 @@ import execa from 'execa' import fs from 'fs-extra' -import pathSerializer from 'jest-serializer-path' import type * as http from 'node:http' import os from 'node:os' import path, { dirname, join, resolve } from 'node:path' @@ -10,14 +9,13 @@ import { createServer, mergeConfig } from 'vite' import { beforeAll, expect } from 'vitest' import type { Checker } from 'vite-plugin-checker/dist/Checker' -import { normalizeWindowsLogSerializer } from './serializers' +import { normalizeLogSerializer } from './serializers' import type { Browser, Page } from 'playwright-chromium' import type { InlineConfig, ResolvedConfig, ViteDevServer } from 'vite' import type { File } from 'vitest' -expect.addSnapshotSerializer(pathSerializer) -expect.addSnapshotSerializer(normalizeWindowsLogSerializer) +expect.addSnapshotSerializer(normalizeLogSerializer) export const workspaceRoot = resolve(__dirname, '../') diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3017bc75..5155f2d7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -79,9 +79,6 @@ importers: fs-extra: specifier: ^11.1.0 version: 11.2.0 - jest-serializer-path: - specifier: ^0.1.15 - version: 0.1.15 klaw: specifier: ^4.0.1 version: 4.1.0 @@ -4128,10 +4125,6 @@ packages: resolution: {integrity: sha512-JVYhQnN59LVPFCEcVa2C3CrEKYacvjRfqIQl+h8oi91aLYQVWRYbxjPcv1bUiUy/kLmQaANrYfNMCO3kuEDHfw==} engines: {node: '>=14'} - jest-serializer-path@0.1.15: - resolution: {integrity: sha512-sXb+Ckz9LK5bB5sRAXFeG/nwhGn1XBKayy9xhPpgOmAWaljJiS+VN/xJ3P4I19jZ+WejowvO/kES+A9HePTMvQ==} - engines: {node: '>=6.4.x', npm: '>=3.10.3'} - joycon@3.1.1: resolution: {integrity: sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw==} engines: {node: '>=10'} @@ -4254,12 +4247,6 @@ packages: resolution: {integrity: sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==} engines: {node: '>=10'} - lodash.clonedeep@4.5.0: - resolution: {integrity: sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ==} - - lodash.iserror@3.1.1: - resolution: {integrity: sha512-eT/VeNns9hS7vAj1NKW/rRX6b+C3UX3/IAAqEE7aC4Oo2C0iD82NaP5IS4bSlQsammTii4qBJ8G1zd1LTL8hCw==} - lodash.kebabcase@4.1.1: resolution: {integrity: sha512-N8XRTIMMqqDgSy4VLKPnJ/+hpGZN+PHQiJnSenYqPaVV/NCqEogTnAdZLQiGKhxX+JCs8waWq2t1XHWKOmlY8g==} @@ -5054,10 +5041,6 @@ packages: sisteransi@1.0.5: resolution: {integrity: sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==} - slash@2.0.0: - resolution: {integrity: sha512-ZYKh3Wh2z1PpEXWr0MpSBZ0V6mZHAQfYevttO11c51CaWjGTaadiKZ+wVt1PbMlDV5qhMFslpZCemhwOK7C89A==} - engines: {node: '>=6'} - slash@3.0.0: resolution: {integrity: sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==} engines: {node: '>=8'} @@ -8987,12 +8970,6 @@ snapshots: optionalDependencies: '@pkgjs/parseargs': 0.11.0 - jest-serializer-path@0.1.15: - dependencies: - lodash.clonedeep: 4.5.0 - lodash.iserror: 3.1.1 - slash: 2.0.0 - joycon@3.1.1: {} js-tokens@4.0.0: {} @@ -9116,10 +9093,6 @@ snapshots: dependencies: p-locate: 5.0.0 - lodash.clonedeep@4.5.0: {} - - lodash.iserror@3.1.1: {} - lodash.kebabcase@4.1.1: {} lodash.merge@4.6.2: {} @@ -9893,8 +9866,6 @@ snapshots: sisteransi@1.0.5: {} - slash@2.0.0: {} - slash@3.0.0: {} slice-ansi@3.0.0: