/
githubmirror
/
tailwindcss
Обзор
Документация
Войти
/
githubmirror
/
tailwindcss
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/@tailwindcss-upgrade/src/utils/args.test.ts
123 строки
3 KB
Robin Malfait
Add initial codemod tooling (#14434)
18 сен 2024, 17:45
Не верифицирован
18 сен 2024, 17:45
ee7e02b
Код
Авторство
О чём код?
import { expect, it } from 'vitest' import { args, type Arg } from './args' it('should be possible to parse a single argument', () => { expect( args( { '--input': { type: 'string', description: 'Input file' }, }, ['--input', 'input.css'], ), ).toMatchInlineSnapshot(` { "--input": "input.css", "_": [], } `) }) it('should fallback to the default value if no flag is passed', () => { expect( args( { '--input': { type: 'string', description: 'Input file', default: 'input.css' }, }, ['--other'], ), ).toMatchInlineSnapshot(` { "--input": "input.css", "_": [], } `) }) it('should fallback to null if no flag is passed and no default value is provided', () => { expect( args( { '--input': { type: 'string', description: 'Input file' }, }, ['--other'], ), ).toMatchInlineSnapshot(` { "--input": null, "_": [], } `) }) it('should be possible to parse a single argument using the shorthand alias', () => { expect( args( { '--input': { type: 'string', description: 'Input file', alias: '-i' }, }, ['-i', 'input.css'], ), ).toMatchInlineSnapshot(` { "--input": "input.css", "_": [], } `) }) it('should convert the incoming value to the correct type', () => { expect( args( { '--input': { type: 'string', description: 'Input file' }, '--watch': { type: 'boolean', description: 'Watch mode' }, '--retries': { type: 'number', description: 'Amount of retries' }, }, ['--input', 'input.css', '--watch', '--retries', '3'], ), ).toMatchInlineSnapshot(` { "--input": "input.css", "--retries": 3, "--watch": true, "_": [], } `) }) it('should be possible to provide multiple types, and convert the value to that type', () => { let options = { '--retries': { type: 'boolean | number | string', description: 'Retries' }, } satisfies Arg expect(args(options, ['--retries'])).toMatchInlineSnapshot(` { "--retries": true, "_": [], } `) expect(args(options, ['--retries', 'true'])).toMatchInlineSnapshot(` { "--retries": true, "_": [], } `) expect(args(options, ['--retries', 'false'])).toMatchInlineSnapshot(` { "--retries": false, "_": [], } `) expect(args(options, ['--retries', '5'])).toMatchInlineSnapshot(` { "--retries": 5, "_": [], } `) expect(args(options, ['--retries', 'indefinitely'])).toMatchInlineSnapshot(` { "--retries": "indefinitely", "_": [], } `) })