-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Expose styles build as a standalone feature (#72)
- Loading branch information
1 parent
89daeee
commit 2a31329
Showing
15 changed files
with
107 additions
and
7 deletions.
There are no files selected for viewing
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
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions
3
src/build/__tests__/__fixtures__/scss-only/dependencies/commons.scss
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,3 @@ | ||
.container { | ||
background: #fff; | ||
} |
5 changes: 5 additions & 0 deletions
5
src/build/__tests__/__fixtures__/scss-only/dependencies/styles.scss
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,5 @@ | ||
@use './commons'; | ||
|
||
.root { | ||
inset: 0; | ||
} |
3 changes: 3 additions & 0 deletions
3
src/build/__tests__/__fixtures__/scss-only/dir-structure/styles.scss
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,3 @@ | ||
.root { | ||
/* used in test-utils */ | ||
} |
3 changes: 3 additions & 0 deletions
3
src/build/__tests__/__fixtures__/scss-only/dir-structure/sub-component/styles.scss
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,3 @@ | ||
.root { | ||
/* used in test-utils */ | ||
} |
5 changes: 5 additions & 0 deletions
5
src/build/__tests__/__fixtures__/scss-only/inlines/styles.scss
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,5 @@ | ||
@use 'awsui:tokens' as tokens; | ||
|
||
.root { | ||
background: tokens.$color-background; | ||
} |
9 changes: 9 additions & 0 deletions
9
src/build/__tests__/__fixtures__/scss-only/simple/styles.scss
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,9 @@ | ||
$root-color: red; | ||
|
||
.root { | ||
/* used in tests */ | ||
} | ||
|
||
.red-text { | ||
color: $root-color; | ||
} |
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,66 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { expect, test } from 'vitest'; | ||
import { buildStyles, InlineStylesheet } from '../internal'; | ||
import { join } from 'node:path'; | ||
import { readFileSync, readdirSync } from 'node:fs'; | ||
|
||
const fixturesRoot = join(__dirname, '__fixtures__', 'scss-only'); | ||
const outputRoot = join(__dirname, 'out', 'scss-only'); | ||
|
||
async function buildWithFixtures(suiteName: string, inlines?: InlineStylesheet[]) { | ||
const outDir = join(outputRoot, suiteName); | ||
await buildStyles(join(fixturesRoot, suiteName), join(outputRoot, suiteName), inlines); | ||
return outDir; | ||
} | ||
|
||
test('simple styles build', async () => { | ||
const outDir = await buildWithFixtures('simple'); | ||
expect(readdirSync(outDir)).toEqual(['styles.css.js', 'styles.scoped.css', 'styles.selectors.js']); | ||
const { default: styles } = await import(join(outDir, 'styles.css.js')); | ||
expect(styles).toMatchInlineSnapshot(` | ||
{ | ||
"red-text": "awsui_red-text_4px4j_e9pfl_5", | ||
"root": "awsui_root_4px4j_e9pfl_1", | ||
} | ||
`); | ||
}); | ||
|
||
test('bundles all imports for styles.scss entry point', async () => { | ||
const outDir = await buildWithFixtures('dependencies'); | ||
expect(readdirSync(outDir)).toEqual(['styles.css.js', 'styles.scoped.css', 'styles.selectors.js']); | ||
const { default: styles } = await import(join(outDir, 'styles.css.js')); | ||
// includes class names from both files in the fixture | ||
expect(styles).toMatchInlineSnapshot(` | ||
{ | ||
"container": "awsui_container_4px4j_1gm47_1", | ||
"root": "awsui_root_4px4j_1gm47_5", | ||
} | ||
`); | ||
}); | ||
|
||
test('supports virtual stylesheets', async () => { | ||
const outDir = await buildWithFixtures('inlines', [{ url: 'awsui:tokens', contents: '$color-background: #abcabc' }]); | ||
expect(readdirSync(outDir)).toEqual(['styles.css.js', 'styles.scoped.css', 'styles.selectors.js']); | ||
const cssContent = readFileSync(join(outDir, 'styles.scoped.css'), 'utf8'); | ||
expect(cssContent).toContain('#abcabc'); | ||
}); | ||
|
||
test('throws an error if a virtual stylesheet is not defined', async () => { | ||
// rejects with an error containing message 'Can\'t find stylesheet to import' | ||
await expect(() => buildWithFixtures('inlines')).rejects.toThrowError(/awsui:tokens/); | ||
}); | ||
|
||
test('mirrors directory structure of the sources', async () => { | ||
const outDir = await buildWithFixtures('dir-structure'); | ||
expect(readdirSync(outDir)).toEqual(['styles.css.js', 'styles.scoped.css', 'styles.selectors.js', 'sub-component']); | ||
expect(readdirSync(join(outDir, 'sub-component'))).toEqual([ | ||
'styles.css.js', | ||
'styles.scoped.css', | ||
'styles.selectors.js', | ||
]); | ||
const { default: rootStyles } = await import(join(outDir, 'styles.css.js')); | ||
const { default: subComponentStyles } = await import(join(outDir, 'sub-component', 'styles.css.js')); | ||
// ensure the same class name has different scoped name in different files | ||
expect(rootStyles.root).not.toEqual(subComponentStyles.root); | ||
}); |
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