77
88import * as assert from 'assert' ;
99import { expect } from 'chai' ;
10- import { Given , Then , When } from 'cucumber' ;
10+ import { Given , Then , When , World } from 'cucumber' ;
1111import * as fs from 'fs-extra' ;
1212import * as path from 'path' ;
1313import { CucumberRetryMax10Seconds , CucumberRetryMax5Seconds } from '../constants' ;
1414import { noop , retryWrapper , sleep } from '../helpers' ;
15- import { warn } from '../helpers/logger' ;
1615import { IApplication } from '../types' ;
1716
1817// tslint:disable-next-line: no-var-requires no-require-imports
1918const clipboardy = require ( 'clipboardy' ) ;
2019
21- // const autoCompletionListItemSlector = '.editor-widget.suggest-widget.visible .monaco-list-row a.label-name .monaco-highlighted-label';
22-
2320When ( 'I create a new file' , async function ( ) {
2421 await this . app . documents . createNewUntitledFile ( ) ;
2522} ) ;
@@ -36,29 +33,6 @@ When('I create a new file with the following content', async function(contents:
3633 await sleep ( 200 ) ;
3734} ) ;
3835
39- Given ( 'a file named {string} is created with the following content' , async function ( filename : string , contents : string ) {
40- const fullpath = path . join ( this . app . workspacePathOrFolder , filename ) ;
41- await fs . ensureDir ( path . dirname ( fullpath ) ) ;
42- await fs . writeFile ( fullpath , contents ) ;
43- // Ensure VS Code has had time to refresh to explorer and is aware of the file.
44- // Else if we later attempt to open this file, VSC might not be aware of it and woudn't display anything in the `quick open` dropdown.
45- const openRecentlyCreatedDocument = async ( ) => {
46- await this . app . documents . refreshExplorer ( ) ;
47- // Sometimes VS Code just doesn't know about files created from outside VS Code.
48- // Not unless we expand the file explorer.
49- // Hopefully we don't have (write) tests where files are created in nested folders and not detected by VSC, but required to be opened.
50- const opened = await this . app . quickopen
51- . openFile ( path . basename ( filename ) )
52- . then ( ( ) => true )
53- . catch ( ex => warn ( `Failed to open the file '${ filename } ' in VS Code, but continuing (hopefully file will not have to be opened)` , ex ) ) ;
54- if ( opened === true ) {
55- await this . app . quickopen . runCommand ( 'View: Close Editor' ) ;
56- }
57- } ;
58-
59- await retryWrapper ( { timeout : 5000 } , openRecentlyCreatedDocument ) ;
60- } ) ;
61-
6236When ( 'I change the language of the file to {string}' , async function ( language : string ) {
6337 await this . app . quickopen . runCommand ( 'Change Language Mode' ) ;
6438 await this . app . quickinput . select ( { value : language } ) ;
@@ -103,19 +77,19 @@ Then('the file {string} is opened', async function(file: string) {
10377 await this . app . documents . waitUntilFileOpened ( file ) ;
10478} ) ;
10579
106- // Then('a file named {string} is created with the following content', async (fileName: string, contents: string) => {
107- // const fullFilePath = path.join(context.app.workspacePathOrFolder, fileName);
108- // await fs.mkdirp(path.dirname(fullFilePath)).catch(noop);
109- // await fs.writeFile(fullFilePath, contents);
110- // await sleep(1000);
111- // });
80+ async function createFile ( this : World , filename : string , contents : string ) {
81+ const fullpath = path . join ( this . app . workspacePathOrFolder , filename ) ;
82+ await fs . ensureDir ( path . dirname ( fullpath ) ) ;
83+ await fs . writeFile ( fullpath , contents ) ;
84+ }
11285
113- // When('the file {string} has the following content', async (fileName: string, contents: string) => {
114- // const fullFilePath = path.join(context.app.workspacePathOrFolder, fileName);
115- // await fs.mkdirp(path.dirname(fullFilePath)).catch(noop);
116- // await fs.writeFile(fullFilePath, contents);
117- // await sleep(1000);
118- // });
86+ Given ( 'a file named {string} is created with the following content' , async function ( filename : string , contents : string ) {
87+ await createFile . call ( this , filename , contents ) ;
88+ } ) ;
89+
90+ When ( 'the file {string} has the following content' , async function ( filename : string , contents : string ) {
91+ await createFile . call ( this , filename , contents ) ;
92+ } ) ;
11993
12094Given ( 'a file named {string} does not exist' , async function ( fileName : string ) {
12195 const fullFilePath = path . join ( this . app . workspacePathOrFolder , fileName ) ;
@@ -128,12 +102,6 @@ Given('the file {string} does not exist', async function(fileName: string) {
128102 await sleep ( 1000 ) ;
129103} ) ;
130104
131- // Then('a file named {string} exists', async (fileName: string) => {
132- // const fullFilePath = path.join(context.app.workspacePathOrFolder, fileName);
133- // const exists = await fs.pathExists(fullFilePath);
134- // expect(exists).to.equal(true, `File '${fullFilePath}' should exist`);
135- // });
136-
137105async function expectFile ( app : IApplication , fileName : string , timeout = 1000 ) {
138106 const checkFile = async ( ) => {
139107 const fullFilePath = path . join ( app . workspacePathOrFolder , fileName ) ;
0 commit comments