Skip to content

Commit

Permalink
add legacy tailwind tests
Browse files Browse the repository at this point in the history
  • Loading branch information
heidkaemper committed Jan 27, 2025
1 parent 168936a commit 8e033dd
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 80 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: NPM Publish
name: Publish

on:
release:
Expand All @@ -13,6 +13,7 @@ jobs:
with:
node-version: '20.x'
- run: npm install
- run: npm install --prefix jest/legacy
- run: npm test

publish:
Expand Down
14 changes: 6 additions & 8 deletions .github/workflows/ci.yml → .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
name: CI
name: Tests

on: [push, pull_request]

jobs:
test:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x, 21.x]

node-version: [20.x, 22.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: yarn
- run: yarn lint
- run: yarn test
- run: npm install
- run: npm install --prefix jest/legacy
- run: npm run lint
- run: npm run test
144 changes: 73 additions & 71 deletions jest/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,84 +22,86 @@ async function run(file, options = {}) {
return result.css
}

it('generates `delay` utilities', async () => {
expect(await run('content/delay.html', { scope: 'utilities' })).toIncludeAll([
'.animate-delay-75 { animation-delay: 75ms; }',
'.animate-delay-333 { animation-delay: 333ms; }',
'.animate-delay-\\[666ms\\] { animation-delay: 666ms; }',
])
})
describe('modern tailwind', () => {
it('generates `composition` utilities', async () => {
expect(await run('content/composition.html', { scope: 'utilities' })).toIncludeAll([
'.animate-add { animation-composition: add; }',
'.animate-replace { animation-composition: replace; }',
'.animate-accumulate { animation-composition: accumulate; }',
])
})

it('generates `duration` utilities', async () => {
expect(await run('content/duration.html', { scope: 'utilities' })).toIncludeAll([
'.animate-duration-75 { animation-duration: 75ms; }',
'.animate-duration-333 { animation-duration: 333ms; }',
'.animate-duration-\\[666ms\\] { animation-duration: 666ms; }',
])
})
it('generates `delay` utilities', async () => {
expect(await run('content/delay.html', { scope: 'utilities' })).toIncludeAll([
'.animate-delay-75 { animation-delay: 75ms; }',
'.animate-delay-333 { animation-delay: 333ms; }',
'.animate-delay-\\[666ms\\] { animation-delay: 666ms; }',
])
})

it('generates `direction` utilities', async () => {
expect(await run('content/direction.html', { scope: 'utilities' })).toIncludeAll([
'.animate-normal { animation-direction: normal; }',
'.animate-reverse { animation-direction: reverse; }',
])
})
it('generates `direction` utilities', async () => {
expect(await run('content/direction.html', { scope: 'utilities' })).toIncludeAll([
'.animate-normal { animation-direction: normal; }',
'.animate-reverse { animation-direction: reverse; }',
])
})

it('generates `fill-mode` utilities', async () => {
expect(await run('content/fill-mode.html', { scope: 'utilities' })).toIncludeAll([
'.animate-fill-both { animation-fill-mode: both; }',
'.animate-fill-none { animation-fill-mode: normal; }',
])
})
it('generates `duration` utilities', async () => {
expect(await run('content/duration.html', { scope: 'utilities' })).toIncludeAll([
'.animate-duration-75 { animation-duration: 75ms; }',
'.animate-duration-333 { animation-duration: 333ms; }',
'.animate-duration-\\[666ms\\] { animation-duration: 666ms; }',
])
})

it('generates `iteration-count` utilities', async () => {
expect(await run('content/iteration-count.html', { scope: 'utilities' })).toIncludeAll([
'.animate-infinite { animation-iteration-count: infinite; }',
'.animate-once { animation-iteration-count: 1; }',
'.animate-iteration-7 { animation-iteration-count: 7; }',
'.animate-iteration-\\[14\\] { animation-iteration-count: 14; }',
])
})
it('generates `fill-mode` utilities', async () => {
expect(await run('content/fill-mode.html', { scope: 'utilities' })).toIncludeAll([
'.animate-fill-both { animation-fill-mode: both; }',
'.animate-fill-none { animation-fill-mode: normal; }',
])
})

it('generates `play-state` utilities', async () => {
expect(await run('content/play-state.html', { scope: 'utilities' })).toIncludeAll([
'.animate-play { animation-play-state: running; }',
'.animate-stop { animation-play-state: paused; }',
])
})
it('generates `iteration-count` utilities', async () => {
expect(await run('content/iteration-count.html', { scope: 'utilities' })).toIncludeAll([
'.animate-infinite { animation-iteration-count: infinite; }',
'.animate-once { animation-iteration-count: 1; }',
'.animate-iteration-7 { animation-iteration-count: 7; }',
'.animate-iteration-\\[14\\] { animation-iteration-count: 14; }',
])
})

it('generates `timing-function` utilities', async () => {
expect(await run('content/timing-function.html', { scope: 'utilities' })).toIncludeAll([
'.animate-ease { animation-timing-function: ease; }',
'.animate-ease-linear { animation-timing-function: linear; }',
'.animate-ease-\\[cubic-bezier\\(1\\,0\\.66\\,0\\.33\\,0\\)\\] { animation-timing-function: cubic-bezier(1,0.66,0.33,0); }',
])
})
it('generates `play-state` utilities', async () => {
expect(await run('content/play-state.html', { scope: 'utilities' })).toIncludeAll([
'.animate-play { animation-play-state: running; }',
'.animate-stop { animation-play-state: paused; }',
])
})

it('generates `composition` utilities', async () => {
expect(await run('content/composition.html', { scope: 'utilities' })).toIncludeAll([
'.animate-add { animation-composition: add; }',
'.animate-replace { animation-composition: replace; }',
'.animate-accumulate { animation-composition: accumulate; }',
])
})
it('generates predefined animations for modern import', async () => {
expect(await run('content/predefined-animations.html', { importType: 'modern' })).toIncludeAll([
'.animate-fade { animation: var(--animate-fade); }',
'--animate-fade: fade var(--default-animation-duration, 1s) var(--default-animation-timing-function, ease) var(--default-animation-delay, 0s) both;',
'@keyframes fade { 0% { opacity: 0; } 100% { opacity: 1; }}',
'.animate-spin { animation: var(--animate-spin); }',
'--animate-spin: spin var(--default-animation-duration, 1s) var(--default-animation-timing-function, linear) var(--default-animation-delay, 0s) infinite;',
'@keyframes spin { to { transform: rotate(360deg); }}',
])
})

it('generates predefined animations for modern import', async () => {
expect(await run('content/predefined-animations.html', { importType: 'modern' })).toIncludeAll([
'.animate-fade { animation: var(--animate-fade); }',
'--animate-fade: fade var(--default-animation-duration, 1s) var(--default-animation-timing-function, ease) var(--default-animation-delay, 0s) both;',
'@keyframes fade { 0% { opacity: 0; } 100% { opacity: 1; }}',
'.animate-spin { animation: var(--animate-spin); }',
'--animate-spin: spin var(--default-animation-duration, 1s) var(--default-animation-timing-function, linear) var(--default-animation-delay, 0s) infinite;',
'@keyframes spin { to { transform: rotate(360deg); }}',
])
})
it('generates predefined animations for legacy import', async () => {
expect(await run('content/predefined-animations.html', { importType: 'legacy' })).toIncludeAll([
'.animate-fade { animation: fade var(--default-animation-duration, 1s) var(--default-animation-timing-function, ease) var(--default-animation-delay, 0s) both; }',
'@keyframes fade { 0% { opacity: 0; } 100% { opacity: 1; }}',
'.animate-spin { animation: spin var(--default-animation-duration, 1s) var(--default-animation-timing-function, linear) var(--default-animation-delay, 0s) infinite; }',
'@keyframes spin { to { transform: rotate(360deg); }}',
])
})

it('generates predefined animations for legacy import', async () => {
expect(await run('content/predefined-animations.html', { importType: 'legacy' })).toIncludeAll([
'.animate-fade { animation: fade var(--default-animation-duration, 1s) var(--default-animation-timing-function, ease) var(--default-animation-delay, 0s) both; }',
'@keyframes fade { 0% { opacity: 0; } 100% { opacity: 1; }}',
'.animate-spin { animation: spin var(--default-animation-duration, 1s) var(--default-animation-timing-function, linear) var(--default-animation-delay, 0s) infinite; }',
'@keyframes spin { to { transform: rotate(360deg); }}',
])
it('generates `timing-function` utilities', async () => {
expect(await run('content/timing-function.html', { scope: 'utilities' })).toIncludeAll([
'.animate-ease { animation-timing-function: ease; }',
'.animate-ease-linear { animation-timing-function: linear; }',
'.animate-ease-\\[cubic-bezier\\(1\\,0\\.66\\,0\\.33\\,0\\)\\] { animation-timing-function: cubic-bezier(1,0.66,0.33,0); }',
])
})
})
94 changes: 94 additions & 0 deletions jest/legacy/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
const fs = require('fs')
const path = require('path')
const postcss = require('postcss')
const tailwindcss = require('tailwindcss')

async function run(file) {
const { currentTestName } = expect.getState()

const config = {
content: [file],
corePlugins: { preflight: false },
plugins: [require('../../src')],
}

const result = await postcss(tailwindcss(config)).process('@tailwind utilities', {
from: `${path.resolve(__filename)}?test=${currentTestName}`,
})

return result.css
}

describe('legacy tailwind', () => {
if (! fs.existsSync(`${__dirname}/node_modules`)) {
throw new Error(`Dependencies in ${__dirname} are missing`)
}

it('generates `composition` utilities', async () => {
expect(await run('jest/content/composition.html')).toIncludeAll([
'.animate-add { animation-composition: add; }',
'.animate-replace { animation-composition: replace; }',
'.animate-accumulate { animation-composition: accumulate; }',
])
})

it('should add `delay` utilities', async () => {
expect(await run('jest/content/delay.html')).toIncludeAll([
'.animate-delay-75 { animation-delay: 75ms; }',
'.animate-delay-\\[666ms\\] { animation-delay: 666ms; }',
])
})

it('generates `direction` utilities', async () => {
expect(await run('jest/content/direction.html')).toIncludeAll([
'.animate-normal { animation-direction: normal; }',
'.animate-reverse { animation-direction: reverse; }',
])
})

it('generates `duration` utilities', async () => {
expect(await run('jest/content/duration.html')).toIncludeAll([
'.animate-duration-75 { animation-duration: 75ms; }',
'.animate-duration-\\[666ms\\] { animation-duration: 666ms; }',
])
})

it('generates `fill-mode` utilities', async () => {
expect(await run('jest/content/fill-mode.html')).toIncludeAll([
'.animate-fill-both { animation-fill-mode: both; }',
'.animate-fill-none { animation-fill-mode: normal; }',
])
})

it('generates `iteration-count` utilities', async () => {
expect(await run('jest/content/iteration-count.html')).toIncludeAll([
'.animate-infinite { animation-iteration-count: infinite; }',
'.animate-once { animation-iteration-count: 1; }',
'.animate-iteration-\\[14\\] { animation-iteration-count: 14; }',
])
})

it('generates `play-state` utilities', async () => {
expect(await run('jest/content/play-state.html')).toIncludeAll([
'.animate-play { animation-play-state: running; }',
'.animate-stop { animation-play-state: paused; }',
])
})

it('generates predefined animations', async () => {
expect(await run('jest/content/predefined-animations.html')).toIncludeAll([
'.animate-fade { animation: fade var(--default-animation-duration, 1s) var(--default-animation-timing-function, ease) var(--default-animation-delay, 0s) both; }',
'@keyframes fade { 0% { opacity: 0; } 100% { opacity: 1; }}',
'.animate-spin { animation: spin var(--default-animation-duration, 1s) var(--default-animation-timing-function, linear) var(--default-animation-delay, 0s) infinite; }',
'@keyframes spin { to { transform: rotate(360deg); }}',
])
})

it('generates `timing-function` utilities', async () => {
expect(await run('jest/content/timing-function.html')).toIncludeAll([
'.animate-ease { animation-timing-function: ease; }',
'.animate-ease-linear { animation-timing-function: linear; }',
'.animate-ease-\\[cubic-bezier\\(1\\2c 0\\.66\\2c 0\\.33\\2c 0\\)\\] { animation-timing-function: cubic-bezier(1,0.66,0.33,0); }',
])
})
})
11 changes: 11 additions & 0 deletions jest/legacy/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"private": true,
"devDependencies": {
"tailwindcss": "3.1.0"
},
"browserslist": {
"defaults": [
"> 2%"
]
}
}

0 comments on commit 8e033dd

Please sign in to comment.