diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ac4d97d3e95..388e3585043e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ ### Chore & Maintenance +- `[*]` Replaced `substr` method with `substring` ([#12066](https://github.com/facebook/jest/pull/12066)) + ### Performance ## 27.3.1 diff --git a/packages/jest-config/src/utils.ts b/packages/jest-config/src/utils.ts index 869e60897d7e..9958f6b6bcaf 100644 --- a/packages/jest-config/src/utils.ts +++ b/packages/jest-config/src/utils.ts @@ -65,7 +65,7 @@ export const replaceRootDirInPath = ( return path.resolve( rootDir, - path.normalize('./' + filePath.substr(''.length)), + path.normalize('./' + filePath.substring(''.length)), ); }; diff --git a/packages/jest-haste-map/src/lib/fast_path.ts b/packages/jest-haste-map/src/lib/fast_path.ts index 39e3e1812387..ea1d0c11ef8d 100644 --- a/packages/jest-haste-map/src/lib/fast_path.ts +++ b/packages/jest-haste-map/src/lib/fast_path.ts @@ -10,7 +10,7 @@ import * as path from 'path'; // rootDir and filename must be absolute paths (resolved) export function relative(rootDir: string, filename: string): string { return filename.indexOf(rootDir + path.sep) === 0 - ? filename.substr(rootDir.length + 1) + ? filename.substring(rootDir.length + 1) : path.relative(rootDir, filename); } diff --git a/packages/jest-haste-map/src/worker.ts b/packages/jest-haste-map/src/worker.ts index 7422bb5643fc..4a53879e6ae4 100644 --- a/packages/jest-haste-map/src/worker.ts +++ b/packages/jest-haste-map/src/worker.ts @@ -63,7 +63,7 @@ export async function worker(data: WorkerMessage): Promise { } catch (err: any) { throw new Error(`Cannot parse ${filePath} as JSON: ${err.message}`); } - } else if (!blacklist.has(filePath.substr(filePath.lastIndexOf('.')))) { + } else if (!blacklist.has(filePath.substring(filePath.lastIndexOf('.')))) { // Process a random file that is returned as a MODULE. if (hasteImpl) { id = hasteImpl.getHasteName(filePath); diff --git a/packages/jest-snapshot/src/index.ts b/packages/jest-snapshot/src/index.ts index d9c7fed4dc38..58bae0a9d0b8 100644 --- a/packages/jest-snapshot/src/index.ts +++ b/packages/jest-snapshot/src/index.ts @@ -99,7 +99,7 @@ function stripAddedIndentation(inlineSnapshot: string) { return inlineSnapshot; } - lines[i] = lines[i].substr(indentation.length); + lines[i] = lines[i].substring(indentation.length); } } diff --git a/packages/jest-transform/src/ScriptTransformer.ts b/packages/jest-transform/src/ScriptTransformer.ts index b643eaf91857..7e17f65822e5 100644 --- a/packages/jest-transform/src/ScriptTransformer.ts +++ b/packages/jest-transform/src/ScriptTransformer.ts @@ -876,9 +876,9 @@ function readCodeCacheFile(cachePath: Config.Path): string | null { if (content == null) { return null; } - const code = content.substr(33); + const code = content.substring(33); const checksum = createHash('md5').update(code).digest('hex'); - if (checksum === content.substr(0, 32)) { + if (checksum === content.substring(0, 32)) { return code; } return null;