-
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add additionalData option (#248)
- Loading branch information
1 parent
eba6f1f
commit 9f781b7
Showing
8 changed files
with
247 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`"additionalData" option should work additionalData data as function: css 1`] = ` | ||
"/* RelativePath: additional-data.styl; */ | ||
body { | ||
color: #ff7f50; | ||
} | ||
.custom-class { | ||
background: #808080; | ||
} | ||
" | ||
`; | ||
|
||
exports[`"additionalData" option should work additionalData data as function: errors 1`] = `Array []`; | ||
|
||
exports[`"additionalData" option should work additionalData data as function: warnings 1`] = `Array []`; | ||
|
||
exports[`"additionalData" option should work additionalData data as string: css 1`] = ` | ||
"body { | ||
color: #ff7f50; | ||
} | ||
" | ||
`; | ||
|
||
exports[`"additionalData" option should work additionalData data as string: errors 1`] = `Array []`; | ||
|
||
exports[`"additionalData" option should work additionalData data as string: warnings 1`] = `Array []`; |
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,49 @@ | ||
import { | ||
compile, | ||
getCodeFromBundle, | ||
getCompiler, | ||
getErrors, | ||
getWarnings, | ||
} from './helpers'; | ||
|
||
describe('"additionalData" option', () => { | ||
it('should work additionalData data as string', async () => { | ||
const testId = './additional-data.styl'; | ||
const additionalData = 'color = coral'; | ||
const compiler = getCompiler(testId, { additionalData }); | ||
const stats = await compile(compiler); | ||
const codeFromBundle = getCodeFromBundle(stats, compiler); | ||
|
||
expect(codeFromBundle.css).toMatchSnapshot('css'); | ||
expect(getWarnings(stats)).toMatchSnapshot('warnings'); | ||
expect(getErrors(stats)).toMatchSnapshot('errors'); | ||
}); | ||
|
||
it('should work additionalData data as function', async () => { | ||
const testId = './additional-data.styl'; | ||
const additionalData = (content, loaderContext) => { | ||
const { resourcePath, rootContext } = loaderContext; | ||
// eslint-disable-next-line global-require | ||
const relativePath = require('path').relative(rootContext, resourcePath); | ||
|
||
return ` | ||
/* RelativePath: ${relativePath}; */ | ||
color = coral; | ||
bg = gray; | ||
${content} | ||
.custom-class | ||
background: bg | ||
`; | ||
}; | ||
const compiler = getCompiler(testId, { additionalData }); | ||
const stats = await compile(compiler); | ||
const codeFromBundle = getCodeFromBundle(stats, compiler); | ||
|
||
expect(codeFromBundle.css).toMatchSnapshot('css'); | ||
expect(getWarnings(stats)).toMatchSnapshot('warnings'); | ||
expect(getErrors(stats)).toMatchSnapshot('errors'); | ||
}); | ||
}); |
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,2 @@ | ||
body | ||
color 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