Skip to content

Commit

Permalink
feat: pass styleOption into compiler (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
Szymon-dziewonski authored Oct 8, 2021
1 parent c6292f3 commit 4012b2c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,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

0 comments on commit 4012b2c

Please sign in to comment.