diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000..578e137 --- /dev/null +++ b/jest.config.js @@ -0,0 +1,7 @@ +module.exports = { + transform: { + '^.+\\.ts?$': ['ts-jest', { tsconfig: './tsconfig.jest.json' }], + }, + testRegex: '/test/.*\\.test?\\.ts$', + moduleFileExtensions: ['ts', 'js'], + }; diff --git a/test/crc.test.ts b/test/crc.test.ts new file mode 100644 index 0000000..257597a --- /dev/null +++ b/test/crc.test.ts @@ -0,0 +1,17 @@ +import {expect, test} from '@jest/globals'; + +import { crc32 } from "../src/crc32"; + +describe('crc module', () => { + test('crc for a simple string is correct', async () => { + const something = "something"; + var blob = new Blob([something], { + type: 'text/plain' + }); + + const buffer = await new Response(blob).arrayBuffer(); + const bytes = new Uint8Array(buffer); + + expect(crc32(bytes)).toBe(0x9DA31FB); + }); +}); diff --git a/tsconfig.jest.json b/tsconfig.jest.json new file mode 100644 index 0000000..6b380f4 --- /dev/null +++ b/tsconfig.jest.json @@ -0,0 +1,6 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "verbatimModuleSyntax": false + } + }