|
1 | 1 | const yaml = require('js-yaml') |
2 | 2 | const { createChangelogEntry, cleanPreviewTitle, previewAnchor, prependDatedEntry } = require('../../script/graphql/build-changelog') |
3 | 3 | const fs = require('fs') |
| 4 | +const MockDate = require("mockdate") |
| 5 | +const expectedChangelogEntry = require('../fixtures/changelog-entry') |
| 6 | +const expectedUpdatedChangelogFile = require('../fixtures/updated-changelog-file') |
4 | 7 |
|
5 | 8 | describe('creating a changelog from old schema and new schema', () => { |
| 9 | + afterEach(() => { |
| 10 | + MockDate.reset() |
| 11 | + }) |
| 12 | + |
6 | 13 | it('finds a diff of schema changes, upcoming changes, and preview changes', async () => { |
7 | 14 | const oldSchemaString = ` |
8 | 15 | type PreviewType { |
@@ -68,7 +75,7 @@ upcoming_changes: |
68 | 75 | `).upcoming_changes |
69 | 76 |
|
70 | 77 | const entry = await createChangelogEntry(oldSchemaString, newSchemaString, previews, oldUpcomingChanges, newUpcomingChanges) |
71 | | - expect(entry).toMatchSnapshot() |
| 78 | + expect(entry).toEqual(expectedChangelogEntry) |
72 | 79 | }) |
73 | 80 |
|
74 | 81 | it('returns null when there isnt any difference', async () => { |
@@ -100,18 +107,25 @@ describe('Preparing preview links', () => { |
100 | 107 | }) |
101 | 108 |
|
102 | 109 | describe('updating the changelog file', () => { |
| 110 | + afterEach(() => { |
| 111 | + MockDate.reset() |
| 112 | + }) |
| 113 | + |
103 | 114 | it('modifies the entry object and the file on disk', () => { |
104 | 115 | const testTargetPath = 'tests/graphql/example_changelog.json' |
105 | 116 | const previousContents = fs.readFileSync(testTargetPath) |
106 | 117 |
|
107 | 118 | const exampleEntry = { someStuff: true } |
| 119 | + const expectedDate = "2020-11-20" |
| 120 | + MockDate.set(expectedDate) |
| 121 | + |
108 | 122 | prependDatedEntry(exampleEntry, testTargetPath) |
109 | 123 | const newContents = fs.readFileSync(testTargetPath, 'utf8') |
110 | 124 | // reset the file: |
111 | 125 | fs.writeFileSync(testTargetPath, previousContents) |
112 | 126 |
|
113 | | - const expectedDate = (new Date()).toISOString().split('T')[0] |
| 127 | + |
114 | 128 | expect(exampleEntry).toEqual({ someStuff: true, date: expectedDate }) |
115 | | - expect(newContents).toMatchSnapshot() |
| 129 | + expect(JSON.parse(newContents)).toEqual(expectedUpdatedChangelogFile) |
116 | 130 | }) |
117 | 131 | }) |
0 commit comments