Skip to content

Commit

Permalink
jest: ensure Buffer instanceof Uint8Array
Browse files Browse the repository at this point in the history
  • Loading branch information
yoursunny committed Sep 24, 2019
1 parent 19eed49 commit d191172
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 31 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const path = require("path");

module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testEnvironment: './mk/jest-env/node',

moduleFileExtensions: ['ts', 'js'],
moduleNameMapper: {
Expand Down
10 changes: 10 additions & 0 deletions mk/jest-env/node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const NodeEnvironment = require("jest-environment-node");

class MyEnvironment extends NodeEnvironment {
async setup() {
await super.setup();
this.global.Uint8Array = Uint8Array;
}
}

module.exports = MyEnvironment;
6 changes: 0 additions & 6 deletions packages/tlv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,5 @@
"publishConfig": {
"main": "lib/index.js",
"types": "lib/index.d.ts"
},
"dependencies": {
"is-buffer": "^2.0.3"
},
"devDependencies": {
"@types/is-buffer": "^2.0.0"
}
}
5 changes: 0 additions & 5 deletions packages/tlv/src/decoder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import isBuffer from "is-buffer";

export interface Decodable<R> {
decodeFrom(decoder: Decoder): R;
}
Expand Down Expand Up @@ -52,9 +50,6 @@ export class Decoder {
private offset: number = 0;

constructor(private input: Uint8Array) {
if (isBuffer(input)) {
this.input = new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
}
}

/** Read TLV structure. */
Expand Down
20 changes: 1 addition & 19 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d191172

Please sign in to comment.