Skip to content

Commit

Permalink
chore: cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
OR13 committed Jan 22, 2022
1 parent 399c265 commit 303ecf7
Show file tree
Hide file tree
Showing 5 changed files with 12,517 additions and 10,510 deletions.
22 changes: 22 additions & 0 deletions packages/json-web-signature/custom-jest-node-environment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// From https://github.com/facebook/jest/issues/7780#issuecomment-615890410
const NodeEnvironment = require("jest-environment-node");

class MyEnvironment extends NodeEnvironment {
constructor(config) {
super(
Object.assign({}, config, {
globals: Object.assign({}, config.globals, {
Uint32Array: Uint32Array,
Uint8Array: Uint8Array,
ArrayBuffer: ArrayBuffer,
}),
})
);
}

async setup() {}

async teardown() {}
}

module.exports = MyEnvironment;
7 changes: 4 additions & 3 deletions packages/json-web-signature/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
moduleNameMapper: {
'^jose/(.*)$': '<rootDir>/node_modules/jose/dist/node/cjs/$1',
},
// We cannot use testEnvironment: 'node' because jest breaks Buffer / byte arrays necessary for crypto operations
// We cannot use testEnvironment: 'jsdom' because mongoose (see https://mongoosejs.com/docs/jest.html)
// Therefore we use a custom node environment without the broken Buffer classes
testEnvironment: './custom-jest-node-environment.js',
};
Loading

0 comments on commit 303ecf7

Please sign in to comment.