Skip to content
Closed
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
8 changes: 8 additions & 0 deletions packages/process-explorer-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
"testMatch": [
"**/test/**"
],
"testPathIgnorePatterns": [
"/node_modules/",
"<rootDir>/test/fixtures/"
],
"coveragePathIgnorePatterns": [
"/node_modules/",
"<rootDir>/test/fixtures/"
],
"collectCoverage": true,
"coverageThreshold": {
"global": {
Expand Down
35 changes: 18 additions & 17 deletions packages/process-explorer-worker/test/ApplyRender.test.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import { expect, test } from '@jest/globals'
import { ViewletCommand } from '@lvce-editor/constants'
import * as ApplyRender from '../src/parts/ApplyRender/ApplyRender.ts'
import { createDefaultState } from '../src/parts/CreateDefaultState/CreateDefaultState.ts'
import * as DiffType from '../src/parts/DiffType/DiffType.ts'
import { createProcessState } from './fixtures/ProcessExplorerFixtures.ts'

test('applyRender - filters empty render commands', () => {
const state = createDefaultState()

expect(ApplyRender.applyRender(state, state, [DiffType.RenderFocus])).toEqual(
[],
)
})

test('applyRender - returns render commands', () => {
const oldState = createDefaultState()
const newState = {
...oldState,
test('applyRender ignores empty render results', () => {
const state = createProcessState({
focused: true,
focusedIndex: 0,
}
})
const commands = ApplyRender.applyRender(state, state, [DiffType.RenderFocus])
expect(commands).toEqual([])
})

expect(
ApplyRender.applyRender(oldState, newState, [DiffType.RenderFocus]),
).toEqual([[ViewletCommand.FocusSelector, '[data-index="0"]']])
test('applyRender returns non-empty render results', () => {
const oldState = createProcessState()
const newState = createProcessState({
initial: false,
})
const commands = ApplyRender.applyRender(oldState, newState, [
DiffType.RenderFocus,
DiffType.RenderItems,
])
expect(commands).toHaveLength(1)
expect(commands[0][0]).toBe(ViewletCommand.SetDom2)
})
27 changes: 27 additions & 0 deletions packages/process-explorer-worker/test/CollapseAll.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { expect, test } from '@jest/globals'
import * as CollapseAll from '../src/parts/CollapseAll/CollapseAll.ts'
import { createDefaultState } from '../src/parts/CreateDefaultState/CreateDefaultState.ts'
import {
createProcessState,
processes,
} from './fixtures/ProcessExplorerFixtures.ts'

test('collapseAll collapses every parent process', () => {
const state = createProcessState()
const result = CollapseAll.collapseAll(state)
expect(result.collapsedPids).toEqual([1, 2])
expect(result.focusedIndex).toBe(0)
expect(result.visibleProcesses.map((process) => process.pid)).toEqual([1])
})

test('collapseAll focuses nothing when no process is visible', () => {
const state = {
...createDefaultState(),
processes,
rootPid: 99,
}
const result = CollapseAll.collapseAll(state)
expect(result.collapsedPids).toEqual([1, 2])
expect(result.focusedIndex).toBe(-1)
expect(result.visibleProcesses).toEqual([])
})
27 changes: 4 additions & 23 deletions packages/process-explorer-worker/test/Create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,9 @@ test('create', () => {
expect(ProcessExplorerStates.get(7).newState).toBe(state)
})

test('create - defaults and include frontend memory usage', () => {
test('create uses default asset dir', () => {
ProcessExplorerStates.clear()
const state = create(
8,
'',
1,
2,
300,
400,
{ includeFrontendMemoryUsage: true },
5,
)
expect(state).toMatchObject({
assetDir: '',
includeFrontendMemoryUsage: true,
platform: 0,
})
expect(ProcessExplorerStates.get(8).newState).toBe(state)
})

test('create - missing args', () => {
ProcessExplorerStates.clear()
const state = create(9, '', 1, 2, 300, 400, undefined, 5)
expect(state.includeFrontendMemoryUsage).toBe(false)
const state = create(8, '', 1, 2, 300, 400, [], 5)
expect(state.assetDir).toBe('')
expect(state.uid).toBe(8)
})
17 changes: 17 additions & 0 deletions packages/process-explorer-worker/test/FocusFirst.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { expect, test } from '@jest/globals'
import * as FocusFirst from '../src/parts/FocusFirst/FocusFirst.ts'
import { createProcessState } from './fixtures/ProcessExplorerFixtures.ts'

test('focusFirst focuses first visible process', () => {
const state = createProcessState({
focusedIndex: 2,
})
expect(FocusFirst.focusFirst(state).focusedIndex).toBe(0)
})

test('focusFirst returns state for empty visible processes', () => {
const state = createProcessState({
visibleProcesses: [],
})
expect(FocusFirst.focusFirst(state)).toBe(state)
})
25 changes: 25 additions & 0 deletions packages/process-explorer-worker/test/FocusIndex.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { expect, test } from '@jest/globals'
import * as FocusIndex from '../src/parts/FocusIndex/FocusIndex.ts'
import { createProcessState } from './fixtures/ProcessExplorerFixtures.ts'

test('focusIndex focuses valid index', () => {
const state = createProcessState()
expect(FocusIndex.focusIndex(state, 1)).toMatchObject({
focusedIndex: 1,
})
})

test('focusIndex allows -1', () => {
const state = createProcessState({
focusedIndex: 1,
})
expect(FocusIndex.focusIndex(state, -1).focusedIndex).toBe(-1)
})

test('focusIndex ignores invalid indexes', () => {
const state = createProcessState()
expect(FocusIndex.focusIndex(state, -2)).toBe(state)
expect(FocusIndex.focusIndex(state, state.visibleProcesses.length)).toBe(
state,
)
})
15 changes: 15 additions & 0 deletions packages/process-explorer-worker/test/FocusLast.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { expect, test } from '@jest/globals'
import * as FocusLast from '../src/parts/FocusLast/FocusLast.ts'
import { createProcessState } from './fixtures/ProcessExplorerFixtures.ts'

test('focusLast focuses last visible process', () => {
const state = createProcessState()
expect(FocusLast.focusLast(state).focusedIndex).toBe(2)
})

test('focusLast returns state for empty visible processes', () => {
const state = createProcessState({
visibleProcesses: [],
})
expect(FocusLast.focusLast(state)).toBe(state)
})
60 changes: 23 additions & 37 deletions packages/process-explorer-worker/test/FocusPrevious.test.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,30 @@
import { expect, test } from '@jest/globals'
import { createDefaultState } from '../src/parts/CreateDefaultState/CreateDefaultState.ts'
import * as FocusPrevious from '../src/parts/FocusPrevious/FocusPrevious.ts'
import * as GetVisibleProcesses from '../src/parts/GetVisibleProcesses/GetVisibleProcesses.ts'

const processes = [
{
cmd: 'main',
memory: 1,
name: 'main',
pid: 1,
ppid: 0,
},
{
cmd: 'node child.js',
memory: 1500,
name: 'child',
pid: 2,
ppid: 1,
},
{
cmd: 'leaf',
memory: 2_500_000,
name: 'leaf',
pid: 3,
ppid: 2,
},
{
cmd: 'orphan',
memory: 1,
name: 'orphan',
pid: 4,
ppid: 999,
},
]
import { createProcessState } from './fixtures/ProcessExplorerFixtures.ts'

test('focusPrevious', () => {
const state = {
...createDefaultState(),
const state = createProcessState({
focusedIndex: 1,
visibleProcesses: GetVisibleProcesses.getVisibleProcesses(processes, [], 1),
}
})
expect(FocusPrevious.focusPrevious(state).focusedIndex).toBe(0)
})

test('focusPrevious focuses last item from -1', () => {
const state = createProcessState({
focusedIndex: -1,
})
expect(FocusPrevious.focusPrevious(state).focusedIndex).toBe(2)
})

test('focusPrevious returns state at beginning or empty list', () => {
const state = createProcessState({
focusedIndex: 0,
})
expect(FocusPrevious.focusPrevious(state)).toBe(state)

const emptyState = createProcessState({
focusedIndex: -1,
visibleProcesses: [],
})
expect(FocusPrevious.focusPrevious(emptyState)).toBe(emptyState)
})
8 changes: 2 additions & 6 deletions packages/process-explorer-worker/test/GetRenderer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,20 @@ import * as DiffType from '../src/parts/DiffType/DiffType.ts'
import * as GetRenderer from '../src/parts/GetRenderer/GetRenderer.ts'
import * as RenderFocus from '../src/parts/RenderFocus/RenderFocus.ts'
import * as RenderFocusContext from '../src/parts/RenderFocusContext/RenderFocusContext.ts'
import { renderIncremental } from '../src/parts/RenderIncremental/RenderIncremental.ts'
import * as RenderItems from '../src/parts/RenderItems/RenderItems.ts'

test('getRenderer', () => {
test('getRenderer returns renderer for diff type', () => {
expect(GetRenderer.getRenderer(DiffType.RenderFocus)).toBe(
RenderFocus.renderFocus,
)
expect(GetRenderer.getRenderer(DiffType.RenderFocusContext)).toBe(
RenderFocusContext.renderFocusContext,
)
expect(GetRenderer.getRenderer(DiffType.RenderIncremental)).toBe(
renderIncremental,
)
expect(GetRenderer.getRenderer(DiffType.RenderItems)).toBe(
RenderItems.renderItems,
)
})

test('getRenderer - unknown renderer', () => {
test('getRenderer throws for unknown diff type', () => {
expect(() => GetRenderer.getRenderer(999)).toThrow('unknown renderer 999')
})
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,7 @@ test('getVisibleProcesses', () => {
})
})

test('getVisibleProcesses - uses first process when root pid is missing', () => {
test('getVisibleProcesses uses first process when root pid is zero', () => {
const visible = GetVisibleProcesses.getVisibleProcesses(processes, [], 0)

expect(visible.map((process) => process.pid)).toEqual([1, 2, 3])
})

test('getVisibleProcesses - missing root process', () => {
expect(GetVisibleProcesses.getVisibleProcesses(processes, [], 99)).toEqual([])
})
87 changes: 21 additions & 66 deletions packages/process-explorer-worker/test/HandleArrowLeft.test.ts
Original file line number Diff line number Diff line change
@@ -1,88 +1,43 @@
import { expect, test } from '@jest/globals'
import { createDefaultState } from '../src/parts/CreateDefaultState/CreateDefaultState.ts'
import * as GetVisibleProcesses from '../src/parts/GetVisibleProcesses/GetVisibleProcesses.ts'
import * as HandleArrowLeft from '../src/parts/HandleArrowLeft/HandleArrowLeft.ts'

const processes = [
{
cmd: 'main',
memory: 1,
name: 'main',
pid: 1,
ppid: 0,
},
{
cmd: 'node child.js',
memory: 1500,
name: 'child',
pid: 2,
ppid: 1,
},
{
cmd: 'leaf',
memory: 2_500_000,
name: 'leaf',
pid: 3,
ppid: 2,
},
{
cmd: 'orphan',
memory: 1,
name: 'orphan',
pid: 4,
ppid: 999,
},
]
import { createProcessState } from './fixtures/ProcessExplorerFixtures.ts'

test('handleArrowLeft collapses expanded process', () => {
const state = {
...createDefaultState(),
const state = createProcessState({
focusedIndex: 1,
processes,
rootPid: 1,
visibleProcesses: GetVisibleProcesses.getVisibleProcesses(processes, [], 1),
}
})
const result = HandleArrowLeft.handleArrowLeft(state)
expect(result.collapsedPids).toEqual([2])
expect(result.visibleProcesses.map((process) => process.pid)).toEqual([1, 2])
})

test('handleArrowLeft focuses parent for leaf', () => {
const state = {
...createDefaultState(),
const state = createProcessState({
focusedIndex: 2,
processes,
rootPid: 1,
visibleProcesses: GetVisibleProcesses.getVisibleProcesses(processes, [], 1),
}
})
expect(HandleArrowLeft.handleArrowLeft(state).focusedIndex).toBe(1)
})

test('handleArrowLeft - missing focused process', () => {
const state = {
...createDefaultState(),
test('handleArrowLeft returns state without focused process', () => {
const state = createProcessState({
focusedIndex: 99,
processes,
rootPid: 1,
visibleProcesses: GetVisibleProcesses.getVisibleProcesses(processes, [], 1),
}

})
expect(HandleArrowLeft.handleArrowLeft(state)).toBe(state)
})

test('handleArrowLeft - no parent', () => {
const singleProcess = [processes[0]]
const state = {
...createDefaultState(),
test('handleArrowLeft returns state when focused process has no parent', () => {
const processes = [
{
cmd: 'main',
memory: 1,
name: 'main',
pid: 1,
ppid: 0,
},
]
const state = createProcessState({
focusedIndex: 0,
processes: singleProcess,
rootPid: 1,
visibleProcesses: GetVisibleProcesses.getVisibleProcesses(
singleProcess,
[],
1,
),
}

processes,
})
expect(HandleArrowLeft.handleArrowLeft(state)).toBe(state)
})
Loading