-
-
Notifications
You must be signed in to change notification settings - Fork 470
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow to pass options to
insert
function through style.use()
(
#535)
- Loading branch information
Showing
6 changed files
with
104 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import style from './style.css'; | ||
|
||
style.use({ | ||
insertInto: document.body, | ||
additionalStyles: '.some-element {color: red;}' | ||
}); | ||
|
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,53 @@ | ||
/* eslint-env browser */ | ||
|
||
import { | ||
compile, | ||
getCompiler, | ||
getEntryByInjectType, | ||
getErrors, | ||
getWarnings, | ||
runInJsDom, | ||
} from "./helpers/index"; | ||
|
||
describe('lazyStyleTag insertOptions', () => { | ||
it(`should pass "insertOption" to "insert" function`, async () => { | ||
expect.assertions(3); | ||
|
||
const entry = getEntryByInjectType("insertOptions.js", 'lazyStyleTag'); | ||
const compiler = getCompiler(entry, { | ||
injectType: 'lazyStyleTag', | ||
insert: (styleTag, options) => { | ||
options.insertInto.appendChild(styleTag); | ||
} | ||
}); | ||
const stats = await compile(compiler); | ||
|
||
runInJsDom("main.bundle.js", compiler, stats, (dom) => { | ||
expect(dom.serialize()).toMatchSnapshot("DOM"); | ||
}); | ||
|
||
expect(getWarnings(stats)).toMatchSnapshot("warnings"); | ||
expect(getErrors(stats)).toMatchSnapshot("errors"); | ||
}); | ||
|
||
it(`should pass "insertOption" to "styleTagTransform" function`, async () => { | ||
expect.assertions(3); | ||
|
||
const entry = getEntryByInjectType("insertOptions.js", 'lazyStyleTag'); | ||
const compiler = getCompiler(entry, { | ||
injectType: 'lazyStyleTag', | ||
styleTagTransform: (css, styleTag, options) => { | ||
// eslint-disable-next-line no-param-reassign | ||
styleTag.innerHTML = `${css}.${options.additionalStyles}\n`; | ||
} | ||
}); | ||
const stats = await compile(compiler); | ||
|
||
runInJsDom("main.bundle.js", compiler, stats, (dom) => { | ||
expect(dom.serialize()).toMatchSnapshot("DOM"); | ||
}); | ||
|
||
expect(getWarnings(stats)).toMatchSnapshot("warnings"); | ||
expect(getErrors(stats)).toMatchSnapshot("errors"); | ||
}); | ||
}); |