|
| 1 | +import postcss from 'postcss' |
| 2 | +import plugin from '../src/lib/evaluateTailwindFunctions' |
| 3 | + |
| 4 | +function run(input, opts = {}) { |
| 5 | + return postcss([plugin(() => opts)]).process(input) |
| 6 | +} |
| 7 | + |
| 8 | +test("it looks up values in the config using dot notation", () => { |
| 9 | + const input = ` |
| 10 | + .banana { color: config('colors.yellow'); } |
| 11 | + ` |
| 12 | + |
| 13 | + const output = ` |
| 14 | + .banana { color: #f7cc50; } |
| 15 | + ` |
| 16 | + |
| 17 | + return run(input, { |
| 18 | + colors: { |
| 19 | + yellow: '#f7cc50', |
| 20 | + } |
| 21 | + }).then(result => { |
| 22 | + expect(result.css).toEqual(output) |
| 23 | + expect(result.warnings().length).toBe(0) |
| 24 | + }) |
| 25 | +}) |
| 26 | + |
| 27 | +test("quotes are optional around the lookup path", () => { |
| 28 | + const input = ` |
| 29 | + .banana { color: config(colors.yellow); } |
| 30 | + ` |
| 31 | + |
| 32 | + const output = ` |
| 33 | + .banana { color: #f7cc50; } |
| 34 | + ` |
| 35 | + |
| 36 | + return run(input, { |
| 37 | + colors: { |
| 38 | + yellow: '#f7cc50', |
| 39 | + } |
| 40 | + }).then(result => { |
| 41 | + expect(result.css).toEqual(output) |
| 42 | + expect(result.warnings().length).toBe(0) |
| 43 | + }) |
| 44 | +}) |
| 45 | + |
| 46 | +test("a default value can be provided", () => { |
| 47 | + const input = ` |
| 48 | + .cookieMonster { color: config('colors.blue', #0000ff); } |
| 49 | + ` |
| 50 | + |
| 51 | + const output = ` |
| 52 | + .cookieMonster { color: #0000ff; } |
| 53 | + ` |
| 54 | + |
| 55 | + return run(input, { |
| 56 | + colors: { |
| 57 | + yellow: '#f7cc50', |
| 58 | + } |
| 59 | + }).then(result => { |
| 60 | + expect(result.css).toEqual(output) |
| 61 | + expect(result.warnings().length).toBe(0) |
| 62 | + }) |
| 63 | +}) |
| 64 | + |
| 65 | +test("quotes are preserved around default values", () => { |
| 66 | + const input = ` |
| 67 | + .heading { font-family: config('fonts.sans', "Helvetica Neue"); } |
| 68 | + ` |
| 69 | + |
| 70 | + const output = ` |
| 71 | + .heading { font-family: "Helvetica Neue"; } |
| 72 | + ` |
| 73 | + |
| 74 | + return run(input, { |
| 75 | + fonts: { |
| 76 | + serif: "Constantia", |
| 77 | + } |
| 78 | + }).then(result => { |
| 79 | + expect(result.css).toEqual(output) |
| 80 | + expect(result.warnings().length).toBe(0) |
| 81 | + }) |
| 82 | +}) |
0 commit comments