-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: Change testing to use cjs. #636
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"verbose": true, | ||
"testEnvironment": "jest-environment-jsdom", | ||
"testPathIgnorePatterns": ["./dist", "./src"], | ||
"testMatch": ["**.test.ts"], | ||
"setupFiles": ["./setup-jest.js"], | ||
"transform": { | ||
"^.+\\.ts$": [ | ||
"ts-jest", | ||
{ | ||
"tsConfig": "tsconfig.test.json" | ||
} | ||
], | ||
"^.+.tsx?$": ["ts-jest", {}] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,14 +30,12 @@ | |
"build": "tsc --noEmit && rollup -c rollup.config.js", | ||
"lint": "eslint . --ext .ts,.tsx", | ||
"prettier": "prettier --write '**/*.@(js|ts|tsx|json|css)' --ignore-path ../../../.prettierignore", | ||
"test": "NODE_OPTIONS=--experimental-vm-modules npx jest --runInBand", | ||
"test": "npx jest --runInBand", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No longer require experimental options. One of the many benefits is that I can get the debugger to work for this package now. |
||
"coverage": "yarn test --coverage", | ||
"check": "yarn prettier && yarn lint && yarn build && yarn test" | ||
}, | ||
"dependencies": { | ||
"@launchdarkly/js-client-sdk-common": "1.10.0", | ||
"escape-string-regexp": "^5.0.0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This package is ESM only, just vendoring it removes that as a factor in the builds. |
||
"rollup-plugin-visualizer": "^5.12.0" | ||
"@launchdarkly/js-client-sdk-common": "1.10.0" | ||
}, | ||
"devDependencies": { | ||
"@jest/globals": "^29.7.0", | ||
|
@@ -62,6 +60,7 @@ | |
"prettier": "^3.0.0", | ||
"rimraf": "^5.0.5", | ||
"rollup": "^3.23.0", | ||
"rollup-plugin-visualizer": "^5.12.0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should have been a dev dependency to begin with. |
||
"ts-jest": "^29.1.1", | ||
"typedoc": "0.25.0", | ||
"typescript": "^5.5.3" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const { TextEncoder, TextDecoder } = require('node:util'); | ||
const crypto = require('node:crypto'); | ||
|
||
global.TextEncoder = TextEncoder; | ||
|
||
Object.assign(window, { TextDecoder, TextEncoder }); | ||
|
||
// Based on: | ||
// https://stackoverflow.com/a/71750830 | ||
|
||
Object.defineProperty(global.self, 'crypto', { | ||
value: { | ||
getRandomValues: (arr) => crypto.randomBytes(arr.length), | ||
subtle: { | ||
digest: (algorithm, data) => { | ||
return new Promise((resolve) => | ||
resolve( | ||
crypto.createHash(algorithm.toLowerCase().replace('-', '')).update(data).digest(), | ||
), | ||
); | ||
}, | ||
}, | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// From here: https://github.com/sindresorhus/escape-string-regexp | ||
|
||
// This is vendored to reduce the complexity of the built and test setup. | ||
// The NPM package for escape-string-regexp is ESM only, and that introduces | ||
// complexity to the jest configuration which works best/easiest with CJS. | ||
|
||
/** | ||
* MIT License | ||
* | ||
* Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com) | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
* | ||
*/ | ||
|
||
/** | ||
* Escape regular expression especial characters. | ||
* | ||
* @param string The regular expression to escape. | ||
* @returns The escaped expression. | ||
*/ | ||
export default function escapeStringRegexp(string: string) { | ||
if (typeof string !== 'string') { | ||
throw new TypeError('Expected a string'); | ||
} | ||
|
||
// Escape characters with special meaning either inside or outside character sets. | ||
// Use a simple backslash escape when it’s always valid, and a `\xnn` escape when the simpler form would be disallowed by Unicode patterns’ stricter grammar. | ||
return string.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d'); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"compilerOptions": { | ||
"rootDir": "src", | ||
"outDir": "dist", | ||
"lib": ["es6", "DOM"], | ||
"module": "CommonJS", | ||
"strict": true, | ||
"noImplicitOverride": true, | ||
"sourceMap": true, | ||
"declaration": true, | ||
"declarationMap": true, | ||
"stripInternal": true | ||
}, | ||
"exclude": [ | ||
"vite.config.ts", | ||
"__tests__", | ||
"dist", | ||
"docs", | ||
"example", | ||
"node_modules", | ||
"contract-tests", | ||
"babel.config.js", | ||
"jest.config.js", | ||
"jestSetupFile.ts", | ||
"**/*.test.ts*" | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put the TextEncoder and a crypto fix into a setup script.