Skip to content

Commit

Permalink
fix windows unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pieh committed Feb 3, 2022
1 parent 306125e commit 2542b29
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
19 changes: 12 additions & 7 deletions packages/gatsby/src/schema/__tests__/fixtures/queries.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
const os = require(`os`)
const path = require(`path`)

const dir = os.platform() === "win32" ? "C:/Users/test/site" : "/home/test/site"

const nodes = [
{
id: `file1`,
Expand All @@ -8,8 +13,8 @@ const nodes = [
contentDigest: `file1`,
},
name: `1.md`,
dir: `/test`,
absolutePath: `/test/file1`
dir,
absolutePath: path.posix.join(dir, `1.md`)
},
{
id: `file2`,
Expand All @@ -20,8 +25,8 @@ const nodes = [
contentDigest: `file2`,
},
name: `2.md`,
dir: `/test`,
absolutePath: `/test/file2`
dir,
absolutePath: path.posix.join(dir, `2.md`)
},
{
id: `file3`,
Expand All @@ -32,8 +37,8 @@ const nodes = [
contentDigest: `file3`,
},
name: `authors.yaml`,
dir: `/test`,
absolutePath: `/test/file3`
dir,
absolutePath: path.posix.join(dir, `authors.yaml`)
},
{
id: `md1`,
Expand All @@ -52,7 +57,7 @@ const nodes = [
authors: [`author2@example.com`, `author1@example.com`],
reviewer___NODE: `author2`,
reviewerByEmail: `author2@example.com`,
fileRef: `./file2`
fileRef: `2.md`
},
},
{
Expand Down
10 changes: 6 additions & 4 deletions packages/gatsby/src/schema/__tests__/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -2127,14 +2127,16 @@ describe(`Query schema`, () => {
`
const results = await runQuery(query)

expect(results.errors).toBeUndefined()
expect(results.data.markdown.frontmatter.title).toEqual(`Markdown File 1`)
expect(results?.errors).toBeUndefined()
expect(results?.data?.markdown?.frontmatter?.title).toEqual(
`Markdown File 1`
)

// main assertion - markdown.frontmatter.fileRef is a file referenced by local path
// we want to make sure it finds node correctly (and doesn't crash)
expect(
results.data.markdown.frontmatter.fileRef.childMarkdown.frontmatter
.title
results?.data?.markdown?.frontmatter?.fileRef?.childMarkdown
?.frontmatter?.title
).toEqual(`Markdown File 2`)
})

Expand Down

0 comments on commit 2542b29

Please sign in to comment.