Skip to content

Commit

Permalink
refactor(devs-infra): rename util dir to utils dir (#1910)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnpnl committed Aug 29, 2020
1 parent ac88cd6 commit b1dbcca
Show file tree
Hide file tree
Showing 47 changed files with 92 additions and 92 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Expand Up @@ -13,7 +13,7 @@ module.exports = {
'!<rootDir>/src/**/*.spec.ts',
'!<rootDir>/src/**/*.test.ts',
'!<rootDir>/src/**/__*__/*',
'!<rootDir>/src/util/testing.ts',
'!<rootDir>/src/utils/testing.ts',
],
snapshotSerializers: ['<rootDir>/src/__serializers__/processed-source.ts'],
cacheDirectory: '<rootDir>/.cache/unit',
Expand Down
2 changes: 1 addition & 1 deletion src/__helpers__/fakers.ts
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion 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

Expand Down
2 changes: 1 addition & 1 deletion src/__helpers__/setup.ts
@@ -1 +1 @@
jest.mock('../util/logger')
jest.mock('../utils/logger')
2 changes: 1 addition & 1 deletion 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 '.'
Expand Down
2 changes: 1 addition & 1 deletion src/cli/config/migrate.ts
Expand Up @@ -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'

/**
Expand Down
2 changes: 1 addition & 1 deletion src/cli/index.ts
Expand Up @@ -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']

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/instance.ts
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/language-service.ts
Expand Up @@ -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<string, TSFile>
Expand Down
14 changes: 7 additions & 7 deletions src/config/config-set.spec.ts
Expand Up @@ -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)
Expand Down
22 changes: 11 additions & 11 deletions src/config/config-set.ts
Expand Up @@ -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' })

Expand Down
2 changes: 1 addition & 1 deletion 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' })

Expand Down
94 changes: 47 additions & 47 deletions src/config/paths-to-module-name-mapper.spec.ts
Expand Up @@ -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/*'],
Expand All @@ -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: '<rootDir>/' })).toMatchInlineSnapshot(`
Object {
"^api/(.*)$": "<rootDir>/src/api/$1",
"^client$": Array [
"<rootDir>/src/client",
"<rootDir>/src/client/index",
],
"^log$": "<rootDir>/src/util/log",
"^mocks/(.*)$": "<rootDir>/test/mocks/$1",
"^server$": "<rootDir>/src/server",
"^test/(.*)$": "<rootDir>/test/$1",
"^test/(.*)/mock$": Array [
"<rootDir>/test/mocks/$1",
"<rootDir>/test/__mocks__/$1",
],
"^util/(.*)$": "<rootDir>/src/util/$1",
}
`)
Object {
"^api/(.*)$": "<rootDir>/src/api/$1",
"^client$": Array [
"<rootDir>/src/client",
"<rootDir>/src/client/index",
],
"^log$": "<rootDir>/src/utils/log",
"^mocks/(.*)$": "<rootDir>/test/mocks/$1",
"^server$": "<rootDir>/src/server",
"^test/(.*)$": "<rootDir>/test/$1",
"^test/(.*)/mock$": Array [
"<rootDir>/test/mocks/$1",
"<rootDir>/test/__mocks__/$1",
],
"^util/(.*)$": "<rootDir>/src/utils/$1",
}
`)
})

it('should warn about mapping it cannot handle', () => {
Expand All @@ -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 (\`*\`).
",
]
`)
})
})
4 changes: 2 additions & 2 deletions src/config/paths-to-module-name-mapper.ts
Expand Up @@ -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<CompilerOptions['paths'], undefined>
type JestPathMapping = Config.InitialOptions['moduleNameMapper']
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/ts-jest-transformer.ts
Expand Up @@ -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'

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,4 +1,4 @@
import { mocked } from '../../utils'
import { mocked } from './'

import * as _json from './json'
import { JsonableValue } from './jsonable-value'
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,4 +1,4 @@
import { mocked } from '../../utils'
import { mocked } from './'
import { logTargetMock } from '../__helpers__/mocks'

import * as _pv from './get-package-version'
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion utils/index.d.ts
@@ -1 +1 @@
export * from '../dist/util'
export * from '../dist/utils'
2 changes: 1 addition & 1 deletion utils/index.js
@@ -1 +1 @@
module.exports = require('../dist/util')
module.exports = require('../dist/utils')

0 comments on commit b1dbcca

Please sign in to comment.