Add graphql tests to CI, move snapshots to fixures, use mockdate
This commit is contained in:
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@@ -36,7 +36,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
test-group: [content, meta, rendering, routing, unit, links-and-images]
|
test-group: [content, meta, rendering, routing, unit, links-and-images, graphql]
|
||||||
steps:
|
steps:
|
||||||
# Each of these ifs needs to be repeated at each step to make sure the required check still runs
|
# Each of these ifs needs to be repeated at each step to make sure the required check still runs
|
||||||
# Even if if doesn't do anything
|
# Even if if doesn't do anything
|
||||||
|
|||||||
5
package-lock.json
generated
5
package-lock.json
generated
@@ -15892,6 +15892,11 @@
|
|||||||
"integrity": "sha1-mDaL6wnfdT9k9m2U5VNql7NqJDA=",
|
"integrity": "sha1-mDaL6wnfdT9k9m2U5VNql7NqJDA=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"mockdate": {
|
||||||
|
"version": "3.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/mockdate/-/mockdate-3.0.2.tgz",
|
||||||
|
"integrity": "sha512-ldfYSUW1ocqSHGTK6rrODUiqAFPGAg0xaHqYJ5tvj1hQyFsjuHpuWgWFTZWwDVlzougN/s2/mhDr8r5nY5xDpA=="
|
||||||
|
},
|
||||||
"morgan": {
|
"morgan": {
|
||||||
"version": "1.9.1",
|
"version": "1.9.1",
|
||||||
"resolved": "https://registry.npmjs.org/morgan/-/morgan-1.9.1.tgz",
|
"resolved": "https://registry.npmjs.org/morgan/-/morgan-1.9.1.tgz",
|
||||||
|
|||||||
@@ -58,6 +58,7 @@
|
|||||||
"lodash": "^4.17.19",
|
"lodash": "^4.17.19",
|
||||||
"mini-css-extract-plugin": "^0.9.0",
|
"mini-css-extract-plugin": "^0.9.0",
|
||||||
"mkdirp": "^1.0.3",
|
"mkdirp": "^1.0.3",
|
||||||
|
"mockdate": "^3.0.2",
|
||||||
"morgan": "^1.9.1",
|
"morgan": "^1.9.1",
|
||||||
"node-fetch": "^2.6.1",
|
"node-fetch": "^2.6.1",
|
||||||
"platform-utils": "^1.2.0",
|
"platform-utils": "^1.2.0",
|
||||||
|
|||||||
31
tests/fixtures/changelog-entry.json
vendored
Normal file
31
tests/fixtures/changelog-entry.json
vendored
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
"previewChanges": [
|
||||||
|
{
|
||||||
|
"changes": [
|
||||||
|
"Field `Query.previewField` changed type from `PreviewType` to `PreviewType!`",
|
||||||
|
"Type for argument `changeTypeArgument` on field 'PreviewType.field1` changed from `Int` to `Float'"
|
||||||
|
],
|
||||||
|
"title": "The [Test preview](/graphql/overview/schema-previews#test-preview) includes these changes:"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"schemaChanges": [
|
||||||
|
{
|
||||||
|
"changes": [
|
||||||
|
"Field `removedField` was removed from object type `Query`",
|
||||||
|
"Type for argument `argumentMadeRequired` on field `Query.argumentsField` changed from `Int` to `Int!`",
|
||||||
|
"Type for argument `argumentMadeOptional` on field `Query.argumentsField` changed from `Int!` to `Int`",
|
||||||
|
"Argument `removedRequiredArgument: Int!` was removed from field `Query.argumentsField`",
|
||||||
|
"Argument `removedOptionalArgument: Int!` was removed from field `Query.argumentsField`"
|
||||||
|
],
|
||||||
|
"title": "The GraphQL schema includes these changes:"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"upcomingChanges": [
|
||||||
|
{
|
||||||
|
"changes": [
|
||||||
|
"On member `Query.stableField`:`stableField` will be removed. **Effective 2021-06-01**."
|
||||||
|
],
|
||||||
|
"title": "The following changes will be made to the schema:"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
12
tests/fixtures/updated-changelog-file.json
vendored
Normal file
12
tests/fixtures/updated-changelog-file.json
vendored
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"someStuff": true,
|
||||||
|
"date": "2020-11-20"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"previous_entry": "..."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"another_previous_entry": "..."
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
||||||
|
|
||||||
exports[`creating a changelog from old schema and new schema finds a diff of schema changes, upcoming changes, and preview changes 1`] = `
|
|
||||||
Object {
|
|
||||||
"previewChanges": Array [
|
|
||||||
Object {
|
|
||||||
"changes": Array [
|
|
||||||
"Field \`Query.previewField\` changed type from \`PreviewType\` to \`PreviewType!\`",
|
|
||||||
"Type for argument \`changeTypeArgument\` on field 'PreviewType.field1\` changed from \`Int\` to \`Float'",
|
|
||||||
],
|
|
||||||
"title": "The [Test preview](/graphql/overview/schema-previews#test-preview) includes these changes:",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
"schemaChanges": Array [
|
|
||||||
Object {
|
|
||||||
"changes": Array [
|
|
||||||
"Field \`removedField\` was removed from object type \`Query\`",
|
|
||||||
"Type for argument \`argumentMadeRequired\` on field \`Query.argumentsField\` changed from \`Int\` to \`Int!\`",
|
|
||||||
"Type for argument \`argumentMadeOptional\` on field \`Query.argumentsField\` changed from \`Int!\` to \`Int\`",
|
|
||||||
"Argument \`removedRequiredArgument: Int!\` was removed from field \`Query.argumentsField\`",
|
|
||||||
"Argument \`removedOptionalArgument: Int!\` was removed from field \`Query.argumentsField\`",
|
|
||||||
],
|
|
||||||
"title": "The GraphQL schema includes these changes:",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
"upcomingChanges": Array [
|
|
||||||
Object {
|
|
||||||
"changes": Array [
|
|
||||||
"On member \`Query.stableField\`:\`stableField\` will be removed. **Effective 2021-06-01**.",
|
|
||||||
],
|
|
||||||
"title": "The following changes will be made to the schema:",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`updating the changelog file modifies the entry object and the file on disk 1`] = `
|
|
||||||
"[
|
|
||||||
{
|
|
||||||
\\"someStuff\\": true,
|
|
||||||
\\"date\\": \\"2020-11-23\\"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
\\"previous_entry\\": \\"...\\"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
\\"another_previous_entry\\": \\"...\\"
|
|
||||||
}
|
|
||||||
]"
|
|
||||||
`;
|
|
||||||
@@ -1,8 +1,15 @@
|
|||||||
const yaml = require('js-yaml')
|
const yaml = require('js-yaml')
|
||||||
const { createChangelogEntry, cleanPreviewTitle, previewAnchor, prependDatedEntry } = require('../../script/graphql/build-changelog')
|
const { createChangelogEntry, cleanPreviewTitle, previewAnchor, prependDatedEntry } = require('../../script/graphql/build-changelog')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
|
const MockDate = require("mockdate")
|
||||||
|
const expectedChangelogEntry = require('../fixtures/changelog-entry')
|
||||||
|
const expectedUpdatedChangelogFile = require('../fixtures/updated-changelog-file')
|
||||||
|
|
||||||
describe('creating a changelog from old schema and new schema', () => {
|
describe('creating a changelog from old schema and new schema', () => {
|
||||||
|
afterEach(() => {
|
||||||
|
MockDate.reset()
|
||||||
|
})
|
||||||
|
|
||||||
it('finds a diff of schema changes, upcoming changes, and preview changes', async () => {
|
it('finds a diff of schema changes, upcoming changes, and preview changes', async () => {
|
||||||
const oldSchemaString = `
|
const oldSchemaString = `
|
||||||
type PreviewType {
|
type PreviewType {
|
||||||
@@ -68,7 +75,7 @@ upcoming_changes:
|
|||||||
`).upcoming_changes
|
`).upcoming_changes
|
||||||
|
|
||||||
const entry = await createChangelogEntry(oldSchemaString, newSchemaString, previews, oldUpcomingChanges, newUpcomingChanges)
|
const entry = await createChangelogEntry(oldSchemaString, newSchemaString, previews, oldUpcomingChanges, newUpcomingChanges)
|
||||||
expect(entry).toMatchSnapshot()
|
expect(entry).toEqual(expectedChangelogEntry)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns null when there isnt any difference', async () => {
|
it('returns null when there isnt any difference', async () => {
|
||||||
@@ -100,18 +107,25 @@ describe('Preparing preview links', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('updating the changelog file', () => {
|
describe('updating the changelog file', () => {
|
||||||
|
afterEach(() => {
|
||||||
|
MockDate.reset()
|
||||||
|
})
|
||||||
|
|
||||||
it('modifies the entry object and the file on disk', () => {
|
it('modifies the entry object and the file on disk', () => {
|
||||||
const testTargetPath = 'tests/graphql/example_changelog.json'
|
const testTargetPath = 'tests/graphql/example_changelog.json'
|
||||||
const previousContents = fs.readFileSync(testTargetPath)
|
const previousContents = fs.readFileSync(testTargetPath)
|
||||||
|
|
||||||
const exampleEntry = { someStuff: true }
|
const exampleEntry = { someStuff: true }
|
||||||
|
const expectedDate = "2020-11-20"
|
||||||
|
MockDate.set(expectedDate)
|
||||||
|
|
||||||
prependDatedEntry(exampleEntry, testTargetPath)
|
prependDatedEntry(exampleEntry, testTargetPath)
|
||||||
const newContents = fs.readFileSync(testTargetPath, 'utf8')
|
const newContents = fs.readFileSync(testTargetPath, 'utf8')
|
||||||
// reset the file:
|
// reset the file:
|
||||||
fs.writeFileSync(testTargetPath, previousContents)
|
fs.writeFileSync(testTargetPath, previousContents)
|
||||||
|
|
||||||
const expectedDate = (new Date()).toISOString().split('T')[0]
|
|
||||||
expect(exampleEntry).toEqual({ someStuff: true, date: expectedDate })
|
expect(exampleEntry).toEqual({ someStuff: true, date: expectedDate })
|
||||||
expect(newContents).toMatchSnapshot()
|
expect(JSON.parse(newContents)).toEqual(expectedUpdatedChangelogFile)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user