Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spawn Jest command in separate shell on Windows #248

Merged
merged 7 commits into from
Feb 21, 2018
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Bug-fixes within the same version aren't needed

## Master

* Adding `.cmd` in `pathToJest` on Windows isn't necessary anymore - stephtr
* Update settings at runtime - gcangussu
* Improved detection logic for projects created by `create-react-app`
* Added `JestProcess` and `JestProcessManager` abstractions to simplify Jest process management - marcinczenko
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@
"elegant-spinner": "^1.0.1",
"istanbul-lib-coverage": "^1.1.1",
"istanbul-lib-source-maps": "^1.1.0",
"jest-editor-support": "^22.0.4",
"jest-snapshot": "^22.0.3",
"jest-test-typescript-parser": "^22.0.4",
"jest-editor-support": "^22.1.3",
"jest-snapshot": "^22.1.2",
"jest-test-typescript-parser": "^22.1.3",
"micromatch": "^2.3.11"
}
}
6 changes: 5 additions & 1 deletion src/JestProcessManagement/JestProcess.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { platform } from 'os'
import { Runner, ProjectWorkspace } from 'jest-editor-support'

export class JestProcess {
Expand All @@ -15,7 +16,10 @@ export class JestProcess {
private startRunner() {
this.stopRequested = false
let exited = false
this.runner = new Runner(this.projectWorkspace)
// Use a shell to run Jest command on Windows in order to correctly spawn `.cmd` files
// For details see https://github.com/jest-community/vscode-jest/issues/98
const useShell = platform() === 'win32'
this.runner = new Runner(this.projectWorkspace, { shell: useShell })

this.restoreJestEvents()

Expand Down
6 changes: 1 addition & 5 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@ export function pathToJest(pluginSettings: IPluginSettings) {
const defaultPath = normalize('node_modules/.bin/jest')
if (path === defaultPath && isBootstrappedWithCreateReactApp(pluginSettings.rootPath)) {
// If it's the default, run the script instead
return platform() === 'win32' ? 'npm.cmd test --' : 'npm test --'
return 'npm test --'
}

// For windows support, see https://github.com/jest-community/vscode-jest/issues/10
if (!path.includes('.cmd') && platform() === 'win32') {
return path + '.cmd'
}
return path
}

Expand Down
12 changes: 12 additions & 0 deletions typings/jest-editor-support.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
import * as editor from 'jest-editor-support'
import { ChildProcess } from 'child_process'
declare module 'jest-editor-support' {
interface SpawnOptions {
shell?: boolean
}

interface Options {
createProcess?(workspace: ProjectWorkspace, args: string[], options?: SpawnOptions): ChildProcess
testNamePattern?: string
testFileNamePattern?: string
shell?: boolean
}

interface JestTotalResults {
coverageMap: any
}
Expand Down