|
| 1 | +import { parse } from '../lib/parse' |
| 2 | +import { compileStyle } from '../lib/compileStyle' |
| 3 | + |
| 4 | +test('preprocess less', () => { |
| 5 | + const style = parse({ |
| 6 | + source: |
| 7 | + '<style lang="less">\n' + |
| 8 | + '@red: rgb(255, 0, 0);\n' + |
| 9 | + '.color { color: @red; }\n' + |
| 10 | + '</style>\n', |
| 11 | + filename: 'example.vue', |
| 12 | + needMap: true |
| 13 | + }).styles[0] |
| 14 | + const result = compileStyle({ |
| 15 | + id: 'v-scope-xxx', |
| 16 | + filename: 'example.vue', |
| 17 | + source: style.content, |
| 18 | + map: style.map, |
| 19 | + scoped: false, |
| 20 | + preprocessLang: style.lang |
| 21 | + }) |
| 22 | + |
| 23 | + expect(result.errors.length).toBe(0) |
| 24 | + expect(result.code).toEqual(expect.stringContaining('color: #ff0000;')) |
| 25 | + expect(result.map).toBeTruthy() |
| 26 | +}) |
| 27 | + |
| 28 | +test('preprocess scss', () => { |
| 29 | + const style = parse({ |
| 30 | + source: |
| 31 | + '<style lang="scss">\n' + |
| 32 | + '$red: rgb(255, 0, 0);\n' + |
| 33 | + '.color { color: $red; }\n' + |
| 34 | + '</style>\n', |
| 35 | + filename: 'example.vue', |
| 36 | + needMap: true |
| 37 | + }).styles[0] |
| 38 | + const result = compileStyle({ |
| 39 | + id: 'v-scope-xxx', |
| 40 | + filename: 'example.vue', |
| 41 | + source: style.content, |
| 42 | + map: style.map, |
| 43 | + scoped: false, |
| 44 | + preprocessLang: style.lang |
| 45 | + }) |
| 46 | + |
| 47 | + expect(result.errors.length).toBe(0) |
| 48 | + expect(result.code).toEqual(expect.stringContaining('color: red;')) |
| 49 | + expect(result.map).toBeTruthy() |
| 50 | +}) |
| 51 | + |
| 52 | +test('preprocess sass', () => { |
| 53 | + const style = parse({ |
| 54 | + source: |
| 55 | + '<style lang="sass">\n' + |
| 56 | + '$red: rgb(255, 0, 0);\n' + |
| 57 | + '.color\n' + |
| 58 | + ' color: $red\n' + |
| 59 | + '</style>\n', |
| 60 | + filename: 'example.vue', |
| 61 | + needMap: true |
| 62 | + }).styles[0] |
| 63 | + const result = compileStyle({ |
| 64 | + id: 'v-scope-xxx', |
| 65 | + filename: 'example.vue', |
| 66 | + source: style.content, |
| 67 | + map: style.map, |
| 68 | + scoped: false, |
| 69 | + preprocessLang: style.lang |
| 70 | + }) |
| 71 | + |
| 72 | + expect(result.errors.length).toBe(0) |
| 73 | + expect(result.code).toEqual(expect.stringContaining('color: red;')) |
| 74 | + expect(result.map).toBeTruthy() |
| 75 | +}) |
| 76 | + |
| 77 | +test('preprocess stylus', () => { |
| 78 | + const style = parse({ |
| 79 | + source: |
| 80 | + '<style lang="styl">\n' + |
| 81 | + 'red-color = rgb(255, 0, 0);\n' + |
| 82 | + '.color\n' + |
| 83 | + ' color: red-color\n' + |
| 84 | + '</style>\n', |
| 85 | + filename: 'example.vue', |
| 86 | + needMap: true |
| 87 | + }).styles[0] |
| 88 | + const result = compileStyle({ |
| 89 | + id: 'v-scope-xxx', |
| 90 | + filename: 'example.vue', |
| 91 | + source: style.content, |
| 92 | + map: style.map, |
| 93 | + scoped: false, |
| 94 | + preprocessLang: style.lang |
| 95 | + }) |
| 96 | + |
| 97 | + expect(result.errors.length).toBe(0) |
| 98 | + expect(result.code).toEqual(expect.stringContaining('color: #f00;')) |
| 99 | + expect(result.map).toBeTruthy() |
| 100 | +}) |
0 commit comments