Skip to content

Commit c37a58c

Browse files
committed
fix: add missing realpath and initialize files in memory
In the situation, when there were already some files built in the real fs, controlled typescript system returned true for fileExists call on initial run and false on subsequent calls causing assertion in TypeScript to fail. ✅ Closes: #630
1 parent 7afc037 commit c37a58c

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/typescript-reporter/reporter/ControlledTypeScriptSystem.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,18 @@ function createControlledTypeScriptSystem(
150150
}
151151

152152
function getReadFileSystem(path: string) {
153-
if (
154-
!isInitialRun &&
155-
(mode === 'readonly' || mode === 'write-tsbuildinfo') &&
156-
isArtifact(path)
157-
) {
153+
if ((mode === 'readonly' || mode === 'write-tsbuildinfo') && isArtifact(path)) {
154+
if (isInitialRun && !memFileSystem.exists(path) && passiveFileSystem.exists(path)) {
155+
// copy file to memory on initial run
156+
const stats = passiveFileSystem.readStats(path);
157+
if (stats?.isFile()) {
158+
const content = passiveFileSystem.readFile(path);
159+
if (content) {
160+
memFileSystem.writeFile(path, content);
161+
memFileSystem.updateTimes(path, stats.atime, stats.mtime);
162+
}
163+
}
164+
}
158165
return memFileSystem;
159166
}
160167

@@ -175,6 +182,9 @@ function createControlledTypeScriptSystem(
175182
const controlledSystem: ControlledTypeScriptSystem = {
176183
...typescript.sys,
177184
useCaseSensitiveFileNames: caseSensitive,
185+
realpath(path: string): string {
186+
return getReadFileSystem(path).realPath(path);
187+
},
178188
fileExists(path: string): boolean {
179189
const stats = getReadFileSystem(path).readStats(path);
180190

test/e2e/TypeScriptGenerateTrace.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ describe('TypeScript Generate Trace', () => {
7373

7474
// update sandbox to generate trace
7575
await sandbox.patch(
76-
'tsconfig.json',
76+
'tsconfig.base.json',
7777
' "rootDir": "./packages"',
7878
[' "rootDir": "./packages",', ' "generateTrace": "./traces"'].join('\n')
7979
);

0 commit comments

Comments
 (0)