diff --git a/jest.config.js b/jest.config.js index 78764901f0..2987677a30 100644 --- a/jest.config.js +++ b/jest.config.js @@ -13,7 +13,7 @@ module.exports = { '!/src/**/*.spec.ts', '!/src/**/*.test.ts', '!/src/**/__*__/*', - '!/src/util/testing.ts', + '!/src/utils/testing.ts', ], snapshotSerializers: ['/src/__serializers__/processed-source.ts'], cacheDirectory: '/.cache/unit', diff --git a/src/__helpers__/fakers.ts b/src/__helpers__/fakers.ts index b6f0a56722..cf72549996 100644 --- a/src/__helpers__/fakers.ts +++ b/src/__helpers__/fakers.ts @@ -4,7 +4,7 @@ import { resolve } from 'path' import { createCompilerInstance } from '../compiler/instance' import { ConfigSet } from '../config/config-set' import type { BabelConfig, TsCompiler, TsJestConfig, TsJestGlobalOptions } from '../types' -import type { ImportReasons } from '../util/messages' +import type { ImportReasons } from '../utils/messages' export function filePath(relPath: string): string { return resolve(__dirname, '..', '..', relPath) diff --git a/src/__helpers__/mocks.ts b/src/__helpers__/mocks.ts index de96029947..616aeeca97 100644 --- a/src/__helpers__/mocks.ts +++ b/src/__helpers__/mocks.ts @@ -1,6 +1,6 @@ import type { testing } from 'bs-logger' -import { rootLogger } from '../util/logger' +import { rootLogger } from '../utils/logger' export const logTargetMock = (): testing.LogTargetMock => (rootLogger as testing.LoggerMock).target diff --git a/src/__helpers__/setup.ts b/src/__helpers__/setup.ts index a0fd1e342d..894a2a1a09 100644 --- a/src/__helpers__/setup.ts +++ b/src/__helpers__/setup.ts @@ -1 +1 @@ -jest.mock('../util/logger') +jest.mock('../utils/logger') diff --git a/src/cli/cli.spec.ts b/src/cli/cli.spec.ts index 85cbfb3d0f..4f8a302dba 100644 --- a/src/cli/cli.spec.ts +++ b/src/cli/cli.spec.ts @@ -1,7 +1,7 @@ import * as _fs from 'fs' import { normalize, resolve } from 'path' -import { mocked } from '../../utils' +import { mocked } from '../utils' import { logTargetMock, mockObject, mockWriteStream } from '../__helpers__/mocks' import { processArgv } from '.' diff --git a/src/cli/config/migrate.ts b/src/cli/config/migrate.ts index 104a43f565..4d98380f4d 100644 --- a/src/cli/config/migrate.ts +++ b/src/cli/config/migrate.ts @@ -7,7 +7,7 @@ import { basename, resolve } from 'path' import type { Arguments } from 'yargs' import type { CliCommand } from '..' -import { backportJestConfig } from '../../util/backports' +import { backportJestConfig } from '../../utils/backports' import { JestPresetNames, TsJestPresetDescriptor, allPresets, defaults } from '../helpers/presets' /** diff --git a/src/cli/index.ts b/src/cli/index.ts index 452908833f..313da2c70b 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -2,7 +2,7 @@ import { LogContexts, Logger } from 'bs-logger' import type { Arguments } from 'yargs' import * as yargsParser from 'yargs-parser' -import { rootLogger } from '../util/logger' +import { rootLogger } from '../utils/logger' const VALID_COMMANDS = ['help', 'config:migrate', 'config:init'] diff --git a/src/compiler/instance.ts b/src/compiler/instance.ts index 589423b77b..a17dac7f8e 100644 --- a/src/compiler/instance.ts +++ b/src/compiler/instance.ts @@ -5,7 +5,7 @@ import type { CompileFn, CompilerInstance, TsCompiler } from '../types' import { initializeLanguageServiceInstance } from './language-service' import { initializeTranspilerInstance } from './transpiler' -import { stringify } from '../util/json' +import { stringify } from '../utils/json' /** * Rely on TypeScript compiled output generation which contains this prefix to point to sourcemap location. diff --git a/src/compiler/language-service.ts b/src/compiler/language-service.ts index 852c02c70f..323d23a467 100644 --- a/src/compiler/language-service.ts +++ b/src/compiler/language-service.ts @@ -8,10 +8,10 @@ import type * as _ts from 'typescript' import type { ConfigSet } from '../config/config-set' import { LINE_FEED } from '../constants' import type { CompilerInstance, SourceOutput } from '../types' -import { Errors, interpolate } from '../util/messages' +import { Errors, interpolate } from '../utils/messages' -import { parse, stringify } from '../util/json' -import { sha1 } from '../util/sha1' +import { parse, stringify } from '../utils/json' +import { sha1 } from '../utils/sha1' /** where key is filepath */ type TSFiles = Map diff --git a/src/config/config-set.spec.ts b/src/config/config-set.spec.ts index dee08dfc52..5a72eeab94 100644 --- a/src/config/config-set.spec.ts +++ b/src/config/config-set.spec.ts @@ -8,19 +8,19 @@ import * as _myModule from '..' import { logTargetMock } from '../__helpers__/mocks' import { createConfigSet, defaultResolve } from '../__helpers__/fakers' import type { TsJestGlobalOptions } from '../types' -import * as _backports from '../util/backports' -import { getPackageVersion } from '../util/get-package-version' -import { normalizeSlashes } from '../util/normalize-slashes' -import { mocked } from '../util' +import * as _backports from '../utils/backports' +import { getPackageVersion } from '../utils/get-package-version' +import { normalizeSlashes } from '../utils/normalize-slashes' +import { mocked } from '../utils' import { IGNORE_DIAGNOSTIC_CODES, MATCH_NOTHING, TS_JEST_OUT_DIR } from './config-set' // eslint-disable-next-line no-duplicate-imports import type { ConfigSet } from './config-set' -import { Deprecations } from '../util/messages' +import { Deprecations } from '../utils/messages' -jest.mock('../util/backports') +jest.mock('../utils/backports') jest.mock('../index') -jest.mock('../util/get-package-version') +jest.mock('../utils/get-package-version') const backports = mocked(_backports) const myModule = mocked(_myModule) diff --git a/src/config/config-set.ts b/src/config/config-set.ts index 8df6c24d11..a57b441ae3 100644 --- a/src/config/config-set.ts +++ b/src/config/config-set.ts @@ -42,17 +42,17 @@ import type { TsJestHooksMap, TTypeScript, } from '../types' -import { backportJestConfig } from '../util/backports' -import { getPackageVersion } from '../util/get-package-version' -import { importer } from '../util/importer' -import { stringify } from '../util/json' -import { JsonableValue } from '../util/jsonable-value' -import { rootLogger } from '../util/logger' -import { Memoize } from '../util/memoize' -import { Deprecations, Errors, ImportReasons, interpolate } from '../util/messages' -import { normalizeSlashes } from '../util/normalize-slashes' -import { sha1 } from '../util/sha1' -import { TSError } from '../util/ts-error' +import { backportJestConfig } from '../utils/backports' +import { getPackageVersion } from '../utils/get-package-version' +import { importer } from '../utils/importer' +import { stringify } from '../utils/json' +import { JsonableValue } from '../utils/jsonable-value' +import { rootLogger } from '../utils/logger' +import { Memoize } from '../utils/memoize' +import { Deprecations, Errors, ImportReasons, interpolate } from '../utils/messages' +import { normalizeSlashes } from '../utils/normalize-slashes' +import { sha1 } from '../utils/sha1' +import { TSError } from '../utils/ts-error' const logger = rootLogger.child({ namespace: 'config' }) diff --git a/src/config/create-jest-preset.ts b/src/config/create-jest-preset.ts index 33aabefa15..50ea91f571 100644 --- a/src/config/create-jest-preset.ts +++ b/src/config/create-jest-preset.ts @@ -1,6 +1,6 @@ import type { Config } from '@jest/types' -import { rootLogger } from '../util/logger' +import { rootLogger } from '../utils/logger' const logger = rootLogger.child({ namespace: 'jest-preset' }) diff --git a/src/config/paths-to-module-name-mapper.spec.ts b/src/config/paths-to-module-name-mapper.spec.ts index a88301355c..c4d7763dd8 100644 --- a/src/config/paths-to-module-name-mapper.spec.ts +++ b/src/config/paths-to-module-name-mapper.spec.ts @@ -3,10 +3,10 @@ import { logTargetMock } from '../__helpers__/mocks' import { pathsToModuleNameMapper } from './paths-to-module-name-mapper' const tsconfigMap = { - log: ['src/util/log'], + log: ['src/utils/log'], server: ['src/server'], client: ['src/client', 'src/client/index'], - 'util/*': ['src/util/*'], + 'util/*': ['src/utils/*'], 'api/*': ['src/api/*'], 'test/*': ['test/*'], 'mocks/*': ['test/mocks/*'], @@ -16,44 +16,44 @@ const tsconfigMap = { describe('pathsToModuleNameMapper', () => { it('should convert tsconfig mapping', () => { expect(pathsToModuleNameMapper(tsconfigMap)).toMatchInlineSnapshot(` -Object { - "^api/(.*)$": "src/api/$1", - "^client$": Array [ - "src/client", - "src/client/index", - ], - "^log$": "src/util/log", - "^mocks/(.*)$": "test/mocks/$1", - "^server$": "src/server", - "^test/(.*)$": "test/$1", - "^test/(.*)/mock$": Array [ - "test/mocks/$1", - "test/__mocks__/$1", - ], - "^util/(.*)$": "src/util/$1", -} -`) + Object { + "^api/(.*)$": "src/api/$1", + "^client$": Array [ + "src/client", + "src/client/index", + ], + "^log$": "src/utils/log", + "^mocks/(.*)$": "test/mocks/$1", + "^server$": "src/server", + "^test/(.*)$": "test/$1", + "^test/(.*)/mock$": Array [ + "test/mocks/$1", + "test/__mocks__/$1", + ], + "^util/(.*)$": "src/utils/$1", + } + `) }) it('should use the given prefix', () => { expect(pathsToModuleNameMapper(tsconfigMap, { prefix: '/' })).toMatchInlineSnapshot(` -Object { - "^api/(.*)$": "/src/api/$1", - "^client$": Array [ - "/src/client", - "/src/client/index", - ], - "^log$": "/src/util/log", - "^mocks/(.*)$": "/test/mocks/$1", - "^server$": "/src/server", - "^test/(.*)$": "/test/$1", - "^test/(.*)/mock$": Array [ - "/test/mocks/$1", - "/test/__mocks__/$1", - ], - "^util/(.*)$": "/src/util/$1", -} -`) + Object { + "^api/(.*)$": "/src/api/$1", + "^client$": Array [ + "/src/client", + "/src/client/index", + ], + "^log$": "/src/utils/log", + "^mocks/(.*)$": "/test/mocks/$1", + "^server$": "/src/server", + "^test/(.*)$": "/test/$1", + "^test/(.*)/mock$": Array [ + "/test/mocks/$1", + "/test/__mocks__/$1", + ], + "^util/(.*)$": "/src/utils/$1", + } + `) }) it('should warn about mapping it cannot handle', () => { @@ -66,17 +66,17 @@ Object { 'too/*/many/*/stars': ['to/*/many/*/stars'], }), ).toMatchInlineSnapshot(` -Object { - "^kept$": "src/kept", -} -`) + Object { + "^kept$": "src/kept", + } + `) expect(log.lines.warn).toMatchInlineSnapshot(` -Array [ - "[level:40] Not mapping \\"no-target\\" because it has no target. -", - "[level:40] Not mapping \\"too/*/many/*/stars\\" because it has more than one star (\`*\`). -", -] -`) + Array [ + "[level:40] Not mapping \\"no-target\\" because it has no target. + ", + "[level:40] Not mapping \\"too/*/many/*/stars\\" because it has more than one star (\`*\`). + ", + ] + `) }) }) diff --git a/src/config/paths-to-module-name-mapper.ts b/src/config/paths-to-module-name-mapper.ts index a3b3dd0f61..5774cae859 100644 --- a/src/config/paths-to-module-name-mapper.ts +++ b/src/config/paths-to-module-name-mapper.ts @@ -2,8 +2,8 @@ import type { Config } from '@jest/types' import { LogContexts } from 'bs-logger' import type { CompilerOptions } from 'typescript' -import { rootLogger } from '../util/logger' -import { Errors, interpolate } from '../util/messages' +import { rootLogger } from '../utils/logger' +import { Errors, interpolate } from '../utils/messages' type TsPathMapping = Exclude type JestPathMapping = Config.InitialOptions['moduleNameMapper'] diff --git a/src/index.ts b/src/index.ts index 08d2f23c07..9d7c6c642f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,10 +6,10 @@ import { createJestPreset as createJestPresetCore } from './config/create-jest-p import { pathsToModuleNameMapper as pathsToModuleNameMapperCore } from './config/paths-to-module-name-mapper' import { TsJestTransformer } from './ts-jest-transformer' import type { TsJestGlobalOptions } from './types' -import { rootLogger } from './util/logger' -import { Deprecations, interpolate } from './util/messages' -import { mocked as mockedCore } from './util/testing' -import { VersionCheckers } from './util/version-checkers' +import { rootLogger } from './utils/logger' +import { Deprecations, interpolate } from './utils/messages' +import { mocked as mockedCore } from './utils/testing' +import { VersionCheckers } from './utils/version-checkers' declare module '@jest/types' { // eslint-disable-next-line @typescript-eslint/no-namespace diff --git a/src/ts-jest-transformer.ts b/src/ts-jest-transformer.ts index c9d922f903..6565f950ac 100644 --- a/src/ts-jest-transformer.ts +++ b/src/ts-jest-transformer.ts @@ -6,11 +6,11 @@ import { inspect } from 'util' import { ConfigSet } from './config/config-set' import { JS_JSX_REGEX, TS_TSX_REGEX } from './constants' import type { TsJestGlobalOptions } from './types' -import { stringify } from './util/json' -import { JsonableValue } from './util/jsonable-value' -import { rootLogger } from './util/logger' -import { Errors, interpolate } from './util/messages' -import { sha1 } from './util/sha1' +import { stringify } from './utils/json' +import { JsonableValue } from './utils/jsonable-value' +import { rootLogger } from './utils/logger' +import { Errors, interpolate } from './utils/messages' +import { sha1 } from './utils/sha1' const INSPECT_CUSTOM = inspect.custom || 'inspect' diff --git a/src/util/__mocks__/logger.ts b/src/utils/__mocks__/logger.ts similarity index 100% rename from src/util/__mocks__/logger.ts rename to src/utils/__mocks__/logger.ts diff --git a/src/util/__snapshots__/backports.spec.ts.snap b/src/utils/__snapshots__/backports.spec.ts.snap similarity index 100% rename from src/util/__snapshots__/backports.spec.ts.snap rename to src/utils/__snapshots__/backports.spec.ts.snap diff --git a/src/util/backports.spec.ts b/src/utils/backports.spec.ts similarity index 100% rename from src/util/backports.spec.ts rename to src/utils/backports.spec.ts diff --git a/src/util/backports.ts b/src/utils/backports.ts similarity index 100% rename from src/util/backports.ts rename to src/utils/backports.ts diff --git a/src/util/get-package-version.spec.ts b/src/utils/get-package-version.spec.ts similarity index 100% rename from src/util/get-package-version.spec.ts rename to src/utils/get-package-version.spec.ts diff --git a/src/util/get-package-version.ts b/src/utils/get-package-version.ts similarity index 100% rename from src/util/get-package-version.ts rename to src/utils/get-package-version.ts diff --git a/src/util/importer.spec.ts b/src/utils/importer.spec.ts similarity index 100% rename from src/util/importer.spec.ts rename to src/utils/importer.spec.ts diff --git a/src/util/importer.ts b/src/utils/importer.ts similarity index 100% rename from src/util/importer.ts rename to src/utils/importer.ts diff --git a/src/util/index.spec.ts b/src/utils/index.spec.ts similarity index 100% rename from src/util/index.spec.ts rename to src/utils/index.spec.ts diff --git a/src/util/index.ts b/src/utils/index.ts similarity index 100% rename from src/util/index.ts rename to src/utils/index.ts diff --git a/src/util/json.spec.ts b/src/utils/json.spec.ts similarity index 100% rename from src/util/json.spec.ts rename to src/utils/json.spec.ts diff --git a/src/util/json.ts b/src/utils/json.ts similarity index 100% rename from src/util/json.ts rename to src/utils/json.ts diff --git a/src/util/jsonable-value.spec.ts b/src/utils/jsonable-value.spec.ts similarity index 96% rename from src/util/jsonable-value.spec.ts rename to src/utils/jsonable-value.spec.ts index f51f970750..d441196a66 100644 --- a/src/util/jsonable-value.spec.ts +++ b/src/utils/jsonable-value.spec.ts @@ -1,4 +1,4 @@ -import { mocked } from '../../utils' +import { mocked } from './' import * as _json from './json' import { JsonableValue } from './jsonable-value' diff --git a/src/util/jsonable-value.ts b/src/utils/jsonable-value.ts similarity index 100% rename from src/util/jsonable-value.ts rename to src/utils/jsonable-value.ts diff --git a/src/util/logger.spec.ts b/src/utils/logger.spec.ts similarity index 100% rename from src/util/logger.spec.ts rename to src/utils/logger.spec.ts diff --git a/src/util/logger.ts b/src/utils/logger.ts similarity index 100% rename from src/util/logger.ts rename to src/utils/logger.ts diff --git a/src/util/memoize.spec.ts b/src/utils/memoize.spec.ts similarity index 100% rename from src/util/memoize.spec.ts rename to src/utils/memoize.spec.ts diff --git a/src/util/memoize.ts b/src/utils/memoize.ts similarity index 100% rename from src/util/memoize.ts rename to src/utils/memoize.ts diff --git a/src/util/messages.spec.ts b/src/utils/messages.spec.ts similarity index 100% rename from src/util/messages.spec.ts rename to src/utils/messages.spec.ts diff --git a/src/util/messages.ts b/src/utils/messages.ts similarity index 100% rename from src/util/messages.ts rename to src/utils/messages.ts diff --git a/src/util/normalize-slashes.spec.ts b/src/utils/normalize-slashes.spec.ts similarity index 100% rename from src/util/normalize-slashes.spec.ts rename to src/utils/normalize-slashes.spec.ts diff --git a/src/util/normalize-slashes.ts b/src/utils/normalize-slashes.ts similarity index 100% rename from src/util/normalize-slashes.ts rename to src/utils/normalize-slashes.ts diff --git a/src/util/sha1.spec.ts b/src/utils/sha1.spec.ts similarity index 100% rename from src/util/sha1.spec.ts rename to src/utils/sha1.spec.ts diff --git a/src/util/sha1.ts b/src/utils/sha1.ts similarity index 100% rename from src/util/sha1.ts rename to src/utils/sha1.ts diff --git a/src/util/testing.spec.ts b/src/utils/testing.spec.ts similarity index 100% rename from src/util/testing.spec.ts rename to src/utils/testing.spec.ts diff --git a/src/util/testing.ts b/src/utils/testing.ts similarity index 100% rename from src/util/testing.ts rename to src/utils/testing.ts diff --git a/src/util/ts-error.ts b/src/utils/ts-error.ts similarity index 100% rename from src/util/ts-error.ts rename to src/utils/ts-error.ts diff --git a/src/util/version-checkers.spec.ts b/src/utils/version-checkers.spec.ts similarity index 98% rename from src/util/version-checkers.spec.ts rename to src/utils/version-checkers.spec.ts index 0e0363e520..9489dfc537 100644 --- a/src/util/version-checkers.spec.ts +++ b/src/utils/version-checkers.spec.ts @@ -1,4 +1,4 @@ -import { mocked } from '../../utils' +import { mocked } from './' import { logTargetMock } from '../__helpers__/mocks' import * as _pv from './get-package-version' diff --git a/src/util/version-checkers.ts b/src/utils/version-checkers.ts similarity index 100% rename from src/util/version-checkers.ts rename to src/utils/version-checkers.ts diff --git a/utils/index.d.ts b/utils/index.d.ts index 7cf7ee6046..3a0712a43f 100644 --- a/utils/index.d.ts +++ b/utils/index.d.ts @@ -1 +1 @@ -export * from '../dist/util' +export * from '../dist/utils' diff --git a/utils/index.js b/utils/index.js index 62bb0882f6..ad05c74143 100644 --- a/utils/index.js +++ b/utils/index.js @@ -1 +1 @@ -module.exports = require('../dist/util') +module.exports = require('../dist/utils')