|
| 1 | +const compiler = require('../compiler.js'); |
| 2 | + |
| 3 | +describe('Scoped Keyframes', () => { |
| 4 | + test('Mixed mode on tag selector', async () => { |
| 5 | + const source = |
| 6 | + '<style module>'+ |
| 7 | + 'h1 { font-size:18px; animation: fadeIn 2s ease-in; }'+ |
| 8 | + '@keyframes fadeIn {0% {opacity:0} 100% {opacity:1}}'+ |
| 9 | + '</style>'+ |
| 10 | + '<h1>Title</h1>'; |
| 11 | + |
| 12 | + const expectedOutput = |
| 13 | + '<style module>'+ |
| 14 | + 'h1 { font-size:18px; animation: fadeIn-123 2s ease-in; }'+ |
| 15 | + '@keyframes -global-fadeIn-123 {0% {opacity:0} 100% {opacity:1}}'+ |
| 16 | + '</style>'+ |
| 17 | + '<h1>Title</h1>'; |
| 18 | + |
| 19 | + const output = await compiler({ |
| 20 | + source, |
| 21 | + },{ |
| 22 | + mode: 'mixed', |
| 23 | + localIdentName: '[local]-123', |
| 24 | + }); |
| 25 | + |
| 26 | + expect(output).toBe(expectedOutput); |
| 27 | + }); |
| 28 | + |
| 29 | + test('Native mode with multiple animation properties', async () => { |
| 30 | + const source = |
| 31 | + '<style module>'+ |
| 32 | + '.title { font-size:18px; animation: fadeIn 2s ease-in, rotate 2s linear infinite; }'+ |
| 33 | + '@keyframes fadeIn {from {opacity:0} to {opacity:1}}'+ |
| 34 | + '@keyframes rotate {from {transform:rotate(0deg);} to {transform:rotate(360deg);}'+ |
| 35 | + '</style>'+ |
| 36 | + '<span class="title">Red</span>'; |
| 37 | + |
| 38 | + const expectedOutput = |
| 39 | + '<style module>'+ |
| 40 | + ':global(.title-123) { font-size:18px; animation: fadeIn-123 2s ease-in, rotate-123 2s linear infinite; }'+ |
| 41 | + '@keyframes -global-fadeIn-123 {from {opacity:0} to {opacity:1}}'+ |
| 42 | + '@keyframes -global-rotate-123 {from {transform:rotate(0deg);} to {transform:rotate(360deg);}'+ |
| 43 | + '</style>'+ |
| 44 | + '<span class="title-123">Red</span>'; |
| 45 | + |
| 46 | + const output = await compiler({ |
| 47 | + source, |
| 48 | + },{ |
| 49 | + mode: 'native', |
| 50 | + localIdentName: '[local]-123', |
| 51 | + }); |
| 52 | + |
| 53 | + expect(output).toBe(expectedOutput); |
| 54 | + }); |
| 55 | + |
| 56 | + test('Native move on non global keyframes only', async () => { |
| 57 | + const source = |
| 58 | + '<style module>'+ |
| 59 | + '.title { font-size:18px; animation: fadeIn 2s ease-in, rotate 2s linear infinite; }'+ |
| 60 | + '@keyframes fadeIn {from {opacity:0} to {opacity:1}}'+ |
| 61 | + '@keyframes -global-rotate {from {transform:rotate(0deg);} to {transform:rotate(360deg);}'+ |
| 62 | + '</style>'+ |
| 63 | + '<span class="title">Red</span>'; |
| 64 | + |
| 65 | + const expectedOutput = |
| 66 | + '<style module>'+ |
| 67 | + ':global(.title-123) { font-size:18px; animation: fadeIn-123 2s ease-in, rotate 2s linear infinite; }'+ |
| 68 | + '@keyframes -global-fadeIn-123 {from {opacity:0} to {opacity:1}}'+ |
| 69 | + '@keyframes -global-rotate {from {transform:rotate(0deg);} to {transform:rotate(360deg);}'+ |
| 70 | + '</style>'+ |
| 71 | + '<span class="title-123">Red</span>'; |
| 72 | + |
| 73 | + const output = await compiler({ |
| 74 | + source, |
| 75 | + },{ |
| 76 | + mode: 'native', |
| 77 | + localIdentName: '[local]-123', |
| 78 | + }); |
| 79 | + |
| 80 | + expect(output).toBe(expectedOutput); |
| 81 | + }); |
| 82 | +}); |
0 commit comments