custom-transformers.test.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import path from 'path'
  2. import { run, html, css } from './util/run'
  3. function customTransformer(content) {
  4. return content.replace(/uppercase/g, 'lowercase')
  5. }
  6. test('transform function', () => {
  7. let config = {
  8. content: {
  9. files: [{ raw: html`<div class="uppercase"></div>` }],
  10. transform: customTransformer,
  11. },
  12. }
  13. return run('@tailwind utilities', config).then((result) => {
  14. expect(result.css).toMatchFormattedCss(css`
  15. .lowercase {
  16. text-transform: lowercase;
  17. }
  18. `)
  19. })
  20. })
  21. test('transform.DEFAULT', () => {
  22. let config = {
  23. content: {
  24. files: [{ raw: html`<div class="uppercase"></div>` }],
  25. transform: {
  26. DEFAULT: customTransformer,
  27. },
  28. },
  29. }
  30. return run('@tailwind utilities', config).then((result) => {
  31. expect(result.css).toMatchFormattedCss(css`
  32. .lowercase {
  33. text-transform: lowercase;
  34. }
  35. `)
  36. })
  37. })
  38. test('transform.{extension}', () => {
  39. let config = {
  40. content: {
  41. files: [
  42. path.resolve(__dirname, './custom-transformers.test.html'),
  43. path.resolve(__dirname, './custom-transformers.test.php'),
  44. ],
  45. transform: {
  46. html: () => 'uppercase',
  47. php: () => 'lowercase',
  48. },
  49. },
  50. }
  51. return run('@tailwind utilities', config).then((result) => {
  52. expect(result.css).toMatchFormattedCss(css`
  53. .uppercase {
  54. text-transform: uppercase;
  55. }
  56. .lowercase {
  57. text-transform: lowercase;
  58. }
  59. `)
  60. })
  61. })