-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs #38. The `inlineStyle()` function simply loads the given input from runfiles and returns it in a `<style />` element. This is useful for inlining styles in specific parts of the document, such as inside a declarative shadow DOM template.
- Loading branch information
Showing
7 changed files
with
48 additions
and
6 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
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
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 |
---|---|---|
@@ -1,14 +1,32 @@ | ||
import 'jasmine'; | ||
|
||
import { includeStyle } from 'rules_prerender/packages/rules_prerender/styles'; | ||
import { includeStyle, inlineStyle } from 'rules_prerender/packages/rules_prerender/styles'; | ||
|
||
describe('styles', () => { | ||
describe('includeStyle()', () => { | ||
it('returns a style annotation in an HTML comment', () => { | ||
const annotation = includeStyle('foo/bar/baz.css'); | ||
|
||
expect(annotation) | ||
.toBe('<!-- bazel:rules_prerender:PRIVATE_DO_NOT_DEPEND_OR_ELSE - {"type":"style","path":"foo/bar/baz.css"} -->'); | ||
expect(annotation).toBe( | ||
'<!-- bazel:rules_prerender:PRIVATE_DO_NOT_DEPEND_OR_ELSE - {"type":"style","path":"foo/bar/baz.css"} -->'); | ||
}); | ||
}); | ||
|
||
describe('inlineStyle()', () => { | ||
it('resolves to a `<style />` element with the runfiles content of the given file path', async () => { | ||
const styles = await inlineStyle( | ||
'rules_prerender/packages/rules_prerender/testdata/styles.css'); | ||
expect(styles).toBe(` | ||
<style> | ||
.foo { color: red; } | ||
</style> | ||
`.trim()); | ||
}); | ||
|
||
it('rejects when the given file path is not found in runfiles', async () => { | ||
await expectAsync(inlineStyle('rules_prerender/does/not/exist.css')) | ||
.toBeRejected(); | ||
}); | ||
}); | ||
}); |
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 @@ | ||
package(default_visibility = ["//packages/rules_prerender:__pkg__"]) | ||
|
||
exports_files(["styles.css"]) |
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 @@ | ||
.foo { color: red; } |