-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2c8fdd3
commit 4606e3e
Showing
1 changed file
with
18 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,33 @@ | ||
import { safeExec } from '@fuel-ts/errors/test-utils'; | ||
import { execSync } from 'child_process'; | ||
import type { BinaryToTextEncoding } from 'crypto'; | ||
import { createHash } from 'crypto'; | ||
import { readFile } from 'fs/promises'; | ||
|
||
const FUEL_CORE_SCHEMA_FILE_PATH = 'packages/account/src/providers/fuel-core-schema.graphql'; | ||
const FUEL_CORE_SCHEMA_SYNC_COMMAND = 'pnpm --filter @fuel-ts/account build:schema'; | ||
|
||
/** | ||
* @group node | ||
*/ | ||
function generateChecksum( | ||
utf8: Buffer, | ||
algorithm: string = 'md5', | ||
encoding: BinaryToTextEncoding = 'hex' | ||
) { | ||
return createHash(algorithm || 'md5') | ||
.update(utf8.toString(), 'utf8') | ||
.digest(encoding || 'hex'); | ||
} | ||
|
||
describe('fuel-core-schema.graphql', () => { | ||
it('should not change on schema build', async () => { | ||
const preSyncSchema = await readFile(FUEL_CORE_SCHEMA_FILE_PATH); | ||
const preSyncChecksum = await readFile(FUEL_CORE_SCHEMA_FILE_PATH).then(generateChecksum); | ||
|
||
await safeExec(() => execSync(FUEL_CORE_SCHEMA_SYNC_COMMAND)); | ||
|
||
const postSyncSchema = await readFile(FUEL_CORE_SCHEMA_FILE_PATH); | ||
const postSyncChecksum = await readFile(FUEL_CORE_SCHEMA_FILE_PATH).then(generateChecksum); | ||
|
||
expect(preSyncSchema.toString()).toEqual(postSyncSchema.toString()); | ||
expect( | ||
preSyncChecksum, | ||
`\nThe schema at ${FUEL_CORE_SCHEMA_FILE_PATH} is not in sync with fuel-core.\n\nRun '${FUEL_CORE_SCHEMA_SYNC_COMMAND}' to update it.\n\n` | ||
).toEqual(postSyncChecksum); | ||
}); | ||
}); |