| 79 | } |
| 80 | |
| 81 | export const sassModuleTests = (enableHmrTests = false) => { |
| 82 | test('sass modules composes/from path resolving', async () => { |
| 83 | const imported = await page.$('.path-resolved-modules-sass') |
| 84 | expect(await getColor(imported)).toBe('orangered') |
| 85 | |
| 86 | // check if the generated CSS module class name is indeed using the |
| 87 | // format specified in vite.config.js |
| 88 | expect(await imported.getAttribute('class')).toMatch( |
| 89 | /.composed-module__apply-color___[\w-]{5}/, |
| 90 | ) |
| 91 | |
| 92 | expect(await imported.getAttribute('class')).toMatch( |
| 93 | /.composes-path-resolving-module__path-resolving-sass___[\w-]{5}/, |
| 94 | ) |
| 95 | |
| 96 | // @todo HMR is not working on this situation. |
| 97 | // editFile('composed.module.scss', (code) => |
| 98 | // code.replace('color: orangered', 'color: red') |
| 99 | // ) |
| 100 | // await expect.poll(() => getColor(imported)).toMatch('red') |
| 101 | }) |
| 102 | |
| 103 | test('css modules w/ sass', async () => { |
| 104 | const imported = await page.$('.modules-sass') |
| 105 | expect(await getColor(imported)).toBe('orangered') |
| 106 | expect(await imported.getAttribute('class')).toMatch( |
| 107 | /.mod-module__apply-color___[\w-]{5}/, |
| 108 | ) |
| 109 | |
| 110 | if (isBuild) return |
| 111 | |
| 112 | editFile('mod.module.scss', (code) => |
| 113 | code.replace('color: orangered', 'color: blue'), |
| 114 | ) |
| 115 | await expect.poll(() => getColor(imported)).toBe('blue') |
| 116 | }) |
| 117 | } |
| 118 | |
| 119 | export const sassOtherTests = () => { |
| 120 | test('@import dependency w/ sass entry', async () => { |