Skip to content
Prev Previous commit
Next Next commit
Add more tests
  • Loading branch information
Richard Lynch committed Jun 23, 2022
commit a71c68f253370ef924e037b7c7364c58801b9aef
2 changes: 2 additions & 0 deletions tests/cases/fourslash/codeFixImportNonExportedMember1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
////import { bar } from "./b";

goTo.file("/c.ts");
// Recognises that importing from a file with a `declare` is ok if its exported
verify.codeFixAvailable([
{ description: `Export 'bar' from module './b'` },
{ description: `Remove import from './a'` },
{ description: `Remove import from './b'` },
]);
// Exports a function with a `declare` correctly
verify.codeFix({
index: 0,
description: `Export 'bar' from module './b'`,
Expand Down
22 changes: 12 additions & 10 deletions tests/cases/fourslash/codeFixImportNonExportedMember2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ verify.codeFixAvailable([
{ description: `Remove import from './a'` },
{ description: `Remove import from './b'` },
]);

// Can fix a single variable
verify.codeFix({
index: 1,
description: `Export 'd' from module './b'`,
newFileContent: {
"/b.ts": `export let d = 4;
export function whatever2() {
}`,
},
});
// Can fix a variable in a list (adds a named export)
verify.codeFix({
index: 0,
description: `Export 'a' from module './a'`,
Expand All @@ -33,13 +45,3 @@ export { a };
`,
},
});

verify.codeFix({
index: 1,
description: `Export 'd' from module './b'`,
newFileContent: {
"/b.ts": `export let d = 4;
export function whatever2() {
}`,
},
});
1 change: 1 addition & 0 deletions tests/cases/fourslash/codeFixImportNonExportedMember3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ verify.codeFixAvailable([
{ description: `Export 'a' from module './a'` },
{ description: `Remove import from './a'` },
]);
// Can export from list using an existing export
verify.codeFix({
index: 0,
description: `Export 'a' from module './a'`,
Expand Down
1 change: 1 addition & 0 deletions tests/cases/fourslash/codeFixImportNonExportedMember4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
// @Filename: /a.ts
////import { a } from "foo";

// Won't apply fix if `module.exports` is used
verify.not.codeFixAvailable();
18 changes: 13 additions & 5 deletions tests/cases/fourslash/codeFixImportNonExportedMember5.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
/// <reference path='fourslash.ts' />
// @Filename: /a.ts
/////**
//// * hello
//// * foo
//// */
////function a() {
////}
////export { d }
/////**
//// * bar
//// */
////let b = 4;

// @Filename: /b.ts
////import { a, d } from "./a"
////import { a, b } from "./a"

goTo.file("/b.ts");
verify.codeFixAvailable([
{ description: `Export 'a' from module './a'` },
{ description: `Export 'b' from module './a'` },
{ description: `Remove import from './a'` },
]);
// Doesn't clobber jsdoc on functions
verify.codeFix({
index: 0,
description: `Export 'a' from module './a'`,
newFileContent: {
"/a.ts": `/**
* hello
* foo
*/
export function a() {
}
export { d }`,
/**
* bar
*/
let b = 4;`,
},
});
39 changes: 28 additions & 11 deletions tests/cases/fourslash/codeFixImportNonExportedMember6.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,44 @@
/// <reference path='fourslash.ts' />
// @Filename: /a.ts
////let a = 1, b = 2, c = 3;
////let d = 4;
////export function whatever() {
////}
////export { a }
////class a{};
////class b{}, class c{};

// @Filename: /b.ts
////import { a, b } from "./a"
////import { a, b, c } from "./a"

goTo.file("/b.ts");
verify.codeFixAvailable([
{ description: `Export 'a' from module './a'` },
{ description: `Export 'b' from module './a'` },
{ description: `Export 'c' from module './a'` },
{ description: `Remove import from './a'` },
]);
// Can export a class
verify.codeFix({
index: 0,
description: `Export 'a' from module './a'`,
newFileContent: {
"/a.ts": `export class a{};
class b{}, class c{};`,
},
});

// Can export first class in list
verify.codeFix({
index: 0,
description: `Export 'b' from module './a'`,
newFileContent: {
"/a.ts": `let a = 1, b = 2, c = 3;
let d = 4;
export function whatever() {
}
export { a, b };`,
"/a.ts": `class a{};
export class b{}, class c{};`,
},
});

// Can export second class in list
verify.codeFix({
index: 0,
description: `Export 'c' from module './a'`,
newFileContent: {
"/a.ts": `class a{};
class b{}, export class c{};`,
},
});