Skip to content

Commit aeedfac

Browse files
committed
Add graphql tests to CI, move snapshots to fixures, use mockdate
1 parent 84153b4 commit aeedfac

File tree

7 files changed

+67
-54
lines changed

7 files changed

+67
-54
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
strategy:
3737
fail-fast: false
3838
matrix:
39-
test-group: [content, meta, rendering, routing, unit, links-and-images]
39+
test-group: [content, meta, rendering, routing, unit, links-and-images, graphql]
4040
steps:
4141
# Each of these ifs needs to be repeated at each step to make sure the required check still runs
4242
# Even if if doesn't do anything

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"lodash": "^4.17.19",
5959
"mini-css-extract-plugin": "^0.9.0",
6060
"mkdirp": "^1.0.3",
61+
"mockdate": "^3.0.2",
6162
"morgan": "^1.9.1",
6263
"node-fetch": "^2.6.1",
6364
"platform-utils": "^1.2.0",
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"previewChanges": [
3+
{
4+
"changes": [
5+
"Field `Query.previewField` changed type from `PreviewType` to `PreviewType!`",
6+
"Type for argument `changeTypeArgument` on field 'PreviewType.field1` changed from `Int` to `Float'"
7+
],
8+
"title": "The [Test preview](/graphql/overview/schema-previews#test-preview) includes these changes:"
9+
}
10+
],
11+
"schemaChanges": [
12+
{
13+
"changes": [
14+
"Field `removedField` was removed from object type `Query`",
15+
"Type for argument `argumentMadeRequired` on field `Query.argumentsField` changed from `Int` to `Int!`",
16+
"Type for argument `argumentMadeOptional` on field `Query.argumentsField` changed from `Int!` to `Int`",
17+
"Argument `removedRequiredArgument: Int!` was removed from field `Query.argumentsField`",
18+
"Argument `removedOptionalArgument: Int!` was removed from field `Query.argumentsField`"
19+
],
20+
"title": "The GraphQL schema includes these changes:"
21+
}
22+
],
23+
"upcomingChanges": [
24+
{
25+
"changes": [
26+
"On member `Query.stableField`:`stableField` will be removed. **Effective 2021-06-01**."
27+
],
28+
"title": "The following changes will be made to the schema:"
29+
}
30+
]
31+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
"someStuff": true,
4+
"date": "2020-11-20"
5+
},
6+
{
7+
"previous_entry": "..."
8+
},
9+
{
10+
"another_previous_entry": "..."
11+
}
12+
]

tests/graphql/__snapshots__/build-changelog-test.js.snap

Lines changed: 0 additions & 50 deletions
This file was deleted.

tests/graphql/build-changelog-test.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
const yaml = require('js-yaml')
22
const { createChangelogEntry, cleanPreviewTitle, previewAnchor, prependDatedEntry } = require('../../script/graphql/build-changelog')
33
const fs = require('fs')
4+
const MockDate = require("mockdate")
5+
const expectedChangelogEntry = require('../fixtures/changelog-entry')
6+
const expectedUpdatedChangelogFile = require('../fixtures/updated-changelog-file')
47

58
describe('creating a changelog from old schema and new schema', () => {
9+
afterEach(() => {
10+
MockDate.reset()
11+
})
12+
613
it('finds a diff of schema changes, upcoming changes, and preview changes', async () => {
714
const oldSchemaString = `
815
type PreviewType {
@@ -68,7 +75,7 @@ upcoming_changes:
6875
`).upcoming_changes
6976

7077
const entry = await createChangelogEntry(oldSchemaString, newSchemaString, previews, oldUpcomingChanges, newUpcomingChanges)
71-
expect(entry).toMatchSnapshot()
78+
expect(entry).toEqual(expectedChangelogEntry)
7279
})
7380

7481
it('returns null when there isnt any difference', async () => {
@@ -100,18 +107,25 @@ describe('Preparing preview links', () => {
100107
})
101108

102109
describe('updating the changelog file', () => {
110+
afterEach(() => {
111+
MockDate.reset()
112+
})
113+
103114
it('modifies the entry object and the file on disk', () => {
104115
const testTargetPath = 'tests/graphql/example_changelog.json'
105116
const previousContents = fs.readFileSync(testTargetPath)
106117

107118
const exampleEntry = { someStuff: true }
119+
const expectedDate = "2020-11-20"
120+
MockDate.set(expectedDate)
121+
108122
prependDatedEntry(exampleEntry, testTargetPath)
109123
const newContents = fs.readFileSync(testTargetPath, 'utf8')
110124
// reset the file:
111125
fs.writeFileSync(testTargetPath, previousContents)
112126

113-
const expectedDate = (new Date()).toISOString().split('T')[0]
127+
114128
expect(exampleEntry).toEqual({ someStuff: true, date: expectedDate })
115-
expect(newContents).toMatchSnapshot()
129+
expect(JSON.parse(newContents)).toEqual(expectedUpdatedChangelogFile)
116130
})
117131
})

0 commit comments

Comments
 (0)