Skip to content

Commit

Permalink
test: colocate tests and improve test description
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Jun 15, 2023
1 parent c1141f9 commit e6a2c98
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 22 deletions.
9 changes: 0 additions & 9 deletions __tests__/__snapshots__/index.test.ts.snap

This file was deleted.

8 changes: 4 additions & 4 deletions module/browser.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@ describe('browser', () => {
assert.strictEqual(typeof digest, 'function');
});

it('returns "SHA-1"', async () => {
it('hashes message with algorithm "SHA-1"', async () => {
assert.strictEqual(
await digest('SHA-1', ''),
'da39a3ee5e6b4b0d3255bfef95601890afd80709'
);
});

it('returns "SHA-256"', async () => {
it('hashes message with algorithm "SHA-256"', async () => {
assert.strictEqual(
await digest('SHA-256', ''),
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
);
});

it('returns "SHA-384"', async () => {
it('hashes message with algorithm "SHA-384"', async () => {
assert.strictEqual(
await digest('SHA-384', ''),
'38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b'
);
});

it('returns "SHA-512"', async () => {
it('hashes message with algorithm "SHA-512"', async () => {
assert.strictEqual(
await digest('SHA-384', ''),
'38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b'
Expand Down
8 changes: 4 additions & 4 deletions module/index.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@ describe('index', () => {
assert.strictEqual(typeof digest, 'function');
});

it('returns "SHA-1"', async () => {
it('hashes message with algorithm "SHA-1"', async () => {
assert.strictEqual(
await digest('SHA-1', ''),
'da39a3ee5e6b4b0d3255bfef95601890afd80709'
);
});

it('returns "SHA-256"', async () => {
it('hashes message with algorithm "SHA-256"', async () => {
assert.strictEqual(
await digest('SHA-256', ''),
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
);
});

it('returns "SHA-384"', async () => {
it('hashes message with algorithm "SHA-384"', async () => {
assert.strictEqual(
await digest('SHA-384', ''),
'38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b'
);
});

it('returns "SHA-512"', async () => {
it('hashes message with algorithm "SHA-512"', async () => {
assert.strictEqual(
await digest('SHA-384', ''),
'38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b'
Expand Down
9 changes: 9 additions & 0 deletions src/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`digest hashes message with algorithm "SHA-1" 1`] = `"da39a3ee5e6b4b0d3255bfef95601890afd80709"`;

exports[`digest hashes message with algorithm "SHA-256" 1`] = `"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"`;

exports[`digest hashes message with algorithm "SHA-384" 1`] = `"38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b"`;

exports[`digest hashes message with algorithm "SHA-512" 1`] = `"cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"`;
6 changes: 2 additions & 4 deletions __tests__/index.test.ts → src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { digest } from '../src/index.ts';
import { digest } from './index';

describe('digest', () => {
it.each(['SHA-1', 'SHA-256', 'SHA-384', 'SHA-512'] as const)(
'hashes message with algorithm %s',
'hashes message with algorithm "%s"',
async (algorithm) => {
expect(await digest(algorithm, '')).toMatchSnapshot();
}
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
"strict": true,
"outDir": "lib"
},
"include": ["src"]
"include": ["src"],
"exclude": ["node_modules", "src/**/*.test.ts"]
}

0 comments on commit e6a2c98

Please sign in to comment.