stylePluginScoped.spec.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import { compileStyle } from '../src/compileStyle'
  2. // vue-loader/#1370
  3. test('spaces after selector', () => {
  4. const { code } = compileStyle({
  5. source: `.foo , .bar { color: red; }`,
  6. filename: 'test.css',
  7. id: 'test'
  8. })
  9. expect(code).toMatch(`.foo[test], .bar[test] { color: red;`)
  10. })
  11. test('leading deep selector', () => {
  12. const { code } = compileStyle({
  13. source: `>>> .foo { color: red; }`,
  14. filename: 'test.css',
  15. id: 'test'
  16. })
  17. expect(code).toMatch(`[test] .foo { color: red;`)
  18. })
  19. test('scoped css', () => {
  20. const { code: style } = compileStyle({
  21. id: 'v-scope-xxx',
  22. scoped: true,
  23. filename: 'example.vue',
  24. source: `
  25. .test {
  26. color: yellow;
  27. }
  28. .test:after {
  29. content: 'bye!';
  30. }
  31. h1 {
  32. color: green;
  33. }
  34. .anim {
  35. animation: color 5s infinite, other 5s;
  36. }
  37. .anim-2 {
  38. animation-name: color;
  39. animation-duration: 5s;
  40. }
  41. .anim-3 {
  42. animation: 5s color infinite, 5s other;
  43. }
  44. .anim-multiple {
  45. animation: color 5s infinite, opacity 2s;
  46. }
  47. .anim-multiple-2 {
  48. animation-name: color, opacity;
  49. animation-duration: 5s, 2s;
  50. }
  51. @keyframes color {
  52. from { color: red; }
  53. to { color: green; }
  54. }
  55. @-webkit-keyframes color {
  56. from { color: red; }
  57. to { color: green; }
  58. }
  59. @keyframes opacity {
  60. from { opacity: 0; }
  61. to { opacity: 1; }
  62. }
  63. @-webkit-keyframes opacity {
  64. from { opacity: 0; }
  65. to { opacity: 1; }
  66. }
  67. .foo p >>> .bar {
  68. color: red;
  69. }
  70. .foo div /deep/ .bar {
  71. color: red;
  72. }
  73. .foo span ::v-deep .bar {
  74. color: red;
  75. }
  76. `
  77. })
  78. expect(style).toContain(`.test[v-scope-xxx] {\n color: yellow;\n}`)
  79. expect(style).toContain(`.test[v-scope-xxx]:after {\n content: \'bye!\';\n}`)
  80. expect(style).toContain(`h1[v-scope-xxx] {\n color: green;\n}`)
  81. // scoped keyframes
  82. expect(style).toContain(
  83. `.anim[v-scope-xxx] {\n animation: color-v-scope-xxx 5s infinite, other 5s;`
  84. )
  85. expect(style).toContain(
  86. `.anim-2[v-scope-xxx] {\n animation-name: color-v-scope-xxx`
  87. )
  88. expect(style).toContain(
  89. `.anim-3[v-scope-xxx] {\n animation: 5s color-v-scope-xxx infinite, 5s other;`
  90. )
  91. expect(style).toContain(`@keyframes color-v-scope-xxx {`)
  92. expect(style).toContain(`@-webkit-keyframes color-v-scope-xxx {`)
  93. expect(style).toContain(
  94. `.anim-multiple[v-scope-xxx] {\n animation: color-v-scope-xxx 5s infinite,opacity-v-scope-xxx 2s;`
  95. )
  96. expect(style).toContain(
  97. `.anim-multiple-2[v-scope-xxx] {\n animation-name: color-v-scope-xxx,opacity-v-scope-xxx;`
  98. )
  99. expect(style).toContain(`@keyframes opacity-v-scope-xxx {`)
  100. expect(style).toContain(`@-webkit-keyframes opacity-v-scope-xxx {`)
  101. // >>> combinator
  102. expect(style).toContain(`.foo p[v-scope-xxx] .bar {\n color: red;\n}`)
  103. // /deep/ alias for >>>
  104. expect(style).toContain(`.foo div[v-scope-xxx] .bar {\n color: red;\n}`)
  105. // ::-v-deep alias for >>>
  106. expect(style).toContain(`.foo span[v-scope-xxx] .bar {\n color: red;\n}`)
  107. })
  108. test('pseudo element', () => {
  109. const { code } = compileStyle({
  110. source: '::selection { display: none; }',
  111. filename: 'test.css',
  112. id: 'test'
  113. })
  114. expect(code).toContain('[test]::selection {')
  115. })
  116. test('spaces before pseudo element', () => {
  117. const { code } = compileStyle({
  118. source: '.abc, ::selection { color: red; }',
  119. filename: 'test.css',
  120. id: 'test'
  121. })
  122. expect(code).toContain('.abc[test],')
  123. expect(code).toContain('[test]::selection {')
  124. })