import * as vscode from 'vscode' ; import { TestsExplorerDataProvider , Testable , } from './testsExplorerDataProvider' ; import { DEFAULT_TEST_FILE_PATTERNS } from './constants' ; import { getConfig , ConfigOption } from './config' ; import { JestDoItCodeLensProvider } from './jestDoItCodeLensProvider' ; import { runTest , debugTest } from './commands' ; import { ArgumentQuotesMode } from './types' ; export const quoteArgument = ( argumentToQuote , quotesToUse ? ) : string => { if ( quotesToUse === undefined ) { quotesToUse = ( getConfig ( ConfigOption . ArgumentQuotesToUse ) as ArgumentQuotesMode ) || 'auto' ; } if ( quotesToUse === 'auto' ) { quotesToUse = process . platform === 'win32' ? 'double' : 'single' ; } switch ( quotesToUse ) { case 'double' : return `"${ argumentToQuote . replace ( /"/g , '\\"' ) }"` ; case 'single' : return `'${ argumentToQuote . replace ( /'/g , '\\\'' ) }'` ; default : return argumentToQuote ; } } ; export const quoteTestName = ( testName , quotesToUse ? ) => { const escapedTestName = testName . replace ( /[.*+?^${}()|[\]\\]/g , '\\$&' ) ; return quoteArgument ( escapedTestName , quotesToUse ) ; } ; export const getTerminal = ( terminalName ) => { return vscode . window . terminals . find ( t => t . name === terminalName ) ; } ; const runTestFromExplorer = ( testable ) => { runTest ( testable . file , testable . label ) ; } ; const debugTestFromExplorer = ( testable ) => { debugTest ( testable . file , testable . label ) ; } ; const runTestFromEditor = ( uri ) => { const filePath = uri . fsPath ; runTest ( filePath ) ; } ; const debugTestFromEditor = ( uri ) => { const filePath = uri . fsPath ; debugTest ( filePath ) ; } ; export const activate = ( context ) => { const testsExplorerDataProvider = new TestsExplorerDataProvider ( ) ; vscode . window . registerTreeDataProvider ( 'jestRunItTestsExplorer' , testsExplorerDataProvider ) ; const runTestCommand = vscode . commands . registerCommand ( 'jestRunItCodeLens.runTest' , runTest ) ; context . subscriptions . push ( runTestCommand ) ; const debugTestCommand = vscode . commands . registerCommand ( 'jestRunItCodeLens.debugTest' , debugTest ) ; context . subscriptions . push ( debugTestCommand ) ; const updateSnapshotFromExplorerCommand = vscode . commands . registerCommand ( 'jestRunItCodeLens.updateSnapshots' , ( filePath , testName ? ) => runTest ( filePath , testName , true ) ) ; context . subscriptions . push ( updateSnapshotFromExplorerCommand ) ; const runTestFromExplorerCommand = vscode . commands . registerCommand ( 'jestRunItTestsExplorer.runTest' , runTestFromExplorer ) ; context . subscriptions . push ( runTestFromExplorerCommand ) ; const debugTestFromExplorerCommand = vscode . commands . registerCommand ( 'jestRunItTestsExplorer.debugTest' , debugTestFromExplorer ) ; context . subscriptions . push ( debugTestFromExplorerCommand ) ; const runTestFromEditorCommand = vscode . commands . registerCommand ( 'jestRunItTestsEditor.runTest' , runTestFromEditor ) ; context . subscriptions . push ( runTestFromEditorCommand ) ; const debugTestFromEditorCommand = vscode . commands . registerCommand ( 'jestRunItTestsEditor.debugTest' , debugTestFromEditor ) ; context . subscriptions . push ( debugTestFromEditorCommand ) ; let patterns = [ ] ; const testMatchPatternsConfig = getConfig ( ConfigOption . TestMatchPatterns ) as Array < string > ; if ( Array . isArray ( testMatchPatternsConfig ) ) { patterns = testMatchPatternsConfig . map ( tm => ( { pattern : tm , scheme : 'file' , } ) ) ; } else { patterns = DEFAULT_TEST_FILE_PATTERNS . map ( tm => ( { pattern : tm , scheme : 'file' , } ) ) ; } const codeLensProviderDisposable = vscode . languages . registerCodeLensProvider ( patterns , new JestDoItCodeLensProvider ( ) ) ; context . subscriptions . push ( codeLensProviderDisposable ) ; } ; export function deactivate ( ) { }