Files
test-repo/tests/flow/node_tests/crypto/crypto.js
T
Christopher Chedeau 3375cfe605 Move tests around (#454)
* new_tests

* move_all_clobbered_tests

* remove all the tests that no longer exist

* re-run flow tests

* Move all the flow tests to tests/flow and prettier to tests/

* Move prettier tests to their own folders

* Add jsfmt files

* run prettier snapshot tests
2017-01-24 14:35:37 -08:00

39 lines
1.0 KiB
JavaScript

/* @flow */
const crypto = require('crypto');
let tests = [
// Hmac is a duplex stream
function() {
const hmac = crypto.createHmac('sha256', 'a secret');
hmac.on('readable', () => {
(hmac.read(): ?(string | Buffer));
(hmac.read(): number); // 4 errors: null, void, string, Buffer
});
hmac.write('some data to hash');
hmac.write(123); // 2 errors: not a string or a Buffer
hmac.end();
},
// Hmac supports update and digest functions too
function(buf: Buffer) {
const hmac = crypto.createHmac('sha256', 'a secret');
hmac.update('some data to hash');
hmac.update('foo', 'utf8');
hmac.update('foo', 'bogus'); // 1 error
hmac.update(buf);
hmac.update(buf, 'utf8'); // 1 error: no encoding when passing a buffer
// it's also chainable
(hmac.update('some data to hash').update(buf).digest(): Buffer);
(hmac.digest('hex'): string);
(hmac.digest(): Buffer);
(hmac.digest('hex'): void); // 1 error
(hmac.digest(): void); // 1 error
}
]