Jordan Pittman af64d7190c
Prevent nesting plugin from breaking other plugins (#7563)
* Prevent nesting plugin from breaking other plugins

This uses a private API but it’s the only solution we have right now. It’s guarded to hopefully be less breaking if the API disappears.

* Update changelog
2022-02-21 10:12:39 -05:00

43 lines
674 B
JavaScript

export function visitorSpyPlugin() {
let Once = jest.fn()
let OnceExit = jest.fn()
let Root = jest.fn()
let AtRule = jest.fn()
let Rule = jest.fn()
let Comment = jest.fn()
let Declaration = jest.fn()
let plugin = Object.assign(
function () {
return {
postcssPlugin: 'visitor-test',
// These work fine
Once,
OnceExit,
// These break
Root,
Rule,
AtRule,
Declaration,
Comment,
}
},
{ postcss: true }
)
return {
plugin,
spies: {
Once,
OnceExit,
Root,
AtRule,
Rule,
Comment,
Declaration,
},
}
}