Skip to content

Commit

Permalink
failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
romainmenke committed Feb 10, 2024
1 parent d8a9f21 commit 2d1301c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
48 changes: 48 additions & 0 deletions test/helpers/ast-checker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"use strict"

const astCheckerPlugin = () => {
return {
postcssPlugin: "ast-checker-plugin",
OnceExit(root) {
root.walkAtRules(node => {
if (typeof node.params !== "string") {
throw node.error(
`Params must be of type 'string', found '${typeof node.params}' instead`,
)
}

if (typeof node.type !== "string") {
throw node.error(
`Type must be of type 'string', found '${typeof node.type}' instead`,
)
}

if (node.type !== "atrule") {
throw node.error(
`Type must be 'atrule', found '${node.type}' instead`,
)
}

if (typeof node.name !== "string") {
throw node.error(
`Name must be of type 'string', found '${typeof node.name}' instead`,
)
}

if (node.nodes && !Array.isArray(node.nodes)) {
throw node.error(
`Nodes must be of type 'Array' when it is present, found '${typeof node.nodes}' instead`,
)
}

if (!("parent" in node)) {
throw node.error("AtRule must have a 'parent' property")
}
})
},
}
}

astCheckerPlugin.postcss = true

module.exports = astCheckerPlugin
3 changes: 2 additions & 1 deletion test/helpers/check-fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const postcss = require("postcss")

// plugin
const atImport = require("../..")
const astCheckerPlugin = require("./ast-checker")

function read(name, ext) {
ext = ext || ".css"
Expand All @@ -20,7 +21,7 @@ module.exports = function (t, file, opts, postcssOpts, warnings) {
if (typeof file === "string") file = { name: file, ext: ".css" }
const { name, ext } = file

return postcss(atImport(opts))
return postcss([atImport(opts), astCheckerPlugin()])
.process(read(name, ext), postcssOpts || {})
.then(result => {
const actual = result.css
Expand Down

0 comments on commit 2d1301c

Please sign in to comment.