Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion __tests__/command.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect, beforeEach, jest, mock } from 'bun:test'
import { beforeEach, describe, expect, it, jest, mock } from 'bun:test'

const execMock = jest.fn().mockResolvedValue(0)
const debugMock = jest.fn()
Expand Down
2 changes: 1 addition & 1 deletion __tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect, jest, mock } from 'bun:test'
import { describe, expect, it, jest, mock } from 'bun:test'

const runMock = jest.fn().mockResolvedValue(undefined)

Expand Down
78 changes: 73 additions & 5 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect, beforeEach, jest, mock } from 'bun:test'
import { beforeEach, describe, expect, it, jest, mock } from 'bun:test'

const readdirSyncMock = jest.fn().mockReturnValue([])
const statSyncMock = jest.fn().mockReturnValue({ isDirectory: () => false })
Expand Down Expand Up @@ -707,7 +707,7 @@ describe('run', () => {
expect(infoMock).toHaveBeenCalledWith('/workspace/Foo.kt')
})

it('should print custom command in command output mode when output_mode_command is set', async () => {
it('should use custom command in run-locally message when output_mode_command is set', async () => {
runFormatterMock.mockResolvedValue({
exitCode: 1,
stdout: '/workspace/Main.kt\n1 file checked\n'
Expand All @@ -719,7 +719,11 @@ describe('run', () => {
output_mode_command: 'make format',
fail_on_error: false
})
expect(infoMock).toHaveBeenCalledWith('make format')
expect(infoMock).not.toHaveBeenCalledWith('make format')
expect(warningMock).toHaveBeenCalledWith(
expect.stringContaining('make format'),
expect.any(Object)
)
})

it('should print generated elide command in command output mode', async () => {
Expand All @@ -738,6 +742,70 @@ describe('run', () => {
)
})

it('should include generated command in failure message when no custom command', async () => {
runFormatterMock.mockResolvedValue({
exitCode: 1,
stdout: '/workspace/Main.kt\n1 file checked\n'
})
await run({
formatter: 'ktfmt',
files: ['Main.kt'],
output_mode: 'command',
fail_on_error: false
})
expect(warningMock).toHaveBeenCalledWith(
expect.stringContaining("elide ktfmt -- '/workspace/Main.kt'"),
expect.any(Object)
)
})

it('should include generated javaformat command in failure message', async () => {
runFormatterMock.mockResolvedValue({
exitCode: 1,
stdout: '/workspace/Main.java\n1 file checked\n'
})
await run({
formatter: 'javaformat',
files: ['Main.java'],
output_mode: 'command',
fail_on_error: false
})
expect(warningMock).toHaveBeenCalledWith(
expect.stringContaining("elide javaformat -- -r '/workspace/Main.java'"),
expect.any(Object)
)
})

it('should not include run-locally in failure message when output_mode is not command', async () => {
runFormatterMock.mockResolvedValue({
exitCode: 1,
stdout: '/workspace/Main.kt\n1 file checked\n'
})
await run({
formatter: 'ktfmt',
files: ['Main.kt'],
output_mode: 'file',
fail_on_error: false
})
expect(warningMock).toHaveBeenCalledWith(
expect.not.stringContaining('Run locally'),
expect.any(Object)
)
})

it('should not include run-locally in failure message when output_mode is none', async () => {
runFormatterMock.mockResolvedValue({ exitCode: 1, stdout: '' })
await run({
formatter: 'ktfmt',
files: ['Main.kt'],
fail_on_error: false
})
expect(warningMock).toHaveBeenCalledWith(
expect.not.stringContaining('Run locally'),
expect.any(Object)
)
})

it('should set files-failed output when output_mode is file', async () => {
runFormatterMock.mockResolvedValue({
exitCode: 1,
Expand Down Expand Up @@ -894,14 +962,14 @@ describe('printOutputModeResult', () => {
)
})

it('should print custom command string for command mode', () => {
it('should not print bare custom command string for command mode', () => {
printOutputModeResult(
'command',
'ktfmt',
'/workspace/Main.kt\n1 file\n',
'make format'
)
expect(infoMock).toHaveBeenCalledWith('make format')
expect(infoMock).not.toHaveBeenCalled()
})

it('should generate elide command for ktfmt without write flag', () => {
Expand Down
12 changes: 6 additions & 6 deletions __tests__/options.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect, beforeEach, jest, mock } from 'bun:test'
import { beforeEach, describe, expect, it, jest, mock } from 'bun:test'

const getInputMock = jest.fn().mockReturnValue('')
const getBooleanInputMock = jest.fn().mockReturnValue(true)
Expand All @@ -15,13 +15,13 @@ mock.module('@actions/core', () => ({
}))

import buildOptions, {
buildOptionsFromInputs,
normalizeFormatter,
normalizeMode,
normalizeOutputMode,
OptionName,
parseArgs,
parseFiles,
buildOptionsFromInputs,
OptionName
parseFiles
} from '../src/options'

describe('normalizeFormatter', () => {
Expand Down Expand Up @@ -226,8 +226,8 @@ describe('buildOptionsFromInputs', () => {
})

it('should read include-kts input', () => {
getBooleanInputMock.mockImplementation((name: string) =>
name === OptionName.INCLUDE_KTS ? true : true
getBooleanInputMock.mockImplementation(
(name: string) => name === OptionName.INCLUDE_KTS
)
expect(buildOptionsFromInputs().include_kts).toBe(true)
})
Expand Down
2 changes: 1 addition & 1 deletion __tests__/telemetry.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect, beforeEach, jest, mock } from 'bun:test'
import { beforeEach, describe, expect, it, jest, mock } from 'bun:test'

const initMock = jest.fn()
const setTagsMock = jest.fn()
Expand Down
44 changes: 22 additions & 22 deletions dist/index.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions dist/index.js.map

Large diffs are not rendered by default.

Loading
Loading