Skip to content

Commit c0c5040

Browse files
committed
Convert tests to typescript
1 parent b2c8574 commit c0c5040

File tree

4 files changed

+31
-9
lines changed

4 files changed

+31
-9
lines changed
File renamed without changes.

tests/format.test.js renamed to tests/format.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { describe, test } from 'vitest'
2+
import type { TestEntry } from './utils.js'
23
import { format, no, t, yes } from './utils.js'
34

4-
let html = [
5+
let html: TestEntry[] = [
56
t`<div class="${yes}"></div>`,
67
t`<!-- <div class="${no}"></div> -->`,
78
t`<div class="${no} {{ 'p-0 sm:p-0 m-0' }}"></div>`,
@@ -26,7 +27,7 @@ let html = [
2627
],
2728
]
2829

29-
let css = [
30+
let css: TestEntry[] = [
3031
t`@apply ${yes};`,
3132
t`/* @apply ${no}; */`,
3233
t`@not-apply ${no};`,
@@ -37,7 +38,7 @@ let css = [
3738
],
3839
]
3940

40-
let javascript = [
41+
let javascript: TestEntry[] = [
4142
t`;<div class="${yes}" />`,
4243
t`;<div ns:class="${no}" />`,
4344
t`/* <div class="${no}" /> */`,
@@ -112,7 +113,7 @@ javascript = javascript.concat(
112113
]),
113114
)
114115

115-
let vue = [
116+
let vue: TestEntry[] = [
116117
...html,
117118
t`<div :class="'${yes}'"></div>`,
118119
t`<!-- <div :class="'${no}'"></div> -->`,
@@ -158,7 +159,7 @@ let vue = [
158159
],
159160
]
160161

161-
let glimmer = [
162+
let glimmer: TestEntry[] = [
162163
t`<div class='${yes}'></div>`,
163164
t`<!-- <div class='${no}'></div> -->`,
164165
t`<div class='${yes} {{"${yes}"}}'></div>`,
@@ -200,7 +201,7 @@ let glimmer = [
200201
],
201202
]
202203

203-
let tests = {
204+
let tests: Record<string, TestEntry[]> = {
204205
html,
205206
glimmer,
206207
lwc: html,

tests/plugins.test.js renamed to tests/plugins.test.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
import { createRequire } from 'node:module'
22
import { test } from 'vitest'
3+
import type { TestEntry } from './utils.js'
34
import { format, no, pluginPath, t, yes } from './utils.js'
45

56
const require = createRequire(import.meta.url)
67

7-
let tests = [
8+
interface PluginTest {
9+
versions: number[]
10+
plugins: string[]
11+
options?: Record<string, any>
12+
tests: Record<string, TestEntry[]>
13+
}
14+
15+
let tests: PluginTest[] = [
816
{
917
versions: [2, 3],
1018
plugins: ['@trivago/prettier-plugin-sort-imports'],
@@ -479,6 +487,7 @@ for (const group of tests) {
479487
// Hide logs from Pug's prettier plugin
480488
if (parser === 'pug') {
481489
let pug = await import('@prettier/plugin-pug')
490+
// @ts-ignore
482491
pug.logger.level = 'off'
483492
}
484493

tests/utils.js renamed to tests/utils.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,19 @@ let testClassNameSorted = 'p-0 sm:p-0'
1111
export let yes = '__YES__'
1212
export let no = '__NO__'
1313

14-
export function t(strings, ...values) {
14+
export type TestEntry = [
15+
input: string,
16+
output: string,
17+
options?: {
18+
tailwindPreserveWhitespace?: boolean
19+
tailwindPreserveDuplicates?: boolean
20+
},
21+
]
22+
23+
export function t(
24+
strings: TemplateStringsArray,
25+
...values: string[]
26+
): TestEntry {
1527
let input = ''
1628
strings.forEach((string, i) => {
1729
input += string + (values[i] ? testClassName : '')
@@ -30,7 +42,7 @@ export function t(strings, ...values) {
3042

3143
export let pluginPath = path.resolve(__dirname, '../dist/index.mjs')
3244

33-
export async function format(str, options = {}) {
45+
export async function format(str: string, options: prettier.Options = {}) {
3446
let result = await prettier.format(str, {
3547
pluginSearchDirs: [__dirname], // disable plugin autoload
3648
semi: false,

0 commit comments

Comments
 (0)