Skip to content

Commit ef56a32

Browse files
committed
tsc -b file delete tests
1 parent 79db93d commit ef56a32

File tree

5 files changed

+655
-4
lines changed

5 files changed

+655
-4
lines changed

internal/execute/testsys_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,12 @@ func (s *testSys) writeFileNoError(path string, content string, writeByteOrderMa
523523
}
524524
}
525525

526+
func (s *testSys) removeNoError(path string) {
527+
if err := s.fsFromFileMap().Remove(path); err != nil {
528+
panic(err)
529+
}
530+
}
531+
526532
func (s *testSys) replaceFileText(path string, oldText string, newText string) {
527533
content, ok := s.fsFromFileMap().ReadFile(path)
528534
if !ok {

internal/execute/tscbuild_test.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,91 @@ func TestBuildEmitDeclarationOnly(t *testing.T) {
305305
}
306306
}
307307

308+
func TestBuildFileDelete(t *testing.T) {
309+
t.Parallel()
310+
testCases := []*tscInput{
311+
{
312+
subScenario: "detects deleted file",
313+
files: FileMap{
314+
"/home/src/workspaces/solution/child/child.ts": stringtestutil.Dedent(`
315+
import { child2 } from "../child/child2";
316+
export function child() {
317+
child2();
318+
}
319+
`),
320+
"/home/src/workspaces/solution/child/child2.ts": stringtestutil.Dedent(`
321+
export function child2() {
322+
}
323+
`),
324+
"/home/src/workspaces/solution/child/tsconfig.json": stringtestutil.Dedent(`
325+
{
326+
"compilerOptions": { "composite": true }
327+
}
328+
`),
329+
"/home/src/workspaces/solution/main/main.ts": stringtestutil.Dedent(`
330+
import { child } from "../child/child";
331+
export function main() {
332+
child();
333+
}
334+
`),
335+
"/home/src/workspaces/solution/main/tsconfig.json": stringtestutil.Dedent(`
336+
{
337+
"compilerOptions": { "composite": true },
338+
"references": [{ "path": "../child" }],
339+
}
340+
`),
341+
},
342+
cwd: "/home/src/workspaces/solution",
343+
commandLineArgs: []string{"--b", "main/tsconfig.json", "-v", "--traceResolution", "--explainFiles"},
344+
edits: []*tscEdit{
345+
{
346+
caption: "delete child2 file",
347+
edit: func(sys *testSys) {
348+
sys.removeNoError("/home/src/workspaces/solution/child/child2.ts")
349+
sys.removeNoError("/home/src/workspaces/solution/child/child2.js")
350+
sys.removeNoError("/home/src/workspaces/solution/child/child2.d.ts")
351+
},
352+
},
353+
},
354+
},
355+
{
356+
subScenario: "deleted file without composite",
357+
files: FileMap{
358+
"/home/src/workspaces/solution/child/child.ts": stringtestutil.Dedent(`
359+
import { child2 } from "../child/child2";
360+
export function child() {
361+
child2();
362+
}
363+
`),
364+
"/home/src/workspaces/solution/child/child2.ts": stringtestutil.Dedent(`
365+
export function child2() {
366+
}
367+
`),
368+
"/home/src/workspaces/solution/child/tsconfig.json": stringtestutil.Dedent(`
369+
{
370+
"compilerOptions": { }
371+
}
372+
`),
373+
},
374+
cwd: "/home/src/workspaces/solution",
375+
commandLineArgs: []string{"--b", "child/tsconfig.json", "-v", "--traceResolution", "--explainFiles"},
376+
edits: []*tscEdit{
377+
{
378+
caption: "delete child2 file",
379+
edit: func(sys *testSys) {
380+
sys.removeNoError("/home/src/workspaces/solution/child/child2.ts")
381+
sys.removeNoError("/home/src/workspaces/solution/child/child2.js")
382+
},
383+
},
384+
},
385+
},
386+
}
387+
388+
for _, test := range testCases {
389+
test.run(t, "fileDelete")
390+
}
391+
}
392+
308393
func TestBuildSolutionProject(t *testing.T) {
309394
t.Parallel()
310395
testCases := []*tscInput{

internal/execute/tscincremental_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,7 @@ func TestIncremental(t *testing.T) {
415415
{
416416
caption: "delete file with imports",
417417
edit: func(sys *testSys) {
418-
err := sys.fsFromFileMap().Remove("/home/src/workspaces/project/file2.ts")
419-
if err != nil {
420-
panic(err)
421-
}
418+
sys.removeNoError("/home/src/workspaces/project/file2.ts")
422419
},
423420
},
424421
},
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
currentDirectory::/home/src/workspaces/solution
2+
useCaseSensitiveFileNames::true
3+
Input::
4+
//// [/home/src/workspaces/solution/child/child.ts] *new*
5+
import { child2 } from "../child/child2";
6+
export function child() {
7+
child2();
8+
}
9+
//// [/home/src/workspaces/solution/child/child2.ts] *new*
10+
export function child2() {
11+
}
12+
//// [/home/src/workspaces/solution/child/tsconfig.json] *new*
13+
{
14+
"compilerOptions": { }
15+
}
16+
17+
tsgo --b child/tsconfig.json -v --traceResolution --explainFiles
18+
ExitStatus:: Success
19+
Output::
20+
[HH:MM:SS AM] Projects in this build:
21+
* child/tsconfig.json
22+
23+
[HH:MM:SS AM] Project 'child/tsconfig.json' is out of date because output file 'child/tsconfig.tsbuildinfo' does not exist
24+
25+
[HH:MM:SS AM] Building project 'child/tsconfig.json'...
26+
27+
======== Resolving module '../child/child2' from '/home/src/workspaces/solution/child/child.ts'. ========
28+
Module resolution kind is not specified, using 'Bundler'.
29+
Resolving in CJS mode with conditions 'require', 'types'.
30+
Loading module as file / folder, candidate module location '/home/src/workspaces/solution/child/child2', target file types: TypeScript, JavaScript, Declaration, JSON.
31+
File '/home/src/workspaces/solution/child/child2.ts' exists - use it as a name resolution result.
32+
======== Module name '../child/child2' was successfully resolved to '/home/src/workspaces/solution/child/child2.ts'. ========
33+
../../tslibs/TS/Lib/lib.d.ts
34+
Default library for target 'ES5'
35+
child/child2.ts
36+
Imported via ../child/child2 from file 'child/child.ts'
37+
Matched by default include pattern '**/*'
38+
child/child.ts
39+
Matched by default include pattern '**/*'
40+
//// [/home/src/tslibs/TS/Lib/lib.d.ts] *Lib*
41+
/// <reference no-default-lib="true"/>
42+
interface Boolean {}
43+
interface Function {}
44+
interface CallableFunction {}
45+
interface NewableFunction {}
46+
interface IArguments {}
47+
interface Number { toExponential: any; }
48+
interface Object {}
49+
interface RegExp {}
50+
interface String { charAt: any; }
51+
interface Array<T> { length: number; [n: number]: T; }
52+
interface ReadonlyArray<T> {}
53+
interface SymbolConstructor {
54+
(desc?: string | number): symbol;
55+
for(name: string): symbol;
56+
readonly toStringTag: symbol;
57+
}
58+
declare var Symbol: SymbolConstructor;
59+
interface Symbol {
60+
readonly [Symbol.toStringTag]: string;
61+
}
62+
declare const console: { log(msg: any): void; };
63+
//// [/home/src/workspaces/solution/child/child.js] *new*
64+
"use strict";
65+
Object.defineProperty(exports, "__esModule", { value: true });
66+
exports.child = child;
67+
const child2_1 = require("../child/child2");
68+
function child() {
69+
(0, child2_1.child2)();
70+
}
71+
72+
//// [/home/src/workspaces/solution/child/child2.js] *new*
73+
"use strict";
74+
Object.defineProperty(exports, "__esModule", { value: true });
75+
exports.child2 = child2;
76+
function child2() {
77+
}
78+
79+
//// [/home/src/workspaces/solution/child/tsconfig.tsbuildinfo] *new*
80+
{"version":"FakeTSVersion","root":["./child.ts","./child2.ts"]}
81+
//// [/home/src/workspaces/solution/child/tsconfig.tsbuildinfo.readable.baseline.txt] *new*
82+
{
83+
"version": "FakeTSVersion",
84+
"root": [
85+
{
86+
"files": [
87+
"./child.ts"
88+
],
89+
"original": "./child.ts"
90+
},
91+
{
92+
"files": [
93+
"./child2.ts"
94+
],
95+
"original": "./child2.ts"
96+
}
97+
],
98+
"size": 63
99+
}
100+
101+
child/tsconfig.json::
102+
SemanticDiagnostics::
103+
*refresh* /home/src/tslibs/TS/Lib/lib.d.ts
104+
*refresh* /home/src/workspaces/solution/child/child2.ts
105+
*refresh* /home/src/workspaces/solution/child/child.ts
106+
Signatures::
107+
108+
109+
Edit [0]:: delete child2 file
110+
//// [/home/src/workspaces/solution/child/child2.js] *deleted*
111+
//// [/home/src/workspaces/solution/child/child2.ts] *deleted*
112+
113+
tsgo --b child/tsconfig.json -v --traceResolution --explainFiles
114+
ExitStatus:: DiagnosticsPresent_OutputsGenerated
115+
Output::
116+
[HH:MM:SS AM] Projects in this build:
117+
* child/tsconfig.json
118+
119+
[HH:MM:SS AM] Project 'child/tsconfig.json' is out of date because buildinfo file 'child/tsconfig.tsbuildinfo' indicates that file 'child/child2.ts' was root file of compilation but not any more.
120+
121+
[HH:MM:SS AM] Building project 'child/tsconfig.json'...
122+
123+
child/child.ts:1:24 - error TS2307: Cannot find module '../child/child2' or its corresponding type declarations.
124+
125+
1 import { child2 } from "../child/child2";
126+
   ~~~~~~~~~~~~~~~~~
127+
128+
======== Resolving module '../child/child2' from '/home/src/workspaces/solution/child/child.ts'. ========
129+
Module resolution kind is not specified, using 'Bundler'.
130+
Resolving in CJS mode with conditions 'require', 'types'.
131+
Loading module as file / folder, candidate module location '/home/src/workspaces/solution/child/child2', target file types: TypeScript, JavaScript, Declaration, JSON.
132+
File '/home/src/workspaces/solution/child/child2.ts' does not exist.
133+
File '/home/src/workspaces/solution/child/child2.tsx' does not exist.
134+
File '/home/src/workspaces/solution/child/child2.d.ts' does not exist.
135+
File '/home/src/workspaces/solution/child/child2.js' does not exist.
136+
File '/home/src/workspaces/solution/child/child2.jsx' does not exist.
137+
Directory '/home/src/workspaces/solution/child/child2' does not exist, skipping all lookups in it.
138+
======== Module name '../child/child2' was not resolved. ========
139+
../../tslibs/TS/Lib/lib.d.ts
140+
Default library for target 'ES5'
141+
child/child.ts
142+
Matched by default include pattern '**/*'
143+
144+
Found 1 error in child/child.ts:1
145+
146+
//// [/home/src/workspaces/solution/child/child.js] *rewrite with same content*
147+
//// [/home/src/workspaces/solution/child/tsconfig.tsbuildinfo] *modified*
148+
{"version":"FakeTSVersion","errors":true,"root":["./child.ts"]}
149+
//// [/home/src/workspaces/solution/child/tsconfig.tsbuildinfo.readable.baseline.txt] *modified*
150+
{
151+
"version": "FakeTSVersion",
152+
"errors": true,
153+
"root": [
154+
{
155+
"files": [
156+
"./child.ts"
157+
],
158+
"original": "./child.ts"
159+
}
160+
],
161+
"size": 63
162+
}
163+
164+
child/tsconfig.json::
165+
SemanticDiagnostics::
166+
*refresh* /home/src/tslibs/TS/Lib/lib.d.ts
167+
*refresh* /home/src/workspaces/solution/child/child.ts
168+
Signatures::

0 commit comments

Comments
 (0)