- This brings in the flow test suite that contains a ton of JavaScript parsing edge cases - This creates snapshot tests using the pretty printer for all of them - If uncomment `RUN_AST_TESTS` line in `tests/run_specs.js`, it checks ast(pretty_print(x)) == ast(x). Right now, "178 failed, 197 passed, 375 of 377 total". So half of the tests are not passing, most of them are crashes and many of the rest are subtle issues.
39 lines
1.0 KiB
JavaScript
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
|
|
}
|
|
]
|