tailwindcss/packages/@tailwindcss-cli/src/utils/renderer.test.ts
Robin Malfait 0597489604
Move the CLI to its own package @tailwindcss/cli (#13095)
* move `cli` to its own package `@tailwindcss/cli`

* minify builds when using `tsup`

* prefer tsup cli flag over tsup.config.ts file

* add `--clean`, to make sure `dist/` folders are cleaned before building

* make CLI esm only

* use version of `tailwindcss` instead of the version of `@tailwindcss/cli`
2024-03-06 05:41:12 -05:00

63 lines
1.9 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import path from 'path'
import { describe, expect, it } from 'vitest'
import { relative, wordWrap } from './renderer'
describe('relative', () => {
it('should print an absolute path relative to the current working directory', () => {
expect(relative(path.resolve('index.css'))).toMatchInlineSnapshot(`"./index.css"`)
})
it('should prefer the shortest value by default', () => {
// Shortest between absolute and relative paths
expect(relative('index.css')).toMatchInlineSnapshot(`"index.css"`)
})
it('should be possible to override the current working directory', () => {
expect(relative('../utils/index.css', '..')).toMatchInlineSnapshot(`"./utils/index.css"`)
})
it('should be possible to always prefer the relative path', () => {
expect(
relative('index.css', process.cwd(), { preferAbsoluteIfShorter: false }),
).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(`
[
"The quick",
"brown fox",
"jumps over",
"the lazy",
"dog",
]
`)
})
})