-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Relative path for
jestrunner.projectPath
(#306)
* Support relative path? * add linux/macos platformss * docs * better typing * docs
- Loading branch information
Showing
6 changed files
with
136 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; | ||
moduleNameMapper: { | ||
'^vscode$': 'src/test/__mocks__/vscode.ts', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// __mocks__/vscode.ts | ||
|
||
class Uri { | ||
constructor(readonly fsPath: string) {} | ||
} | ||
|
||
class Document { | ||
constructor(public readonly uri: Uri) {} | ||
} | ||
|
||
class TextEditor { | ||
constructor(public readonly document: Document) {} | ||
} | ||
|
||
class WorkspaceFolder { | ||
constructor(public readonly uri: Uri) {} | ||
|
||
name: string; | ||
index: number; | ||
} | ||
|
||
class Workspace { | ||
getWorkspaceFolder(uri: Uri): { uri: Uri } { | ||
return { uri }; | ||
} | ||
|
||
getConfiguration() { | ||
throw new WorkspaceConfiguration({}); | ||
} | ||
} | ||
|
||
class WorkspaceConfiguration { | ||
constructor(private dict: { [key: string]: string }) {} | ||
|
||
get(key: string): string { | ||
if (!(key in this.dict)) { | ||
throw new Error(`unrecognised config key ${key}`); | ||
} | ||
return this.dict[key]; | ||
} | ||
|
||
has(key: string) { | ||
return key in this.dict; | ||
} | ||
inspect(section: string): undefined { | ||
throw new Error('not implemented'); | ||
} | ||
update(key: string, value: string): Thenable<void> { | ||
throw new Error('not implemented'); | ||
} | ||
} | ||
|
||
class Window { | ||
get activeTextEditor(): TextEditor { | ||
return new TextEditor(new Document(new Uri('hi'))); | ||
} | ||
} | ||
|
||
const workspace = new Workspace(); | ||
const window = new Window(); | ||
|
||
export { workspace, window, Uri, Document, TextEditor, WorkspaceFolder, WorkspaceConfiguration }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import * as vscode from 'vscode'; | ||
import { JestRunnerConfig } from '../jestRunnerConfig'; | ||
import { Uri, WorkspaceConfiguration, WorkspaceFolder } from './__mocks__/vscode'; | ||
|
||
const describes = { | ||
windows: process.platform === 'win32' ? describe : describe.skip, | ||
linux: ['linux', 'darwin'].includes(process.platform) ? describe : describe.skip, | ||
}; | ||
|
||
describe('JestRunnerConfig', () => { | ||
describes.windows('Windows style paths', () => { | ||
let jestRunnerConfig: JestRunnerConfig; | ||
beforeEach(() => { | ||
jestRunnerConfig = new JestRunnerConfig(); | ||
jest | ||
.spyOn(vscode.workspace, 'getWorkspaceFolder') | ||
.mockReturnValue(new WorkspaceFolder(new Uri('C:\\project') as any) as any); | ||
}); | ||
|
||
it.each([ | ||
['absolute path (with \\)', 'C:\\project\\jestProject'], | ||
['absolute path (with /)', 'C:/project/jestProject'], | ||
['relative path', './jestProject'], | ||
])('%s', (_testName, projectPath) => { | ||
jest.spyOn(vscode.workspace, 'getConfiguration').mockReturnValue( | ||
new WorkspaceConfiguration({ | ||
'jestrunner.projectPath': projectPath, | ||
}) | ||
); | ||
|
||
expect(jestRunnerConfig.projectPath).toBe('C:\\project\\jestProject'); | ||
}); | ||
}); | ||
|
||
describes.linux('Linux style paths', () => { | ||
let jestRunnerConfig: JestRunnerConfig; | ||
|
||
beforeEach(() => { | ||
jestRunnerConfig = new JestRunnerConfig(); | ||
jest | ||
.spyOn(vscode.workspace, 'getWorkspaceFolder') | ||
.mockReturnValue(new WorkspaceFolder(new Uri('/home/user/project') as any) as any); | ||
}); | ||
|
||
it.each([ | ||
['absolute path', '/home/user/project/jestProject'], | ||
['relative path', './jestProject'], | ||
])('%s', (_testName, projectPath) => { | ||
jest.spyOn(vscode.workspace, 'getConfiguration').mockReturnValue( | ||
new WorkspaceConfiguration({ | ||
'jestrunner.projectPath': projectPath, | ||
}) | ||
); | ||
|
||
expect(jestRunnerConfig.projectPath).toBe('/home/user/project/jestProject'); | ||
}); | ||
}); | ||
}); |