Skip to content

Commit

Permalink
test: update win32 test serializer to work on any win32 machine
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 committed Apr 6, 2024
1 parent 0a2a2e0 commit d88ec57
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions playground/serializers.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import os from 'os'
import os from 'node:os'
import { resolve } from 'node:path'

const winPathReg = /(\/)?(\D:\/)?\D\/vite-plugin-checker\/vite-plugin-checker\/playground-temp/im
const winNewLineReg = /\/r\/n/gim

function doesUseDoubleSlashAsPath(val: string) {
return val.includes('//vite-plugin-checker//')
}

const workspaceRoot = resolve(__dirname, '../').replace(/\\/g, '/')

export const normalizeWindowsLogSerializer = {
print(val, serialize) {
let result = val
if (os.platform() === 'win32') {
result = result.replace(winNewLineReg, '/n')

if (winPathReg.test(result)) {
result = result.replace(winPathReg, '<PROJECT_ROOT>/playground-temp')
}
result = result.replace(workspaceRoot, '<PROJECT_ROOT>')

if (doesUseDoubleSlashAsPath(result)) {
result = result.replace(
Expand All @@ -32,7 +32,7 @@ export const normalizeWindowsLogSerializer = {
if (typeof val !== 'string') return false

if (
(os.platform() === 'win32' && (winPathReg.test(val) || winNewLineReg.test(val))) ||
(os.platform() === 'win32' && (val.includes(workspaceRoot) || winNewLineReg.test(val))) ||
doesUseDoubleSlashAsPath(val)
) {
return true
Expand Down

0 comments on commit d88ec57

Please sign in to comment.