2024-03-05 14:23:26 +01:00
|
|
|
|
import path from 'path'
|
|
|
|
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
|
|
import { relative, wordWrap } from './renderer'
|
2024-07-29 16:50:06 +02:00
|
|
|
|
import { normalizeWindowsSeperators } from './test-helpers'
|
2024-03-05 14:23:26 +01:00
|
|
|
|
|
|
|
|
|
|
describe('relative', () => {
|
|
|
|
|
|
it('should print an absolute path relative to the current working directory', () => {
|
2024-07-29 16:50:06 +02:00
|
|
|
|
expect(normalizeWindowsSeperators(relative(path.resolve('index.css')))).toMatchInlineSnapshot(
|
|
|
|
|
|
`"./index.css"`,
|
|
|
|
|
|
)
|
2024-03-05 14:23:26 +01:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
it('should prefer the shortest value by default', () => {
|
|
|
|
|
|
// Shortest between absolute and relative paths
|
2024-07-29 16:50:06 +02:00
|
|
|
|
expect(normalizeWindowsSeperators(relative('index.css'))).toMatchInlineSnapshot(`"index.css"`)
|
2024-03-05 14:23:26 +01:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
it('should be possible to override the current working directory', () => {
|
2024-07-29 16:50:06 +02:00
|
|
|
|
expect(normalizeWindowsSeperators(relative('../utils/index.css', '..'))).toMatchInlineSnapshot(
|
|
|
|
|
|
`"./utils/index.css"`,
|
|
|
|
|
|
)
|
2024-03-05 14:23:26 +01:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
it('should be possible to always prefer the relative path', () => {
|
|
|
|
|
|
expect(
|
2024-07-29 16:50:06 +02:00
|
|
|
|
normalizeWindowsSeperators(
|
|
|
|
|
|
relative('index.css', process.cwd(), { preferAbsoluteIfShorter: false }),
|
|
|
|
|
|
),
|
2024-03-05 14:23:26 +01:00
|
|
|
|
).toMatchInlineSnapshot(`"./index.css"`)
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
describe('word wrap', () => {
|
|
|
|
|
|
it('should wrap a sentence', () => {
|
|
|
|
|
|
expect(wordWrap('The quick brown fox jumps over the lazy dog', 10)).toMatchInlineSnapshot(`
|
|
|
|
|
|
[
|
|
|
|
|
|
"The quick",
|
|
|
|
|
|
"brown fox",
|
|
|
|
|
|
"jumps over",
|
|
|
|
|
|
"the lazy",
|
|
|
|
|
|
"dog",
|
|
|
|
|
|
]
|
|
|
|
|
|
`)
|
|
|
|
|
|
expect(wordWrap('The quick brown fox jumps over the lazy dog', 30)).toMatchInlineSnapshot(`
|
|
|
|
|
|
[
|
|
|
|
|
|
"The quick brown fox jumps over",
|
|
|
|
|
|
"the lazy dog",
|
|
|
|
|
|
]
|
|
|
|
|
|
`)
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
it('should wrap a sentence with ANSI escape codes', () => {
|
|
|
|
|
|
// The ANSI escape codes are not counted in the length, but they should
|
|
|
|
|
|
// still be rendered correctly.
|
|
|
|
|
|
expect(
|
|
|
|
|
|
wordWrap(
|
|
|
|
|
|
'\x1B[31mThe\x1B[39m \x1B[32mquick\x1B[39m \x1B[34mbrown\x1B[39m \x1B[35mfox\x1B[39m jumps over the lazy dog',
|
|
|
|
|
|
10,
|
|
|
|
|
|
),
|
|
|
|
|
|
).toMatchInlineSnapshot(`
|
|
|
|
|
|
[
|
|
|
|
|
|
"[31mThe[39m [32mquick[39m",
|
|
|
|
|
|
"[34mbrown[39m [35mfox[39m",
|
|
|
|
|
|
"jumps over",
|
|
|
|
|
|
"the lazy",
|
|
|
|
|
|
"dog",
|
|
|
|
|
|
]
|
|
|
|
|
|
`)
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|