Skip to content

Commit

Permalink
fix: add missing realpath and initialize files in memory
Browse files Browse the repository at this point in the history
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
  • Loading branch information
piotr-oles committed Aug 7, 2021
1 parent 230b0b5 commit e21827e
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/typescript-reporter/reporter/ControlledTypeScriptSystem.ts
Expand Up @@ -150,11 +150,18 @@ function createControlledTypeScriptSystem(
}

function getReadFileSystem(path: string) {
if (
!isInitialRun &&
(mode === 'readonly' || mode === 'write-tsbuildinfo') &&
isArtifact(path)
) {
if ((mode === 'readonly' || mode === 'write-tsbuildinfo') && isArtifact(path)) {
if (isInitialRun && !memFileSystem.exists(path) && passiveFileSystem.exists(path)) {
// copy file to memory on initial run
const stats = passiveFileSystem.readStats(path);
if (stats?.isFile()) {
const content = passiveFileSystem.readFile(path);
if (content) {
memFileSystem.writeFile(path, content);
memFileSystem.updateTimes(path, stats.atime, stats.mtime);
}
}
}
return memFileSystem;
}

Expand All @@ -175,6 +182,9 @@ function createControlledTypeScriptSystem(
const controlledSystem: ControlledTypeScriptSystem = {
...typescript.sys,
useCaseSensitiveFileNames: caseSensitive,
realpath(path: string): string {
return getReadFileSystem(path).realPath(path);
},
fileExists(path: string): boolean {
const stats = getReadFileSystem(path).readStats(path);

Expand Down

0 comments on commit e21827e

Please sign in to comment.