Skip to content

Commit 98b7eb9

Browse files
committed
custom reporter
1 parent 1ddf4b7 commit 98b7eb9

File tree

6 files changed

+138
-125
lines changed

6 files changed

+138
-125
lines changed

‎classname.test.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,30 @@ describe('classname', () => {
137137
);
138138
});
139139

140+
test.todo('composite class', () => {
141+
assert.deepEqual(
142+
{ className: 'sr-only' },
143+
classname({
144+
responsiveModifier: null,
145+
pseudoModifier: null,
146+
property: 'composite',
147+
value: null,
148+
relatedProperties: {
149+
position: 'static',
150+
width: 'auto',
151+
height: 'auto',
152+
padding: '0',
153+
margin: '0',
154+
overflow: 'visible',
155+
clip: 'auto',
156+
whiteSpace: 'normal'
157+
}
158+
})
159+
);
160+
});
161+
140162
// todo: unhandled opacity
141-
test.todo('bg-red-200/50', () => {
163+
test.skip('bg-red-200/50', () => {
142164
assert.deepEqual(
143165
{ className: 'bg-red-200/50' },
144166
classname({

‎generated.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const isResponsive = (selector) => {
2525
};
2626

2727
const compositeClassNames = [
28-
'container',
28+
'container', // no clue what to do with this
2929
'sr-only',
3030
'not-sr-only',
3131
'transform',
@@ -60,7 +60,7 @@ const classNames = selectors
6060

6161
describe('generated suite', () => {
6262
// test.only('debug', async () => {
63-
// const originalClassName = 'accent-rose-800';
63+
// const originalClassName = 'sr-only';
6464
// const definition = parse(originalClassName);
6565
// console.log(definition);
6666
// const { className: generatedClassName, error } = classname(definition);

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"utils"
1212
],
1313
"scripts": {
14-
"test": "vitest",
14+
"test": "vitest --run --reporter='./reporter'",
1515
"test:generated": "vitest generated --no-isolate",
1616
"build:fixtures": "npx tailwindcss -i node_modules/tailwindcss/tailwind.css -o ./dist/output.css"
1717
},

‎parse.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ describe('parse', () => {
9595

9696
test('drop-shadow-md', () => {
9797
assert.deepEqual(parse('drop-shadow-md'), {
98-
className: 'drop-shadow-md',
98+
className: 'drop-shadow-m',
9999
responsiveModifier: null,
100100
pseudoModifier: null,
101101
property: 'dropShadow',

‎properties.ts

Lines changed: 2 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -2,126 +2,8 @@
22
// TODO: add negative value support as well
33
// TODO: keep color values, flatten them in theme
44
// TODO: standardise camelcase
5-
6-
/*
7-
this is probably a bad idea?
8-
9-
what properties are missing here that might be in the theme:
10-
"screens",
11-
"colors",
12-
"columns",
13-
"spacing",
14-
"animation",
15-
"aspectRatio",
16-
"backdropBlur",
17-
"backdropBrightness",
18-
"backdropContrast",
19-
"backdropGrayscale",
20-
"backdropHueRotate",
21-
"backdropInvert",
22-
"backdropOpacity",
23-
"backdropSaturate",
24-
"backdropSepia",
25-
"backgroundColor",
26-
"backgroundImage",
27-
"backgroundOpacity",
28-
"backgroundPosition",
29-
"backgroundSize",
30-
"blur",
31-
"brightness",
32-
"borderColor",
33-
"borderOpacity",
34-
"borderRadius",
35-
"borderSpacing",
36-
"borderWidth",
37-
"boxShadow",
38-
"boxShadowColor",
39-
"caretColor",
40-
"accentColor",
41-
"contrast",
42-
"container",
43-
"content",
44-
"cursor",
45-
"divideColor",
46-
"divideOpacity",
47-
"divideWidth",
48-
"dropShadow",
49-
"fill",
50-
"grayscale",
51-
"hueRotate",
52-
"invert",
53-
"flex",
54-
"flexBasis",
55-
"flexGrow",
56-
"flexShrink",
57-
"fontFamily",
58-
"fontSize",
59-
"fontWeight",
60-
"gap",
61-
"gradientColorStops",
62-
"gridAutoColumns",
63-
"gridAutoRows",
64-
"gridColumn",
65-
"gridColumnEnd",
66-
"gridColumnStart",
67-
"gridRow",
68-
"gridRowStart",
69-
"gridRowEnd",
70-
"gridTemplateColumns",
71-
"gridTemplateRows",
72-
"height",
73-
"inset",
74-
"keyframes",
75-
"letterSpacing",
76-
"lineHeight",
77-
"listStyleType",
78-
"margin",
79-
"maxHeight",
80-
"maxWidth",
81-
"minHeight",
82-
"minWidth",
83-
"objectPosition",
84-
"opacity",
85-
"order",
86-
"padding",
87-
"placeholderColor",
88-
"placeholderOpacity",
89-
"outlineColor",
90-
"outlineOffset",
91-
"outlineWidth",
92-
"ringColor",
93-
"ringOffsetColor",
94-
"ringOffsetWidth",
95-
"ringOpacity",
96-
"ringWidth",
97-
"rotate",
98-
"saturate",
99-
"scale",
100-
"scrollMargin",
101-
"scrollPadding",
102-
"sepia",
103-
"skew",
104-
"space",
105-
"stroke",
106-
"strokeWidth",
107-
"textColor",
108-
"textDecorationColor",
109-
"textDecorationThickness",
110-
"textUnderlineOffset",
111-
"textIndent",
112-
"textOpacity",
113-
"transformOrigin",
114-
"transitionDelay",
115-
"transitionDuration",
116-
"transitionProperty",
117-
"transitionTimingFunction",
118-
"translate",
119-
"width",
120-
"willChange",
121-
"zIndex"
122-
]
123-
124-
*/
5+
// TODO: some of these values are not single properties like paddingX
6+
// TODO: some of these values are not simple classname selectors like divideX
1257

1268
type Properties = {
1279
[key: string]: {

‎reporter.ts

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import chalk from 'chalk';
2+
import type { Reporter, TaskState, File } from 'vitest';
3+
4+
const StateMap: { [key in TaskState]: string } = {
5+
pass: chalk.green('▎'),
6+
fail: chalk.red('▎'),
7+
skip: chalk.yellow('▎'),
8+
todo: chalk.gray('▎'),
9+
run: '', // not in final result
10+
only: '' // probably never see this
11+
};
12+
13+
const printResults = (results) => {
14+
const name = results.name;
15+
16+
const printableResult = results.testResults.map((state: TaskState) => {
17+
return StateMap[state];
18+
});
19+
20+
const perLine = process.stdout.columns - 32 || 100;
21+
let resultLines: string[] = [];
22+
23+
if (results.testResults.length < perLine) {
24+
resultLines.push(`│ ${name}${printableResult.join('')}│`);
25+
} else {
26+
const totalRows = Math.ceil(printableResult.length / perLine);
27+
28+
// first line with name
29+
resultLines.push(`│ ${name}${printableResult.slice(0, perLine).join('')}│`);
30+
31+
// not the first and last row
32+
for (let i = 1; i < totalRows - 1; i++) {
33+
// blank line
34+
resultLines.push(`│ ${Array(name.length).fill(' ').join('')}${Array(perLine).fill(' ').join('')}│`);
35+
36+
resultLines.push(
37+
`│ ${Array(name.length).fill(' ').join('')}${printableResult
38+
.slice(i * perLine, i * perLine + perLine)
39+
.join('')}│`
40+
);
41+
}
42+
43+
// last line
44+
// blank line
45+
resultLines.push(`│ ${Array(name.length).fill(' ').join('')}${Array(perLine).fill(' ').join('')}│`);
46+
47+
// fill last line with spaces with extra spaces to make box
48+
resultLines.push(
49+
`│ ${Array(name.length).fill(' ').join('')}${printableResult
50+
.slice((totalRows - 1) * perLine, printableResult.length)
51+
.join('')} ${Array(perLine - 1 - (printableResult.length % perLine))
52+
.fill(' ')
53+
.join('')}│`
54+
);
55+
}
56+
57+
const header = `┌${Array(name.length + 2)
58+
.fill('─')
59+
.join('')}${Array(Math.min(printableResult.length, perLine) + 1)
60+
.fill('─')
61+
.join('')}┐`;
62+
63+
const footer = `└${Array(name.length + 2)
64+
.fill('─')
65+
.join('')}${Array(Math.min(printableResult.length, perLine) + 1)
66+
.fill('─')
67+
.join('')}┘`;
68+
69+
console.log(
70+
`
71+
${header}
72+
${resultLines.join('\n')}
73+
${footer}
74+
`.trim()
75+
);
76+
};
77+
78+
class reporter implements Reporter {
79+
// looks like collected is fired once per file
80+
async onCollected(files?: File[]) {
81+
// console.log('collected', files);
82+
}
83+
84+
async onFinished(files: File[] = [], errors?: unknown[]) {
85+
files.forEach((file) => {
86+
const results = {
87+
name: file.name,
88+
state: 'run',
89+
duration: 0,
90+
testResults: []
91+
};
92+
93+
results.state = file.result!.state; // 'pass' | 'fail' | 'run' | 'skip' | 'only' | 'todo'
94+
results.duration = file.result!.duration;
95+
96+
// each describe is it's own suite
97+
const suites = file.tasks;
98+
suites.forEach((suite) => {
99+
suite.tasks.forEach((task) => {
100+
if (task.mode !== 'run') results.testResults.push(task.mode);
101+
else results.testResults.push(task.result.state);
102+
});
103+
});
104+
printResults(results);
105+
});
106+
}
107+
}
108+
109+
export default reporter;

0 commit comments

Comments
 (0)