Skip to content

Commit

Permalink
fix: remove encoder and decoder polyfill (#3167)
Browse files Browse the repository at this point in the history
  • Loading branch information
stepan662 authored Feb 24, 2023
1 parent e14199f commit fe39cfb
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 100 deletions.
1 change: 1 addition & 0 deletions packages/i18next/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export default {
preset: 'ts-jest',
testEnvironment: 'jsdom',
roots: ['src'],
setupFiles: ['../testing/setupJest.ts'],
unmockedModulePathPatterns: [
'<rootDir>/src/__testFixtures/*',
'/node_modules/*',
Expand Down
1 change: 1 addition & 0 deletions packages/ngx/projects/ngx-tolgee/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
prefix: '<rootDir>/../../',
}),
setupFiles: ['../../../testing/setupJest.ts'],
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
Expand Down
1 change: 1 addition & 0 deletions packages/react/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default {
modulePathIgnorePatterns: ['cypress'],
transformIgnorePatterns: ['node_modules/(?!@tolgee/web)'],
roots: ['src'],
setupFiles: ['../testing/setupJest.ts'],
globals: {
'ts-jest': {
tsconfig: 'tsconfig.spec.json',
Expand Down
1 change: 1 addition & 0 deletions packages/svelte/jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ module.exports = {
'<rootDir>/.svelte-kit/build/runtime/app$1',
],
},
setupFiles: ['../testing/setupJest.ts'],
setupFilesAfterEnv: ['<rootDir>/jest-setup.ts'],
};
5 changes: 5 additions & 0 deletions packages/testing/setupJest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { TextEncoder, TextDecoder } from 'util';
// polyfill TextEncoder and TextDecoder as it is supported in browsers but not present in node
global.TextEncoder = TextEncoder;
// @ts-ignore
global.TextDecoder = TextDecoder;
1 change: 1 addition & 0 deletions packages/vue/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default {
transform: {
'^.+\\.vue$': '@vue/vue3-jest',
},
setupFiles: ['../testing/setupJest.ts'],
testEnvironmentOptions: {
customExportConditions: ['node', 'node-addons'],
},
Expand Down
1 change: 1 addition & 0 deletions packages/web/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export default {
moduleNameMapper: {
'@testFixtures/(.*)': '<rootDir>/src/__testFixtures/$1',
},
setupFiles: ['../testing/setupJest.ts'],
roots: ['src'],
};
96 changes: 0 additions & 96 deletions packages/web/src/observers/invisible/encoderPolyfill.ts

This file was deleted.

6 changes: 2 additions & 4 deletions packages/web/src/observers/invisible/secret.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Encoder, Decoder } from './encoderPolyfill';

export const INVISIBLE_CHARACTERS = ['\u200C', '\u200D'];

export const INVISIBLE_REGEX = RegExp(
Expand All @@ -8,11 +6,11 @@ export const INVISIBLE_REGEX = RegExp(
);

const toBytes = (text: string) => {
return Array.from(new Encoder().encode(text));
return Array.from(new TextEncoder().encode(text));
};

const fromBytes = (bytes: Iterable<number>) => {
return new Decoder().decode(new Uint8Array(bytes));
return new TextDecoder().decode(new Uint8Array(bytes));
};

const padToWholeBytes = (binary: string) => {
Expand Down

0 comments on commit fe39cfb

Please sign in to comment.