|
| 1 | +import postcss from 'postcss' |
| 2 | +import processPlugins from '../../src/util/processPlugins' |
| 3 | +import plugin from '../../src/plugins/animation' |
| 4 | + |
| 5 | +function css(nodes) { |
| 6 | + return postcss.root({ nodes }).toString() |
| 7 | +} |
| 8 | + |
| 9 | +test('defining animation and keyframes', () => { |
| 10 | + const config = { |
| 11 | + theme: { |
| 12 | + animation: { |
| 13 | + none: 'none', |
| 14 | + spin: 'spin 1s linear infinite', |
| 15 | + ping: 'ping 1s cubic-bezier(0, 0, 0.2, 1) infinite', |
| 16 | + }, |
| 17 | + keyframes: { |
| 18 | + spin: { to: { transform: 'rotate(360deg)' } }, |
| 19 | + ping: { '75%, 100%': { transform: 'scale(2)', opacity: '0' } }, |
| 20 | + }, |
| 21 | + }, |
| 22 | + variants: { |
| 23 | + animation: [], |
| 24 | + }, |
| 25 | + } |
| 26 | + |
| 27 | + const { utilities } = processPlugins([plugin()], config) |
| 28 | + |
| 29 | + expect(css(utilities)).toMatchCss(` |
| 30 | + @layer utilities { |
| 31 | + @variants { |
| 32 | + @keyframes spin { |
| 33 | + to { transform: rotate(360deg); } |
| 34 | + } |
| 35 | + @keyframes ping { |
| 36 | + 75%, 100% { transform: scale(2); opacity: 0; } |
| 37 | + } |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + @layer utilities { |
| 42 | + @variants { |
| 43 | + .animate-none { animation: none; } |
| 44 | + .animate-spin { animation: spin 1s linear infinite; } |
| 45 | + .animate-ping { animation: ping 1s cubic-bezier(0, 0, 0.2, 1) infinite; } |
| 46 | + } |
| 47 | + } |
| 48 | + `) |
| 49 | +}) |
| 50 | + |
| 51 | +test('defining animation and keyframes with prefix', () => { |
| 52 | + const config = { |
| 53 | + prefix: 'tw-', |
| 54 | + theme: { |
| 55 | + animation: { |
| 56 | + none: 'none', |
| 57 | + spin: 'spin 1s linear infinite', |
| 58 | + ping: 'ping 1s cubic-bezier(0, 0, 0.2, 1) infinite', |
| 59 | + }, |
| 60 | + keyframes: { |
| 61 | + spin: { to: { transform: 'rotate(360deg)' } }, |
| 62 | + ping: { '75%, 100%': { transform: 'scale(2)', opacity: '0' } }, |
| 63 | + }, |
| 64 | + }, |
| 65 | + variants: { |
| 66 | + animation: [], |
| 67 | + }, |
| 68 | + } |
| 69 | + |
| 70 | + const { utilities } = processPlugins([plugin()], config) |
| 71 | + |
| 72 | + expect(css(utilities)).toMatchCss(` |
| 73 | + @layer utilities { |
| 74 | + @variants { |
| 75 | + @keyframes tw-spin { |
| 76 | + to { transform: rotate(360deg); } |
| 77 | + } |
| 78 | + @keyframes tw-ping { |
| 79 | + 75%, 100% { transform: scale(2); opacity: 0; } |
| 80 | + } |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + @layer utilities { |
| 85 | + @variants { |
| 86 | + .tw-animate-none { animation: none; } |
| 87 | + .tw-animate-spin { animation: tw-spin 1s linear infinite; } |
| 88 | + .tw-animate-ping { animation: tw-ping 1s cubic-bezier(0, 0, 0.2, 1) infinite; } |
| 89 | + } |
| 90 | + } |
| 91 | + `) |
| 92 | +}) |
0 commit comments