|
| 1 | +import { binary, css, js, json, svg, test } from '../utils' |
| 2 | + |
| 3 | +const SIMPLE_IMAGE = `iVBORw0KGgoAAAANSUhEUgAAADAAAAAlAQAAAAAsYlcCAAAACklEQVR4AWMYBQABAwABRUEDtQAAAABJRU5ErkJggg==` |
| 4 | + |
| 5 | +test.debug( |
| 6 | + 'can rewrite urls in production builds', |
| 7 | + { |
| 8 | + fs: { |
| 9 | + 'package.json': json` |
| 10 | + { |
| 11 | + "dependencies": { |
| 12 | + "postcss": "^8", |
| 13 | + "postcss-cli": "^10", |
| 14 | + "tailwindcss": "workspace:^", |
| 15 | + "@tailwindcss/postcss": "workspace:^" |
| 16 | + } |
| 17 | + } |
| 18 | + `, |
| 19 | + 'postcss.config.js': js` |
| 20 | + module.exports = { |
| 21 | + plugins: { |
| 22 | + '@tailwindcss/postcss': {}, |
| 23 | + }, |
| 24 | + } |
| 25 | + `, |
| 26 | + 'src/index.css': css` |
| 27 | + @reference 'tailwindcss'; |
| 28 | + @import './dir-1/bar.css'; |
| 29 | + @import './dir-1/dir-2/baz.css'; |
| 30 | + @import './dir-1/dir-2/vector.css'; |
| 31 | + `, |
| 32 | + 'src/dir-1/bar.css': css` |
| 33 | + .test1 { |
| 34 | + background-image: url('../../resources/image.png'); |
| 35 | + } |
| 36 | + `, |
| 37 | + 'src/dir-1/dir-2/baz.css': css` |
| 38 | + .test2 { |
| 39 | + background-image: url('../../../resources/image.png'); |
| 40 | + } |
| 41 | + `, |
| 42 | + 'src/dir-1/dir-2/vector.css': css` |
| 43 | + @import './dir-3/vector.css'; |
| 44 | + .test3 { |
| 45 | + background-image: url('../../../resources/vector.svg'); |
| 46 | + } |
| 47 | + `, |
| 48 | + 'src/dir-1/dir-2/dir-3/vector.css': css` |
| 49 | + .test4 { |
| 50 | + background-image: url('./vector-2.svg'); |
| 51 | + } |
| 52 | + `, |
| 53 | + 'resources/image.png': binary(SIMPLE_IMAGE), |
| 54 | + 'resources/vector.svg': svg` |
| 55 | + <svg width="400" height="400" xmlns="http://www.w3.org/2000/svg"> |
| 56 | + <rect width="100%" height="100%" fill="red" /> |
| 57 | + <circle cx="200" cy="100" r="80" fill="green" /> |
| 58 | + <rect width="100%" height="100%" fill="red" /> |
| 59 | + <circle cx="200" cy="100" r="80" fill="green" /> |
| 60 | + </svg> |
| 61 | + `, |
| 62 | + 'src/dir-1/dir-2/dir-3/vector-2.svg': svg` |
| 63 | + <svg width="400" height="400" xmlns="http://www.w3.org/2000/svg"> |
| 64 | + <rect width="100%" height="100%" fill="blue" /> |
| 65 | + <circle cx="200" cy="100" r="80" fill="green" /> |
| 66 | + <rect width="100%" height="100%" fill="red" /> |
| 67 | + <circle cx="200" cy="100" r="80" fill="pink" /> |
| 68 | + </svg> |
| 69 | + `, |
| 70 | + }, |
| 71 | + }, |
| 72 | + async ({ fs, exec, expect }) => { |
| 73 | + await exec('pnpm postcss src/index.css --output dist/out.css') |
| 74 | + |
| 75 | + expect(await fs.dumpFiles('dist/out.css')).toMatchInlineSnapshot(` |
| 76 | + " |
| 77 | + --- dist/out.css --- |
| 78 | + .test1 { |
| 79 | + background-image: url('../resources/image.png'); |
| 80 | + } |
| 81 | + .test2 { |
| 82 | + background-image: url('../resources/image.png'); |
| 83 | + } |
| 84 | + .test4 { |
| 85 | + background-image: url('./dir-1/dir-2/dir-3/vector-2.svg'); |
| 86 | + } |
| 87 | + .test3 { |
| 88 | + background-image: url('../resources/vector.svg'); |
| 89 | + } |
| 90 | + " |
| 91 | + `) |
| 92 | + }, |
| 93 | +) |
0 commit comments