Skip to content

Commit a612f5a

Browse files
committed
modify tests
1 parent 9e12e83 commit a612f5a

4 files changed

Lines changed: 23 additions & 33 deletions

File tree

src/JestExt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as vscode from 'vscode'
22
import * as path from 'path'
33
import { Settings, ProjectWorkspace, JestTotalResults } from 'jest-editor-support'
44
import { matcher } from 'micromatch'
5+
import { platform } from 'os'
56

67
import * as decorations from './decorations'
78
import { IPluginSettings } from './Settings'
@@ -23,7 +24,6 @@ import { hasDocument, isOpenInMultipleEditors } from './editor'
2324
import { CoverageOverlay } from './Coverage/CoverageOverlay'
2425
import { JestProcess, JestProcessManager } from './JestProcessManagement'
2526
import { isWatchNotSupported, WatchMode } from './Jest'
26-
import { platform } from 'os'
2727

2828
export class JestExt {
2929
private workspace: ProjectWorkspace

src/JestProcessManagement/JestProcess.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ export class JestProcess {
1818
this.stopRequested = false
1919
let exited = false
2020

21-
const options = { shell: platform() === 'win32' }
22-
this.runner = new Runner(this.projectWorkspace, options)
21+
const useShell = platform() === 'win32'
22+
this.runner = new Runner(this.projectWorkspace, { shell: useShell })
2323

2424
this.restoreJestEvents()
2525

tests/JestExt.test.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@ jest.unmock('../src/JestExt')
44
jest.mock('../src/DebugCodeLens', () => ({
55
DebugCodeLensProvider: class MockCodeLensProvider {},
66
}))
7+
jest.mock('os')
78

89
import { JestExt } from '../src/JestExt'
910
import { ProjectWorkspace, Settings } from 'jest-editor-support'
11+
import { platform } from 'os'
1012
import { window, workspace, debug } from 'vscode'
1113
import { hasDocument, isOpenInMultipleEditors } from '../src/editor'
1214
import { failingAssertionStyle } from '../src/decorations'
1315

1416
describe('JestExt', () => {
1517
const mockSettings = (Settings as any) as jest.Mock<any>
18+
const mockSettingsObject = {
19+
getConfig: callback => callback(),
20+
jestVersionMajor: 22,
21+
}
1622
const getConfiguration = workspace.getConfiguration as jest.Mock<any>
1723
let projectWorkspace: ProjectWorkspace
1824
const channelStub = { appendLine: () => {} } as any
@@ -27,8 +33,8 @@ describe('JestExt', () => {
2733
})
2834

2935
it('should show error message if jest version i < 18', () => {
30-
mockSettings.mockImplementation(() => ({
31-
getConfig: callback => callback(),
36+
mockSettings.mockImplementationOnce(() => ({
37+
...mockSettingsObject,
3238
jestVersionMajor: 17,
3339
}))
3440
new JestExt(null, projectWorkspace, channelStub, extensionSettings)
@@ -37,14 +43,20 @@ describe('JestExt', () => {
3743
})
3844

3945
it.skip('should not show error message if jest version is 20', () => {
40-
mockSettings.mockImplementation(() => ({
41-
getConfig: callback => callback(),
42-
jestVersionMajor: 20,
43-
}))
46+
mockSettings.mockImplementationOnce(() => mockSettingsObject)
4447
new JestExt(null, projectWorkspace, channelStub, extensionSettings)
4548
expect(window.showErrorMessage).not.toBeCalled()
4649
})
4750

51+
it('should create `Settings` with `shell` set on Windows', () => {
52+
mockSettings.mockImplementationOnce((_, options) => {
53+
expect(options.shell).toBe(true)
54+
return mockSettingsObject
55+
})
56+
;((platform as any) as jest.Mock<any>).mockReturnValueOnce('win32')
57+
new JestExt(null, projectWorkspace, channelStub, extensionSettings)
58+
})
59+
4860
describe('resetInlineErrorDecorators()', () => {
4961
let sut: JestExt
5062
const editor: any = {

tests/helpers.test.ts

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -169,29 +169,7 @@ describe('ModuleHelpers', () => {
169169
expect(mockNormalize).toBeCalledWith(settings.pathToJest)
170170
})
171171

172-
it('defaults to "node_modules/.bin/jest.cmd" on Windows when Jest is locally installed', () => {
173-
const expected = 'node_modules\\.bin\\jest.cmd'
174-
175-
mockJoin.mockImplementation(require.requireActual('path').win32.join)
176-
mockPlatform.mockReturnValue('win32')
177-
mockNormalize.mockImplementationOnce(arg => arg)
178-
mockExistsSync.mockImplementation(path => path === expected)
179-
180-
expect(pathToJest(defaultSettings)).toBe(expected)
181-
})
182-
183-
it('defaults to "jest.cmd" on Windows when Jest is not locally installed', () => {
184-
const expected = 'jest.cmd'
185-
186-
mockJoin.mockImplementation(require.requireActual('path').win32.join)
187-
mockPlatform.mockReturnValue('win32')
188-
mockNormalize.mockImplementationOnce(arg => arg)
189-
mockExistsSync.mockImplementation(_ => false)
190-
191-
expect(pathToJest(defaultSettings)).toBe(expected)
192-
})
193-
194-
it('defaults to "node_modules/.bin/jest" on a non-Windows OS when Jest is locally installed', () => {
172+
it('defaults to "node_modules/.bin/jest" when Jest is locally installed', () => {
195173
const expected = 'node_modules/.bin/jest'
196174

197175
mockJoin.mockImplementation(require.requireActual('path').posix.join)
@@ -202,7 +180,7 @@ describe('ModuleHelpers', () => {
202180
expect(pathToJest(defaultSettings)).toBe(expected)
203181
})
204182

205-
it('defaults to "jest" on a non-Windows OS when Jest is locally installed', () => {
183+
it('defaults to "jest" when Jest is locally installed', () => {
206184
const expected = 'jest'
207185

208186
mockJoin.mockImplementation(require.requireActual('path').posix.join)

0 commit comments

Comments
 (0)