Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add webpackImporter option (#244)
- Loading branch information
1 parent
a5bebfc
commit bbe232a
Showing
7 changed files
with
249 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
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,43 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`webpackImporter option should throw an error on webpack import when value is "false": errors 1`] = ` | ||
Array [ | ||
"ModuleBuildError: Module build failed (from \`replaced original path\`): | ||
Error: /test/fixtures/import-webpack.styl:1:9", | ||
] | ||
`; | ||
|
||
exports[`webpackImporter option should throw an error on webpack import when value is "false": warnings 1`] = `Array []`; | ||
|
||
exports[`webpackImporter option should work when value is "false": css 1`] = ` | ||
".other { | ||
font-family: serif; | ||
} | ||
" | ||
`; | ||
|
||
exports[`webpackImporter option should work when value is "false": errors 1`] = `Array []`; | ||
|
||
exports[`webpackImporter option should work when value is "false": warnings 1`] = `Array []`; | ||
|
||
exports[`webpackImporter option should work when value is "true": css 1`] = ` | ||
".imported-in-web-modules { | ||
font-size: 2em; | ||
} | ||
" | ||
`; | ||
|
||
exports[`webpackImporter option should work when value is "true": errors 1`] = `Array []`; | ||
|
||
exports[`webpackImporter option should work when value is "true": warnings 1`] = `Array []`; | ||
|
||
exports[`webpackImporter option should work when value is not specify: css 1`] = ` | ||
".imported-in-web-modules { | ||
font-size: 2em; | ||
} | ||
" | ||
`; | ||
|
||
exports[`webpackImporter option should work when value is not specify: errors 1`] = `Array []`; | ||
|
||
exports[`webpackImporter option should work when value is not specify: 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,86 @@ | ||
import path from 'path'; | ||
|
||
import { | ||
compile, | ||
getCodeFromBundle, | ||
getCompiler, | ||
getErrors, | ||
getWarnings, | ||
} from './helpers'; | ||
|
||
describe('webpackImporter option', () => { | ||
it('should work when value is not specify', async () => { | ||
const testId = './import-webpack.styl'; | ||
const compiler = getCompiler( | ||
testId, | ||
{}, | ||
{ | ||
resolve: { | ||
modules: [path.join(__dirname, 'fixtures', 'web_modules')], | ||
}, | ||
} | ||
); | ||
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 when value is "true"', async () => { | ||
const testId = './import-webpack.styl'; | ||
const compiler = getCompiler( | ||
testId, | ||
{ | ||
webpackImporter: true, | ||
}, | ||
{ | ||
resolve: { | ||
modules: [path.join(__dirname, 'fixtures', 'web_modules')], | ||
}, | ||
} | ||
); | ||
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 when value is "false"', async () => { | ||
const testId = './shallow-paths.styl'; | ||
const compiler = getCompiler(testId, { | ||
webpackImporter: false, | ||
stylusOptions: { | ||
paths: ['test/fixtures/paths'], | ||
}, | ||
}); | ||
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 throw an error on webpack import when value is "false"', async () => { | ||
const testId = './import-webpack.styl'; | ||
const compiler = getCompiler( | ||
testId, | ||
{ | ||
webpackImporter: false, | ||
}, | ||
{ | ||
resolve: { | ||
modules: [path.join(__dirname, 'fixtures', 'web_modules')], | ||
}, | ||
} | ||
); | ||
const stats = await compile(compiler); | ||
|
||
expect(getWarnings(stats)).toMatchSnapshot('warnings'); | ||
expect(getErrors(stats)).toMatchSnapshot('errors'); | ||
}); | ||
}); |