Skip to content

feat: pass styleOption into compiler #398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,24 @@ You can provide [TemplateCompileOptions](https://github.com/vuejs/component-comp
}
}
```

## Style options

Possbility to change style loader options (sass, scss, less etc).

`styleOptions`: `Object` Default `{}`.

```json
{
"jest": {
"globals": {
"vue-jest": {
"styleOptions": {
"quietDeps" // e.q. sass options https://sass-lang.com/documentation/js-api#quietdeps
// unfortunately rest options like `data`, `file` doesnt work because @vue/compiler-component-utils internally overwrite options with their values
},
}
}
}
}
```
32 changes: 32 additions & 0 deletions e2e/2.x/basic/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ import Pug from './components/Pug.vue'
import PugRelative from './components/PugRelativeExtends.vue'
import Jsx from './components/Jsx.vue'
import Constructor from './components/Constructor.vue'
import { compileStyle } from '@vue/component-compiler-utils'
jest.mock('@vue/component-compiler-utils', () => ({
...jest.requireActual('@vue/component-compiler-utils'),
compileStyle: jest.fn(() => ({ errors: [], code: '' }))
}))

beforeEach(() => jest.clearAllMocks())
test('processes .vue files', () => {
const wrapper = mount(Basic)
expect(wrapper.vm.msg).toEqual('Welcome to Your Vue.js App')
Expand Down Expand Up @@ -149,3 +155,29 @@ test('processes SFC with no template', () => {
const wrapper = mount(RenderFunction)
expect(wrapper.element.tagName).toBe('SECTION')
})

test('should pass properly "styleOptions" into "preprocessOptions"', () => {
const filePath = resolve(__dirname, './components/Basic.vue')
const fileString = readFileSync(filePath, { encoding: 'utf8' })
const config = {
moduleFileExtensions: ['js', 'vue'],
globals: {
'vue-jest': {
styleOptions: {
quietDeps: true
}
}
}
}

jestVue.process(fileString, filePath, {
config
})

expect(compileStyle.mock.calls[0][0].preprocessOptions).toStrictEqual({
quietDeps: true
})
expect(compileStyle.mock.calls[1][0].preprocessOptions).toStrictEqual({
quietDeps: true
})
})
5 changes: 4 additions & 1 deletion packages/vue2-jest/lib/process-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ module.exports = function processStyle(stylePart, filePath, config = {}) {
source: content,
filePath,
preprocessLang: stylePart.lang,
preprocessOptions,
preprocessOptions: {
...preprocessOptions,
...vueJestConfig.styleOptions
},
scoped: false
})
logResultErrors(result)
Expand Down