Skip to content

Commit

Permalink
Merge 25cb3c0 into b92c6f8
Browse files Browse the repository at this point in the history
  • Loading branch information
jgillick committed Jun 26, 2023
2 parents b92c6f8 + 25cb3c0 commit 21d9ca9
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -274,6 +274,7 @@ useDashedArgs| Determine if to use dashed arguments for jest processes |undefine
|debugMode|Enable debug mode to diagnose plugin issues. (see developer console)|false|`"jest.debugMode": true`|
|disabledWorkspaceFolders 💼|Disabled workspace folders names in multi-root environment|[]|`"jest.disabledWorkspaceFolders": ["package-a", "package-b"]`|
|[autoRevealOutput](#autoRevealOutput)|Determine when to show test output|"on-run"|`"jest.autoRevealOutput": "on-exec-error"`|
|autoClearTerminal|Clear the terminal output at the start of any new test run.|false|`"jest.autoClearTerminal": true`|

#### Details
##### jestCommandLine
Expand Down
5 changes: 5 additions & 0 deletions package.json
Expand Up @@ -78,6 +78,11 @@
"type": "string",
"scope": "resource"
},
"jest.autoClearTerminal": {
"description": "Clear the terminal output at the start of any new test run.",
"type": "boolean",
"scope": "resource"
},
"jest.rootPath": {
"description": "The path to your frontend src folder",
"type": "string",
Expand Down
1 change: 1 addition & 0 deletions src/JestExt/helper.ts
Expand Up @@ -111,6 +111,7 @@ export const getExtensionResourceSettings = (

return {
jestCommandLine: getSetting<string>('jestCommandLine'),
autoClearTerminal: getSetting<boolean>('autoClearTerminal') ?? false,
rootPath: toAbsoluteRootPath(workspaceFolder, getSetting<string>('rootPath')),
showCoverageOnLoad: getSetting<boolean>('showCoverageOnLoad') ?? false,
coverageFormatter: getSetting<string>('coverageFormatter') ?? 'DefaultFormatter',
Expand Down
7 changes: 7 additions & 0 deletions src/JestExt/output-terminal.ts
Expand Up @@ -133,6 +133,13 @@ export class ExtOutputTerminal implements JestExtOutput {
this.writeEmitter.dispose();
this._terminal?.dispose();
}

/**
* Clear the terminal
*/
clear(): void {
this.write('\x1bc');
}
}
export class JestOutputTerminal extends ExtOutputTerminal {
constructor(workspaceName: string, visible?: boolean) {
Expand Down
1 change: 1 addition & 0 deletions src/Settings/index.ts
Expand Up @@ -41,6 +41,7 @@ export type MonitorLongRun = 'off' | number;
export type AutoRevealOutputType = 'on-run' | 'on-exec-error' | 'off';
export interface PluginResourceSettings {
jestCommandLine?: string;
autoClearTerminal?: boolean;
rootPath: string;
showCoverageOnLoad: boolean;
coverageFormatter: string;
Expand Down
6 changes: 6 additions & 0 deletions src/test-provider/test-item-data.ts
Expand Up @@ -412,6 +412,9 @@ export class WorkspaceRoot extends TestItemDataBase {
run = this.createRunForEvent(event);
this.deepItemState(run.item, run.enqueued);
}
if (this.context.ext.settings.autoClearTerminal === true) {
this.context.output.clear();
}

break;
}
Expand All @@ -426,6 +429,9 @@ export class WorkspaceRoot extends TestItemDataBase {
case 'start': {
run = run ?? this.createRunForEvent(event);
this.deepItemState(run.item, run.started);
if (this.context.ext.settings.autoClearTerminal === true) {
this.context.output.clear();
}
this.runLog('started');
break;
}
Expand Down
1 change: 1 addition & 0 deletions tests/JestExt/helper.test.ts
Expand Up @@ -169,6 +169,7 @@ describe('getExtensionResourceSettings()', () => {
showCoverageOnLoad: false,
debugMode: false,
coverageColors: null,
autoClearTerminal: false,
autoRun: expect.objectContaining({ config: { watch: true } }),
testExplorer: {},
monitorLongRun: 60000,
Expand Down
6 changes: 6 additions & 0 deletions tests/JestExt/outpt-terminal.test.ts
Expand Up @@ -125,6 +125,12 @@ describe('JestOutputTerminal', () => {
expect(mockTerminal.dispose).toHaveBeenCalled();
expect(mockEmitter.dispose).not.toHaveBeenCalled();
});
it('can clear the terminal', () => {
const output = new JestOutputTerminal('a');
output.write = jest.fn().mockImplementation(() => 'test');
output.clear();
expect(output.write).toHaveBeenCalledWith('\x1bc');
});
describe('can write output with options', () => {
it.each`
case | text | options
Expand Down
2 changes: 1 addition & 1 deletion tests/test-provider/test-helper.ts
Expand Up @@ -41,7 +41,7 @@ export const mockExtExplorerContext = (wsName = 'ws-1', override: any = {}): any
debugTests: jest.fn(),
sessionEvents: mockJestExtEvents(),
settings: { testExplorer: { enabled: true }, autoRun: {} },
output: { write: jest.fn(), dispose: jest.fn() },
output: { write: jest.fn(), dispose: jest.fn(), clear: jest.fn() },
...override,
};
};
Expand Down
24 changes: 24 additions & 0 deletions tests/test-provider/test-item-data.test.ts
Expand Up @@ -1171,6 +1171,30 @@ describe('test-item-data', () => {
expect.stringContaining(coloredText)
);
});
describe('optionally clear terminal on start & schedule', () => {
let env;
beforeEach(() => {
env = setupTestEnv();
});
it.each([{ type: 'scheduled' }, { type: 'start' }])(
'$type: clear when autoClearTerminal is true',
({ type }) => {
context.ext.settings = { autoClearTerminal: true };
const process = mockScheduleProcess(context);
env.onRunEvent({ type, process });
expect(context.output.clear).toHaveBeenCalled();
}
);
it.each([{ type: 'scheduled' }, { type: 'start' }])(
'$type: do not clear when when autoClearTerminal is false',
({ type }) => {
context.ext.settings = { autoClearTerminal: false };
const process = mockScheduleProcess(context);
env.onRunEvent({ type, process });
expect(context.output.clear).not.toHaveBeenCalled();
}
);
});
describe('handle run event to set item status and show output', () => {
let env;
beforeEach(() => {
Expand Down

0 comments on commit 21d9ca9

Please sign in to comment.