Skip to content

Commit 6563a39

Browse files
authored
Merge pull request jest-community#340 from stephtr/fix-shell
Add usage of shell when gathering Jest settings
2 parents 53f9e3d + a612f5a commit 6563a39

10 files changed

Lines changed: 79 additions & 91 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Bug-fixes within the same version aren't needed
1212
- seanpoulter
1313
* Fix regression in handling workspaces that have been bootstrapped with
1414
create-react-app - seanpoulter
15+
* Run Jest on Windows in a shell when gathering settings, such that we don't
16+
have to deal with the .cmd extension anymore - stephtr
1517
1618
-->
1719

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
},
5656
"jest.pathToJest": {
5757
"description":
58-
"The path to the Jest binary, or an npm command to run tests prefixed with `--` e.g. `npm test --`",
58+
"The path to the Jest binary, or an npm command to run tests prefixed with `--` e.g. `node_modules/.bin/jest` or `npm test --`",
5959
"type": "string",
6060
"default": null
6161
},
@@ -232,7 +232,7 @@
232232
"elegant-spinner": "^1.0.1",
233233
"istanbul-lib-coverage": "^1.1.1",
234234
"istanbul-lib-source-maps": "^1.1.0",
235-
"jest-editor-support": "22.4.0",
235+
"jest-editor-support": "23.0.0",
236236
"jest-snapshot": "^22.1.2",
237237
"jest-test-typescript-parser": "^22.1.3",
238238
"micromatch": "^2.3.11"

src/JestExt.ts

Lines changed: 8 additions & 2 deletions
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'
@@ -68,7 +69,7 @@ export class JestExt {
6869
this.failingAssertionDecorators = {}
6970
this.failDiagnostics = vscode.languages.createDiagnosticCollection('Jest')
7071
this.clearOnNextInput = true
71-
this.jestSettings = new Settings(workspace)
72+
this.recreateJestSettings()
7273
this.pluginSettings = pluginSettings
7374

7475
this.coverageMapProvider = new CoverageMapProvider()
@@ -259,7 +260,7 @@ export class JestExt {
259260
this.workspace.pathToJest = pathToJest(updatedSettings)
260261
this.workspace.pathToConfig = pathToConfig(updatedSettings)
261262

262-
this.jestSettings = new Settings(this.workspace)
263+
this.recreateJestSettings()
263264

264265
this.coverageOverlay.enabled = updatedSettings.showCoverageOnLoad
265266

@@ -274,6 +275,11 @@ export class JestExt {
274275
}, 500)
275276
}
276277

278+
private recreateJestSettings() {
279+
const useShell = platform() === 'win32'
280+
this.jestSettings = new Settings(this.workspace, { shell: useShell })
281+
}
282+
277283
private updateDotDecorators(editor: vscode.TextEditor) {
278284
const filePath = editor.document.fileName
279285
const testResults = this.testResultProvider.getSortedResults(filePath)

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

src/TestResults/TestResultProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TestReconciler, FormattedTestResults } from 'jest-editor-support'
1+
import { TestReconciler, JestTotalResults } from 'jest-editor-support'
22
import { TestFileAssertionStatus } from 'jest-editor-support'
33
import { TestReconciliationState } from './TestReconciliationState'
44
import { TestResult } from './TestResult'
@@ -99,7 +99,7 @@ export class TestResultProvider {
9999
return result
100100
}
101101

102-
updateTestResults(data: FormattedTestResults): TestFileAssertionStatus[] {
102+
updateTestResults(data: JestTotalResults): TestFileAssertionStatus[] {
103103
this.resetCache()
104104
return this.reconciler.updateFileWithJestStatus(data)
105105
}

src/helpers.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,11 @@ export function pathToJest({ pathToJest, rootPath }: IPluginSettings) {
7373
if (existsSync(localJestExecutable)) {
7474
return localJestExecutable
7575
}
76-
return `jest${isWindows() ? '.cmd' : ''}`
76+
return 'jest'
7777
}
7878

7979
function pathToLocalJestExecutable(rootDir) {
80-
return normalize(join(rootDir, `node_modules/.bin/jest${isWindows() ? '.cmd' : ''}`))
81-
}
82-
83-
function isWindows() {
84-
return platform() === 'win32'
80+
return normalize(join(rootDir, 'node_modules/.bin/jest'))
8581
}
8682

8783
/**

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)

typings/jest-editor-support.d.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.

yarn.lock

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2260,19 +2260,28 @@ jest-diff@^22.4.3:
22602260
jest-get-type "^22.4.3"
22612261
pretty-format "^22.4.3"
22622262

2263+
jest-diff@^23.2.0:
2264+
version "23.2.0"
2265+
resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-23.2.0.tgz#9f2cf4b51e12c791550200abc16b47130af1062a"
2266+
dependencies:
2267+
chalk "^2.0.1"
2268+
diff "^3.2.0"
2269+
jest-get-type "^22.1.0"
2270+
pretty-format "^23.2.0"
2271+
22632272
jest-docblock@^22.4.3:
22642273
version "22.4.3"
22652274
resolved "https://registry.yarnpkg.com/jest-docblock/-/jest-docblock-22.4.3.tgz#50886f132b42b280c903c592373bb6e93bb68b19"
22662275
dependencies:
22672276
detect-newline "^2.1.0"
22682277

2269-
jest-editor-support@22.4.0:
2270-
version "22.4.0"
2271-
resolved "https://registry.yarnpkg.com/jest-editor-support/-/jest-editor-support-22.4.0.tgz#1f6e2359dbf90f84c1a8a16b911db5ef4333b0a0"
2278+
jest-editor-support@23.0.0:
2279+
version "23.0.0"
2280+
resolved "https://registry.yarnpkg.com/jest-editor-support/-/jest-editor-support-23.0.0.tgz#2fa06aba27c0eabf0b9028774ee201c4492e39bd"
22722281
dependencies:
22732282
babel-traverse "^6.14.1"
22742283
babylon "^6.14.1"
2275-
jest-snapshot "^22.4.0"
2284+
jest-snapshot "^23.0.0"
22762285

22772286
jest-editor-support@^22.4.3:
22782287
version "22.4.3"
@@ -2301,7 +2310,7 @@ jest-get-type@^21.2.0:
23012310
version "21.2.0"
23022311
resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-21.2.0.tgz#f6376ab9db4b60d81e39f30749c6c466f40d4a23"
23032312

2304-
jest-get-type@^22.4.3:
2313+
jest-get-type@^22.1.0, jest-get-type@^22.4.3:
23052314
version "22.4.3"
23062315
resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-22.4.3.tgz#e3a8504d8479342dd4420236b322869f18900ce4"
23072316

@@ -2347,6 +2356,14 @@ jest-matcher-utils@^22.4.3:
23472356
jest-get-type "^22.4.3"
23482357
pretty-format "^22.4.3"
23492358

2359+
jest-matcher-utils@^23.2.0:
2360+
version "23.2.0"
2361+
resolved "https://registry.yarnpkg.com/jest-matcher-utils/-/jest-matcher-utils-23.2.0.tgz#4d4981f23213e939e3cedf23dc34c747b5ae1913"
2362+
dependencies:
2363+
chalk "^2.0.1"
2364+
jest-get-type "^22.1.0"
2365+
pretty-format "^23.2.0"
2366+
23502367
jest-message-util@^22.4.3:
23512368
version "22.4.3"
23522369
resolved "https://registry.yarnpkg.com/jest-message-util/-/jest-message-util-22.4.3.tgz#cf3d38aafe4befddbfc455e57d65d5239e399eb7"
@@ -2423,7 +2440,7 @@ jest-serializer@^22.4.3:
24232440
version "22.4.3"
24242441
resolved "https://registry.yarnpkg.com/jest-serializer/-/jest-serializer-22.4.3.tgz#a679b81a7f111e4766235f4f0c46d230ee0f7436"
24252442

2426-
jest-snapshot@^22.1.2, jest-snapshot@^22.4.0, jest-snapshot@^22.4.3:
2443+
jest-snapshot@^22.1.2, jest-snapshot@^22.4.3:
24272444
version "22.4.3"
24282445
resolved "https://registry.yarnpkg.com/jest-snapshot/-/jest-snapshot-22.4.3.tgz#b5c9b42846ffb9faccb76b841315ba67887362d2"
24292446
dependencies:
@@ -2434,6 +2451,17 @@ jest-snapshot@^22.1.2, jest-snapshot@^22.4.0, jest-snapshot@^22.4.3:
24342451
natural-compare "^1.4.0"
24352452
pretty-format "^22.4.3"
24362453

2454+
jest-snapshot@^23.0.0:
2455+
version "23.2.0"
2456+
resolved "https://registry.yarnpkg.com/jest-snapshot/-/jest-snapshot-23.2.0.tgz#c7a3d017177bbad60c8a595869cf90a8782e6a7e"
2457+
dependencies:
2458+
chalk "^2.0.1"
2459+
jest-diff "^23.2.0"
2460+
jest-matcher-utils "^23.2.0"
2461+
mkdirp "^0.5.1"
2462+
natural-compare "^1.4.0"
2463+
pretty-format "^23.2.0"
2464+
24372465
jest-test-typescript-parser@^22.1.3:
24382466
version "22.4.3"
24392467
resolved "https://registry.yarnpkg.com/jest-test-typescript-parser/-/jest-test-typescript-parser-22.4.3.tgz#805d6e203c1aea5811e7019d998fe1917f130930"
@@ -3472,6 +3500,13 @@ pretty-format@^22.4.3:
34723500
ansi-regex "^3.0.0"
34733501
ansi-styles "^3.2.0"
34743502

3503+
pretty-format@^23.2.0:
3504+
version "23.2.0"
3505+
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-23.2.0.tgz#3b0aaa63c018a53583373c1cb3a5d96cc5e83017"
3506+
dependencies:
3507+
ansi-regex "^3.0.0"
3508+
ansi-styles "^3.2.0"
3509+
34753510
private@^0.1.7:
34763511
version "0.1.8"
34773512
resolved "https://registry.yarnpkg.com/private/-/private-0.1.8.tgz#2381edb3689f7a53d653190060fcf822d2f368ff"

0 commit comments

Comments
 (0)