Move tests to TypeScript (coverage is still JS based)

This commit is contained in:
junderw 2019-09-07 13:42:03 +09:00
parent 11e4a12caf
commit 6c08a0be40
No known key found for this signature in database
GPG key ID: B256185D3A971908
41 changed files with 3920 additions and 2712 deletions

View file

@ -1,49 +1,49 @@
const { describe, it } = require('mocha')
const assert = require('assert')
const bufferutils = require('../src/bufferutils')
import * as assert from 'assert';
import { describe, it } from 'mocha';
import * as bufferutils from '../src/bufferutils';
const fixtures = require('./fixtures/bufferutils.json')
import * as fixtures from './fixtures/bufferutils.json';
describe('bufferutils', () => {
describe('readUInt64LE', () => {
fixtures.valid.forEach(f => {
it('decodes ' + f.hex, () => {
const buffer = Buffer.from(f.hex, 'hex')
const number = bufferutils.readUInt64LE(buffer, 0)
const buffer = Buffer.from(f.hex, 'hex');
const number = bufferutils.readUInt64LE(buffer, 0);
assert.strictEqual(number, f.dec)
})
})
assert.strictEqual(number, f.dec);
});
});
fixtures.invalid.readUInt64LE.forEach(f => {
it('throws on ' + f.description, () => {
const buffer = Buffer.from(f.hex, 'hex')
const buffer = Buffer.from(f.hex, 'hex');
assert.throws(() => {
bufferutils.readUInt64LE(buffer, 0)
}, new RegExp(f.exception))
})
})
})
bufferutils.readUInt64LE(buffer, 0);
}, new RegExp(f.exception));
});
});
});
describe('writeUInt64LE', () => {
fixtures.valid.forEach(f => {
it('encodes ' + f.dec, () => {
const buffer = Buffer.alloc(8, 0)
const buffer = Buffer.alloc(8, 0);
bufferutils.writeUInt64LE(buffer, f.dec, 0)
assert.strictEqual(buffer.toString('hex'), f.hex)
})
})
bufferutils.writeUInt64LE(buffer, f.dec, 0);
assert.strictEqual(buffer.toString('hex'), f.hex);
});
});
fixtures.invalid.readUInt64LE.forEach(f => {
it('throws on ' + f.description, () => {
const buffer = Buffer.alloc(8, 0)
const buffer = Buffer.alloc(8, 0);
assert.throws(() => {
bufferutils.writeUInt64LE(buffer, f.dec, 0)
}, new RegExp(f.exception))
})
})
})
})
bufferutils.writeUInt64LE(buffer, f.dec, 0);
}, new RegExp(f.exception));
});
});
});
});