diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 333ab42ef51..47f0a91b286 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2293,9 +2293,13 @@ Actual: ${stringify(fullActual)}`); } public verifyCurrentFileContent(text: string) { - const actual = this.getFileContent(this.activeFile.fileName); + this.verifyFileContent(this.activeFile.fileName, text); + } + + private verifyFileContent(fileName: string, text: string) { + const actual = this.getFileContent(fileName); if (actual !== text) { - throw new Error(`verifyCurrentFileContent failed:\n${showTextDiff(text, actual)}`); + throw new Error(`verifyFileContent failed:\n${showTextDiff(text, actual)}`); } } @@ -2483,7 +2487,7 @@ Actual: ${stringify(fullActual)}`); this.applyCodeActions(details.codeActions); - this.verifyNewContent(options); + this.verifyNewContent(options, ts.flatMap(details.codeActions, a => a.changes.map(c => c.fileName))); } public verifyRangeIs(expectedText: string, includeWhiteSpace?: boolean) { @@ -2570,13 +2574,25 @@ Actual: ${stringify(fullActual)}`); this.applyEdits(change.fileName, change.textChanges, /*isFormattingEdit*/ false); } - this.verifyNewContent(options); + this.verifyNewContent(options, action.changes.map(c => c.fileName)); } - private verifyNewContent(options: FourSlashInterface.NewContentOptions) { + private verifyNewContent(options: FourSlashInterface.NewContentOptions, changedFiles: ReadonlyArray) { + const assertedChangedFiles = !options.newFileContent || typeof options.newFileContent === "string" + ? [this.activeFile.fileName] + : ts.getOwnKeys(options.newFileContent); + assert.deepEqual(assertedChangedFiles, changedFiles); + if (options.newFileContent !== undefined) { assert(!options.newRangeContent); - this.verifyCurrentFileContent(options.newFileContent); + if (typeof options.newFileContent === "string") { + this.verifyCurrentFileContent(options.newFileContent); + } + else { + for (const fileName in options.newFileContent) { + this.verifyFileContent(fileName, options.newFileContent[fileName]); + } + } } else { this.verifyRangeIs(options.newRangeContent, /*includeWhitespace*/ true); @@ -4781,7 +4797,7 @@ namespace FourSlashInterface { export interface NewContentOptions { // Exactly one of these should be defined. - newFileContent?: string; + newFileContent?: string | { readonly [filename: string]: string }; newRangeContent?: string; } diff --git a/src/services/codefixes/convertToEs6Module.ts b/src/services/codefixes/convertToEs6Module.ts index 57af2edcd01..92a14b1d20d 100644 --- a/src/services/codefixes/convertToEs6Module.ts +++ b/src/services/codefixes/convertToEs6Module.ts @@ -233,7 +233,7 @@ namespace ts.codefix { Debug.assertNever(prop); } }); - return statements && [statements, true]; + return statements && [statements, false]; } function convertNamedExport( diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 704163ae576..b8b06edca15 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -179,7 +179,7 @@ declare namespace FourSlashInterface { isInCommentAtPosition(onlyMultiLineDiverges?: boolean): void; codeFix(options: { description: string, - newFileContent?: string, + newFileContent?: string | { readonly [fileName: string]: string }, newRangeContent?: string, errorCode?: number, index?: number, diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_export_moduleDotExports_changesImports.ts b/tests/cases/fourslash/refactorConvertToEs6Module_export_moduleDotExports_changesImports.ts index 277525e10fe..ddc6a77721e 100644 --- a/tests/cases/fourslash/refactorConvertToEs6Module_export_moduleDotExports_changesImports.ts +++ b/tests/cases/fourslash/refactorConvertToEs6Module_export_moduleDotExports_changesImports.ts @@ -14,11 +14,9 @@ verify.codeFix({ description: "Convert to ES6 module", - newFileContent: "export default 0;", + newFileContent: { + "/a.js": "export default 0;", + "/b.ts": 'import a from "./a";', + "/c.js": 'const a = require("./a").default;', + } }); - -goTo.file("/b.ts"); -verify.currentFileContentIs('import a from "./a";'); - -goTo.file("/c.js"); -verify.currentFileContentIs('const a = require("./a").default;'); diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_export_object.ts b/tests/cases/fourslash/refactorConvertToEs6Module_export_object.ts index 5b9107f275c..97056ceefda 100644 --- a/tests/cases/fourslash/refactorConvertToEs6Module_export_object.ts +++ b/tests/cases/fourslash/refactorConvertToEs6Module_export_object.ts @@ -12,6 +12,9 @@ //// C: class {}, ////}; +// @Filename: /b.js +////const a = require("./a.js"); + verify.codeFix({ description: "Convert to ES6 module", newFileContent: