Skip to content

Commit eb3141a

Browse files
author
Adam Plesnik
committed
First version of tests
1 parent 721cd43 commit eb3141a

File tree

4 files changed

+77
-3
lines changed

4 files changed

+77
-3
lines changed

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"author": "Adam Plesnik <adam@adamplesnik.com>",
55
"scripts": {
66
"dev-docs": "npm run --workspace=docs dev",
7-
"build": "swc ./src/index.ts --out-dir ./dist"
7+
"build": "swc ./src/index.ts --out-dir ./dist",
8+
"test": "vitest"
89
},
910
"workspaces": [
1011
"docs"
@@ -21,10 +22,12 @@
2122
"devDependencies": {
2223
"@swc/cli": "^0.3.10",
2324
"@swc/core": "^1.4.11",
25+
"@types/jest": "^29.5.12",
2426
"prettier": "^3.2.5",
2527
"swcify": "^1.0.1",
2628
"tailwindcss": "^0.0.0-insiders.3ba51d1",
27-
"typescript": "^5.4.3"
29+
"typescript": "^5.4.3",
30+
"vitest": "^1.5.0"
2831
},
2932
"description": "A plugin for Tailwind CSS v3.4+ that provides utilities for scroll-driven animations.",
3033
"files": [

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import plugin from 'tailwindcss/plugin'
22

33
export = plugin(
4-
function ({ matchUtilities, addVariant, theme }) {
4+
function scrollDrivenAnimations({ matchUtilities, addVariant, theme }) {
55
matchUtilities(
66
{
77
timeline: (value, { modifier }) => ({

tests/index.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { expect, test } from 'vitest'
2+
import { css, html, run } from './utils'
3+
4+
test('Test', async () => {
5+
let config = {
6+
content: [
7+
{
8+
raw: html`
9+
<div>
10+
<div class="timeline"></div>
11+
<div class="timeline-auto"></div>
12+
<div class="timeline-none"></div>
13+
<div class="timeline-scroll-x"></div>
14+
<div class="timeline-view"></div>
15+
<div class="timeline/test"></div>
16+
</div>
17+
`,
18+
},
19+
],
20+
theme: {},
21+
corePlugins: { preflight: false },
22+
}
23+
24+
let input = `
25+
@tailwind utilities;
26+
`
27+
28+
const result = await run(input, config)
29+
expect(result.css).toMatch(css`
30+
.timeline {
31+
animation-timeline: scroll(y);
32+
}
33+
.timeline-auto {
34+
animation-timeline: auto;
35+
}
36+
.timeline-none {
37+
animation-timeline: none;
38+
}
39+
.timeline-scroll-x {
40+
animation-timeline: scroll(x);
41+
}
42+
.timeline-view {
43+
animation-timeline: view();
44+
}
45+
.timeline\/test {
46+
animation-timeline: --test;
47+
}
48+
`)
49+
})

tests/utils.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import path from 'path'
2+
import postcss from 'postcss'
3+
import tailwind, { Config } from 'tailwindcss'
4+
import { expect } from 'vitest'
5+
import scrollDrivenAnimations from '../src/index'
6+
7+
export let css = String.raw
8+
export let html = String.raw
9+
export let javascript = String.raw
10+
11+
export function run(input: string, config: Config, plugin = tailwind) {
12+
let { currentTestName } = expect.getState()
13+
14+
config.plugins ??= []
15+
if (!config.plugins.includes(scrollDrivenAnimations)) {
16+
config.plugins.push(scrollDrivenAnimations)
17+
}
18+
19+
return postcss(plugin(config)).process(input, {
20+
from: `${path.resolve(__filename)}?test=${currentTestName}`,
21+
})
22+
}

0 commit comments

Comments
 (0)