Testing AST Node Object Conversion in GatsbyJS
This test suite validates the functionality of the getObjectFromNode utility in Gatsby Recipes, which converts AST nodes into JavaScript objects. The tests ensure accurate parsing and transformation of complex object structures with nested properties and various data types.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
gatsbyjs/gatsby
deprecated-packages/gatsby-recipes/src/providers/gatsby/utils/get-object-from-node.test.js
import template from "@babel/template"
import getObjectFromNode from "./get-object-from-node"
const buildFixture = () => {
const ast = template(`
const foo = {
foo: \`bar\`,
"baz": 123,
"qux": [
{
foo: 'bar'
},
'baz',
12.34
]
}
`)()
return ast.declarations[0].init
}
test(`get-object-from-node return object from AST node`, () => {
const result = getObjectFromNode(buildFixture())
expect(result).toMatchInlineSnapshot(`
Object {
"baz": 123,
"foo": "bar",
"qux": Array [
Object {
"foo": "bar",
},
"baz",
12.34,
],
}
`)
})