Skip to content
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

[1.0] Make nodes fully immutable by adding API for allowing plugins to add fields #1035

Merged
merged 17 commits into from
May 26, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update transformer tests
  • Loading branch information
KyleAMathews committed May 25, 2017
commit d89607fcf3b17f6b343102d9111aa3bd4cd8a09a
3 changes: 1 addition & 2 deletions packages/gatsby-transformer-json/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"author": "Kyle Mathews <mathews.kyle@gmail.com>",
"license": "MIT",
"dependencies": {
"bluebird": "^3.5.0",
"unist-util-select": "^1.5.0"
"bluebird": "^3.5.0"
},
"devDependencies": {
"babel-cli": "^6.24.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,58 @@ exports[`Process JSON nodes correctly correctly creates nodes from JSON which is
Array [
Array [
Object {
"children": Array [
"foo",
"whatever [1] >>> JSON",
],
"content": "[{\\"id\\":\\"foo\\",\\"blue\\":true,\\"funny\\":\\"yup\\"},{\\"blue\\":false,\\"funny\\":\\"nope\\"}]",
"id": "whatever",
"internal": Object {
"contentDigest": "whatever",
"mediaType": "application/json",
"name": "test",
"child": Object {
"blue": true,
"children": Array [],
"funny": "yup",
"id": "foo",
"internal": Object {
"content": "{\\"id\\":\\"foo\\",\\"blue\\":true,\\"funny\\":\\"yup\\"}",
"contentDigest": "8838e569ae02d98806532310fb2a577a",
"mediaType": "application/json",
"type": "UndefinedJson",
},
"parent": "whatever",
},
"parent": Object {
"children": Array [],
"content": "[{\\"id\\":\\"foo\\",\\"blue\\":true,\\"funny\\":\\"yup\\"},{\\"blue\\":false,\\"funny\\":\\"nope\\"}]",
"id": "whatever",
"internal": Object {
"contentDigest": "whatever",
"mediaType": "application/json",
"name": "test",
},
"parent": "SOURCE",
},
},
],
Array [
Object {
"child": Object {
"blue": false,
"children": Array [],
"funny": "nope",
"id": "whatever [1] >>> JSON",
"internal": Object {
"content": "{\\"blue\\":false,\\"funny\\":\\"nope\\"}",
"contentDigest": "f624311d932d73dcd416d2a8bea2b67d",
"mediaType": "application/json",
"type": "UndefinedJson",
},
"parent": "whatever",
},
"parent": Object {
"children": Array [],
"content": "[{\\"id\\":\\"foo\\",\\"blue\\":true,\\"funny\\":\\"yup\\"},{\\"blue\\":false,\\"funny\\":\\"nope\\"}]",
"id": "whatever",
"internal": Object {
"contentDigest": "whatever",
"mediaType": "application/json",
"name": "test",
},
"parent": "SOURCE",
},
"parent": "SOURCE",
},
],
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe(`Process JSON nodes correctly`, () => {
expect(createNode.mock.calls).toMatchSnapshot()
expect(addNodeToParent.mock.calls).toMatchSnapshot()
expect(createNode).toHaveBeenCalledTimes(2)
expect(addNodeToParent).toHaveBeenCalledTimes(1)
expect(addNodeToParent).toHaveBeenCalledTimes(2)
})
})

Expand Down
1 change: 0 additions & 1 deletion packages/gatsby-transformer-json/src/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const select = require(`unist-util-select`)
const Promise = require(`bluebird`)
const fs = require(`fs`)
const _ = require(`lodash`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,38 @@ exports[`Process markdown content correctly Correctly creates a new MarkdownRema
Array [
Array [
Object {
"children": Array [
"whatever >>> MarkdownRemark",
],
"content": "---
"child": Object {
"children": Array [],
"frontmatter": Object {
"date": "12/12/2014",
"parent": "whatever",
"title": "my little pony",
},
"id": "whatever >>> MarkdownRemark",
"internal": Object {
"content": "
Where oh where is my little pony?
",
"contentDigest": "54cfa2ad99756f2fa232cac585280a37",
"mediaType": "text/x-markdown",
"type": "MarkdownRemark",
},
"parent": "whatever",
},
"parent": Object {
"children": Array [],
"content": "---
title: \\"my little pony\\"
date: \\"12/12/2014\\"
---

Where oh where is my little pony?
",
"id": "whatever",
"internal": Object {
"contentDigest": "whatever",
"mediaType": "text/x-markdown",
"id": "whatever",
"internal": Object {
"contentDigest": "whatever",
"mediaType": "text/x-markdown",
},
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,23 @@ exports[`Process image nodes correctly correctly creates an ImageSharp node from
Array [
Array [
Object {
"children": Array [
"whatever >> ImageSharp",
],
"extension": "png",
"id": "whatever",
"internal": Object {
"contentDigest": "whatever",
"child": Object {
"children": Array [],
"id": "whatever >> ImageSharp",
"internal": Object {
"contentDigest": "whatever",
"mediaType": undefined,
"type": "ImageSharp",
},
"parent": "whatever",
},
"parent": Object {
"children": Array [],
"extension": "png",
"id": "whatever",
"internal": Object {
"contentDigest": "whatever",
},
},
},
],
Expand Down
3 changes: 1 addition & 2 deletions packages/gatsby-transformer-yaml/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
"license": "MIT",
"dependencies": {
"bluebird": "^3.5.0",
"js-yaml": "3.7.0",
"unist-util-select": "^1.5.0"
"js-yaml": "3.7.0"
},
"devDependencies": {
"babel-cli": "^6.24.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,66 @@ exports[`Process YAML nodes correctly correctly creates nodes from JSON which is
Array [
Array [
Object {
"children": Array [
"whatever [0] >>> YAML",
"whatever [1] >>> YAML",
],
"content": "- blue: true
"child": Object {
"blue": true,
"children": Array [],
"funny": "yup",
"id": "whatever [0] >>> YAML",
"internal": Object {
"content": "{\\"blue\\":true,\\"funny\\":\\"yup\\"}",
"contentDigest": "73901821b17d5aa9dd6026181f73b64c",
"mediaType": "application/json",
"type": "TestYaml",
},
"parent": "whatever",
},
"parent": Object {
"children": Array [],
"content": "- blue: true
funny: yup
- blue: false
funny: nope
",
"id": "whatever",
"internal": Object {
"contentDigest": "whatever",
"mediaType": "text/yaml",
"id": "whatever",
"internal": Object {
"contentDigest": "whatever",
"mediaType": "text/yaml",
},
"name": "test",
"parent": "SOURCE",
},
},
],
Array [
Object {
"child": Object {
"blue": false,
"children": Array [],
"funny": "nope",
"id": "whatever [1] >>> YAML",
"internal": Object {
"content": "{\\"blue\\":false,\\"funny\\":\\"nope\\"}",
"contentDigest": "f624311d932d73dcd416d2a8bea2b67d",
"mediaType": "application/json",
"type": "TestYaml",
},
"parent": "whatever",
},
"parent": Object {
"children": Array [],
"content": "- blue: true
funny: yup
- blue: false
funny: nope
",
"id": "whatever",
"internal": Object {
"contentDigest": "whatever",
"mediaType": "text/yaml",
},
"name": "test",
"parent": "SOURCE",
},
"name": "test",
"parent": "SOURCE",
},
],
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe(`Process YAML nodes correctly`, () => {
expect(createNode.mock.calls).toMatchSnapshot()
expect(addNodeToParent.mock.calls).toMatchSnapshot()
expect(createNode).toHaveBeenCalledTimes(2)
expect(addNodeToParent).toHaveBeenCalledTimes(1)
expect(addNodeToParent).toHaveBeenCalledTimes(2)
})
})

Expand Down