1
0
mirror of synced 2025-12-21 10:57:10 -05:00

Add graphql tests to CI, move snapshots to fixures, use mockdate

This commit is contained in:
Robert Mosolgo
2020-11-25 11:12:13 -05:00
parent 84153b4d03
commit aeedfac37e
7 changed files with 67 additions and 54 deletions

View File

@@ -36,7 +36,7 @@ jobs:
strategy:
fail-fast: false
matrix:
test-group: [content, meta, rendering, routing, unit, links-and-images]
test-group: [content, meta, rendering, routing, unit, links-and-images, graphql]
steps:
# 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

5
package-lock.json generated
View File

@@ -15892,6 +15892,11 @@
"integrity": "sha1-mDaL6wnfdT9k9m2U5VNql7NqJDA=",
"dev": true
},
"mockdate": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/mockdate/-/mockdate-3.0.2.tgz",
"integrity": "sha512-ldfYSUW1ocqSHGTK6rrODUiqAFPGAg0xaHqYJ5tvj1hQyFsjuHpuWgWFTZWwDVlzougN/s2/mhDr8r5nY5xDpA=="
},
"morgan": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/morgan/-/morgan-1.9.1.tgz",

View File

@@ -58,6 +58,7 @@
"lodash": "^4.17.19",
"mini-css-extract-plugin": "^0.9.0",
"mkdirp": "^1.0.3",
"mockdate": "^3.0.2",
"morgan": "^1.9.1",
"node-fetch": "^2.6.1",
"platform-utils": "^1.2.0",

31
tests/fixtures/changelog-entry.json vendored Normal file
View 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:"
}
]
}

View File

@@ -0,0 +1,12 @@
[
{
"someStuff": true,
"date": "2020-11-20"
},
{
"previous_entry": "..."
},
{
"another_previous_entry": "..."
}
]

View File

@@ -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\\": \\"...\\"
}
]"
`;

View File

@@ -1,8 +1,15 @@
const yaml = require('js-yaml')
const { createChangelogEntry, cleanPreviewTitle, previewAnchor, prependDatedEntry } = require('../../script/graphql/build-changelog')
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', () => {
afterEach(() => {
MockDate.reset()
})
it('finds a diff of schema changes, upcoming changes, and preview changes', async () => {
const oldSchemaString = `
type PreviewType {
@@ -68,7 +75,7 @@ upcoming_changes:
`).upcoming_changes
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 () => {
@@ -100,18 +107,25 @@ describe('Preparing preview links', () => {
})
describe('updating the changelog file', () => {
afterEach(() => {
MockDate.reset()
})
it('modifies the entry object and the file on disk', () => {
const testTargetPath = 'tests/graphql/example_changelog.json'
const previousContents = fs.readFileSync(testTargetPath)
const exampleEntry = { someStuff: true }
const expectedDate = "2020-11-20"
MockDate.set(expectedDate)
prependDatedEntry(exampleEntry, testTargetPath)
const newContents = fs.readFileSync(testTargetPath, 'utf8')
// reset the file:
fs.writeFileSync(testTargetPath, previousContents)
const expectedDate = (new Date()).toISOString().split('T')[0]
expect(exampleEntry).toEqual({ someStuff: true, date: expectedDate })
expect(newContents).toMatchSnapshot()
expect(JSON.parse(newContents)).toEqual(expectedUpdatedChangelogFile)
})
})