Skip to content

Commit

Permalink
Merge 904d48d into 19e9269
Browse files Browse the repository at this point in the history
  • Loading branch information
connectdotz committed Nov 23, 2021
2 parents 19e9269 + 904d48d commit 5faf8b0
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 32 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@
],
"editor/context": [
{
"when": "jest:run.interactive && editorLangId =~ /(javascript|javascriptreact|typescript|typescriptreact)/ ",
"when": "jest:run.interactive && editorLangId =~ /(javascript|javascriptreact|typescript|typescriptreact|vue)/ ",
"command": "io.orta.jest.editor.run-all-tests",
"group": "Jest"
}
Expand All @@ -319,7 +319,7 @@
"command": "io.orta.jest.editor.run-all-tests",
"key": "ctrl+alt+t",
"mac": "ctrl+alt+t",
"when": "jest:run.interactive && editorLangId =~ /(javascript|javascriptreact|typescript|typescriptreact)/ "
"when": "jest:run.interactive && editorLangId =~ /(javascript|javascriptreact|typescript|typescriptreact|vue)/ "
}
],
"debuggers": [
Expand Down
6 changes: 4 additions & 2 deletions src/JestExt/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ export class JestExt {
this.processSession.scheduleProcess({
type: 'by-file',
testFileName: name,
notTestFile: this.testResultProvider.isTestFile(name) !== 'yes',
})
) {
this.dirtyFiles.delete(name);
Expand Down Expand Up @@ -524,14 +525,15 @@ export class JestExt {
if (!this.isSupportedDocument(document) || this.extContext.autoRun.isWatch) {
return;
}
const isTestFile = this.testResultProvider.isTestFile(document.fileName);
if (
this.extContext.autoRun.onSave &&
(this.extContext.autoRun.onSave === 'test-src-file' ||
this.testResultProvider.isTestFile(document.fileName) !== 'no')
(this.extContext.autoRun.onSave === 'test-src-file' || isTestFile !== 'no')
) {
this.processSession.scheduleProcess({
type: 'by-file',
testFileName: document.fileName,
notTestFile: isTestFile !== 'yes',
});
} else {
this.dirtyFiles.add(document.fileName);
Expand Down
5 changes: 4 additions & 1 deletion src/JestProcessManagement/JestProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ export class JestProcess implements JestProcessInfo {
break;
case 'by-file': {
options.testFileNamePattern = this.quoteFileName(this.request.testFileName);
args.push('--findRelatedTests', '--watchAll=false');
args.push('--watchAll=false');
if (this.request.notTestFile) {
args.push('--findRelatedTests');
}
if (this.request.updateSnapshot) {
args.push('--updateSnapshot');
}
Expand Down
1 change: 1 addition & 0 deletions src/JestProcessManagement/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export type JestProcessRequestBase =
type: Extract<JestTestProcessType, 'by-file'>;
testFileName: string;
updateSnapshot?: boolean;
notTestFile?: boolean;
}
| {
type: Extract<JestTestProcessType, 'by-file-test'>;
Expand Down
1 change: 1 addition & 0 deletions src/appGlobals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export const SupportedLanguageIds = [
'javascriptreact',
'typescript',
'typescriptreact',
'vue',
];
1 change: 1 addition & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const addSubscriptions = (context: vscode.ExtensionContext): void => {
{ language: 'javascriptreact' },
{ language: 'typescript' },
{ language: 'typescriptreact' },
{ language: 'vue' },
];

// command function
Expand Down
11 changes: 4 additions & 7 deletions src/test-provider/test-item-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ export class WorkspaceRoot extends TestItemDataBase {
}
};

private getItemFromProcess = (process: JestProcessInfo): vscode.TestItem => {
/** get test item from jest process. If running tests from source file, will return undefined */
private getItemFromProcess = (process: JestProcessInfo): vscode.TestItem | undefined => {
let fileName;
switch (process.request.type) {
case 'watch-tests':
Expand All @@ -270,15 +271,11 @@ export class WorkspaceRoot extends TestItemDataBase {
throw new Error(`unsupported external process type ${process.request.type}`);
}

const item = this.testDocuments.get(fileName)?.item;
if (item) {
return item;
}
throw new Error(`No test file found for ${fileName}`);
return this.testDocuments.get(fileName)?.item;
};

private createTestItemRun = (event: JestRunEvent): TestItemRun => {
const item = this.getItemFromProcess(event.process);
const item = this.getItemFromProcess(event.process) ?? this.item;
const run = this.createRun(`${event.type}:${event.process.id}`, item);
const end = () => {
this.cachedRun.delete(event.process.id);
Expand Down
81 changes: 68 additions & 13 deletions tests/JestExt/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ describe('JestExt', () => {
${{ watch: true }} | ${'javascript'} | ${'yes'} | ${false} | ${false}
${{ watch: false }} | ${'javascript'} | ${'yes'} | ${false} | ${true}
${{ watch: false, onSave: 'test-src-file' }} | ${'javascript'} | ${'no'} | ${true} | ${false}
${{ watch: false, onSave: 'test-src-file' }} | ${'javascript'} | ${'unknown'} | ${true} | ${false}
${{ watch: false, onSave: 'test-src-file' }} | ${'javascript'} | ${'yes'} | ${true} | ${false}
${{ watch: false, onSave: 'test-src-file' }} | ${'json'} | ${'no'} | ${false} | ${false}
${{ watch: false, onSave: 'test-file' }} | ${'javascript'} | ${'no'} | ${false} | ${true}
Expand Down Expand Up @@ -533,7 +534,11 @@ describe('JestExt', () => {

if (shouldSchedule) {
expect(mockProcessSession.scheduleProcess).toBeCalledWith(
expect.objectContaining({ type: 'by-file', testFileName: fileName })
expect.objectContaining({
type: 'by-file',
testFileName: fileName,
notTestFile: isTestFile !== 'yes',
})
);
} else {
expect(mockProcessSession.scheduleProcess).not.toBeCalled();
Expand Down Expand Up @@ -651,6 +656,7 @@ describe('JestExt', () => {
${'javascriptreact'} | ${false}
${'typescript'} | ${false}
${'typescriptreact'} | ${false}
${'vue'} | ${false}
`('if languageId=languageId => skip? $shouldSkip', ({ languageId, shouldSkip }) => {
const editor = mockEditor('file', languageId);
sut.triggerUpdateActiveEditor(editor);
Expand Down Expand Up @@ -887,20 +893,69 @@ describe('JestExt', () => {
});
});
describe('runAllTests', () => {
it('can run all test for the workspace', () => {
const sut = newJestExt();
sut.runAllTests();
expect(mockProcessSession.scheduleProcess).toBeCalledWith({ type: 'all-tests' });
});
it('can run all test for the given editor', () => {
const sut = newJestExt();
const editor: any = { document: { fileName: 'whatever' } };
sut.runAllTests(editor);
expect(mockProcessSession.scheduleProcess).toBeCalledWith({
type: 'by-file',
testFileName: 'whatever',
describe.each`
scheduleProcess
${{}}
${undefined}
`('scheduleProcess returns $scheduleProcess', ({ scheduleProcess }) => {
beforeEach(() => {
mockProcessSession.scheduleProcess.mockReturnValueOnce(scheduleProcess);
});
it('can run all test for the workspace', () => {
const sut = newJestExt();
const dirtyFiles: any = sut['dirtyFiles'];
dirtyFiles.clear = jest.fn();

sut.runAllTests();
expect(mockProcessSession.scheduleProcess).toBeCalledWith({ type: 'all-tests' });
if (scheduleProcess) {
expect(dirtyFiles.clear).toBeCalled();
} else {
expect(dirtyFiles.clear).not.toBeCalled();
}
});
it('can run all test for the given editor', () => {
const sut = newJestExt();

const dirtyFiles: any = sut['dirtyFiles'];
dirtyFiles.delete = jest.fn();

const editor: any = { document: { fileName: 'whatever' } };

sut.runAllTests(editor);
expect(mockProcessSession.scheduleProcess).toBeCalledWith({
type: 'by-file',
testFileName: editor.document.fileName,
notTestFile: true,
});
if (scheduleProcess) {
expect(dirtyFiles.delete).toBeCalledWith(editor.document.fileName);
} else {
expect(dirtyFiles.delete).not.toBeCalled();
}
});
});
it.each`
isTestFile | notTestFile
${'yes'} | ${false}
${'no'} | ${true}
${'unknown'} | ${true}
`(
'treat unknown as notTestFile: isTestFile=$isTestFile => notTestFile=$notTestFile',
({ isTestFile, notTestFile }) => {
const sut = newJestExt();
const editor: any = { document: { fileName: 'whatever' } };

(sut.testResultProvider.isTestFile as jest.Mocked<any>).mockReturnValueOnce(isTestFile);

sut.runAllTests(editor);
expect(mockProcessSession.scheduleProcess).toBeCalledWith({
type: 'by-file',
testFileName: editor.document.fileName,
notTestFile: notTestFile,
});
}
);
});
describe('refresh test file list upon file system change', () => {
const getProcessType = () => {
Expand Down
3 changes: 2 additions & 1 deletion tests/JestProcessManagement/JestProcess.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ describe('JestProcess', () => {
${'all-tests'} | ${undefined} | ${[false, false]} | ${true} | ${undefined}
${'watch-tests'} | ${undefined} | ${[true, false]} | ${true} | ${undefined}
${'watch-all-tests'} | ${undefined} | ${[true, true]} | ${true} | ${undefined}
${'by-file'} | ${{ testFileName: '"c:\\a\\b.ts"' }} | ${[false, false]} | ${true} | ${{ args: { args: ['--findRelatedTests'] }, testFileNamePattern: '"C:\\a\\b.ts"' }}
${'by-file'} | ${{ testFileName: '"c:\\a\\b.ts"' }} | ${[false, false]} | ${true} | ${{ args: { args: [] }, testFileNamePattern: '"C:\\a\\b.ts"' }}
${'by-file'} | ${{ testFileName: '"c:\\a\\b.ts"', notTestFile: true }} | ${[false, false]} | ${true} | ${{ args: { args: ['--findRelatedTests'] }, testFileNamePattern: '"C:\\a\\b.ts"' }}
${'by-file-test'} | ${{ testFileName: '"/a/b.js"', testNamePattern: 'a test' }} | ${[false, false]} | ${true} | ${{ args: { args: ['--runTestsByPath'] }, testFileNamePattern: '"/a/b.js"', testNamePattern: '"a test"' }}
${'by-file-pattern'} | ${{ testFileNamePattern: '"c:\\a\\b.ts"' }} | ${[false, false]} | ${true} | ${{ args: { args: ['--testPathPattern', '"c:\\\\a\\\\b\\.ts"'] } }}
${'by-file-test-pattern'} | ${{ testFileNamePattern: '/a/b.js', testNamePattern: 'a test' }} | ${[false, false]} | ${true} | ${{ args: { args: ['--testPathPattern', '"/a/b\\.js"'] }, testNamePattern: '"a test"' }}
Expand Down
13 changes: 7 additions & 6 deletions tests/test-provider/test-item-data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1092,12 +1092,13 @@ describe('test-item-data', () => {
controllerMock.createTestRun.mockClear();
});
describe.each`
request | withFile
${{ type: 'watch-tests' }} | ${false}
${{ type: 'watch-all-tests' }} | ${false}
${{ type: 'all-tests' }} | ${false}
${{ type: 'by-file', testFileName: file }} | ${true}
${{ type: 'by-file-pattern', testFileNamePattern: file }} | ${true}
request | withFile
${{ type: 'watch-tests' }} | ${false}
${{ type: 'watch-all-tests' }} | ${false}
${{ type: 'all-tests' }} | ${false}
${{ type: 'by-file', testFileName: file }} | ${true}
${{ type: 'by-file', testFileName: 'source.ts', notTestFile: true }} | ${false}
${{ type: 'by-file-pattern', testFileNamePattern: file }} | ${true}
`('will create a new run and use it throughout: $request', ({ request, withFile }) => {
it('if run starts before schedule returns: no enqueue', () => {
const process = { id: 'whatever', request };
Expand Down

0 comments on commit 5faf8b0

Please sign in to comment.