Skip to content

Commit

Permalink
chore: updated test to use checksum
Browse files Browse the repository at this point in the history
  • Loading branch information
petertonysmith94 committed Jun 26, 2024
1 parent 2c8fdd3 commit 4606e3e
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions packages/account/test/fuel-core-schema.test.ts
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);
});
});

0 comments on commit 4606e3e

Please sign in to comment.