-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: fix run css playground with legacy sass (#18946)
- Loading branch information
1 parent
11cd5a4
commit 322503b
Showing
9 changed files
with
133 additions
and
95 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
playground/css-sourcemap/__tests__/sass-legacy/sass-legacy.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
// NOTE: a separate directory from `playground/css-sourcemap` is created by playground/vitestGlobalSetup.ts | ||
import '../css-sourcemap.spec' |
1 change: 1 addition & 0 deletions
1
playground/css-sourcemap/__tests__/sass-modern/sass-modern.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
// NOTE: a separate directory from `playground/css-sourcemap` is created by playground/vitestGlobalSetup.ts | ||
import '../css-sourcemap.spec' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// NOTE: a separate directory from `playground/css` is created by playground/vitestGlobalSetup.ts | ||
import { sassModuleTests, sassOtherTests, sassTest } from '../sass-tests' | ||
|
||
sassTest() | ||
sassModuleTests() | ||
sassOtherTests() |
1 change: 0 additions & 1 deletion
1
playground/css/__tests__/sass-modern-compiler/sass-modern-compiler.spec.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
import '../css.spec' | ||
// NOTE: a separate directory from `playground/css` is created by playground/vitestGlobalSetup.ts | ||
import { sassModuleTests, sassOtherTests, sassTest } from '../sass-tests' | ||
|
||
sassTest() | ||
sassModuleTests() | ||
sassOtherTests() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { expect, test } from 'vitest' | ||
import { | ||
editFile, | ||
getBg, | ||
getColor, | ||
isBuild, | ||
page, | ||
untilUpdated, | ||
viteTestUrl, | ||
} from '~utils' | ||
|
||
export const sassTest = () => { | ||
test('sass', async () => { | ||
const imported = await page.$('.sass') | ||
const atImport = await page.$('.sass-at-import') | ||
const atImportAlias = await page.$('.sass-at-import-alias') | ||
const urlStartsWithVariable = await page.$('.sass-url-starts-with-variable') | ||
const urlStartsWithFunctionCall = await page.$( | ||
'.sass-url-starts-with-function-call', | ||
) | ||
const partialImport = await page.$('.sass-partial') | ||
|
||
expect(await getColor(imported)).toBe('orange') | ||
expect(await getColor(atImport)).toBe('olive') | ||
expect(await getBg(atImport)).toMatch( | ||
isBuild ? /base64/ : '/nested/icon.png', | ||
) | ||
expect(await getColor(atImportAlias)).toBe('olive') | ||
expect(await getBg(atImportAlias)).toMatch( | ||
isBuild ? /base64/ : '/nested/icon.png', | ||
) | ||
expect(await getBg(urlStartsWithVariable)).toMatch( | ||
isBuild ? /ok-[-\w]+\.png/ : `${viteTestUrl}/ok.png`, | ||
) | ||
expect(await getBg(urlStartsWithFunctionCall)).toMatch( | ||
isBuild ? /ok-[-\w]+\.png/ : `${viteTestUrl}/ok.png`, | ||
) | ||
expect(await getColor(partialImport)).toBe('orchid') | ||
expect(await getColor(await page.$('.sass-file-absolute'))).toBe('orange') | ||
expect(await getColor(await page.$('.sass-dir-index'))).toBe('orange') | ||
expect(await getColor(await page.$('.sass-root-relative'))).toBe('orange') | ||
|
||
if (isBuild) return | ||
|
||
editFile('sass.scss', (code) => | ||
code.replace('color: $injectedColor', 'color: red'), | ||
) | ||
await untilUpdated(() => getColor(imported), 'red') | ||
|
||
editFile('nested/_index.scss', (code) => | ||
code.replace('color: olive', 'color: blue'), | ||
) | ||
await untilUpdated(() => getColor(atImport), 'blue') | ||
|
||
editFile('nested/_partial.scss', (code) => | ||
code.replace('color: orchid', 'color: green'), | ||
) | ||
await untilUpdated(() => getColor(partialImport), 'green') | ||
}) | ||
} | ||
|
||
export const sassModuleTests = (enableHmrTests = false) => { | ||
test('sass modules composes/from path resolving', async () => { | ||
const imported = await page.$('.path-resolved-modules-sass') | ||
expect(await getColor(imported)).toBe('orangered') | ||
|
||
// check if the generated CSS module class name is indeed using the | ||
// format specified in vite.config.js | ||
expect(await imported.getAttribute('class')).toMatch( | ||
/.composed-module__apply-color___[\w-]{5}/, | ||
) | ||
|
||
expect(await imported.getAttribute('class')).toMatch( | ||
/.composes-path-resolving-module__path-resolving-sass___[\w-]{5}/, | ||
) | ||
|
||
// @todo HMR is not working on this situation. | ||
// editFile('composed.module.scss', (code) => | ||
// code.replace('color: orangered', 'color: red') | ||
// ) | ||
// await untilUpdated(() => getColor(imported), 'red') | ||
}) | ||
|
||
test('css modules w/ sass', async () => { | ||
const imported = await page.$('.modules-sass') | ||
expect(await getColor(imported)).toBe('orangered') | ||
expect(await imported.getAttribute('class')).toMatch( | ||
/.mod-module__apply-color___[\w-]{5}/, | ||
) | ||
|
||
if (isBuild) return | ||
|
||
editFile('mod.module.scss', (code) => | ||
code.replace('color: orangered', 'color: blue'), | ||
) | ||
await untilUpdated(() => getColor(imported), 'blue') | ||
}) | ||
} | ||
|
||
export const sassOtherTests = () => { | ||
test('@import dependency w/ sass entry', async () => { | ||
expect(await getColor('.css-dep-sass')).toBe('orange') | ||
}) | ||
|
||
test('@import dependency w/ sass export mapping', async () => { | ||
expect(await getColor('.css-dep-exports-sass')).toBe('orange') | ||
}) | ||
|
||
test('@import dependency w/out package scss', async () => { | ||
expect(await getColor('.sass-dep')).toBe('lavender') | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters