Skip to content

Commit

Permalink
chore(snc): remove in-memory-fs.spec snc violations (#4401)
Browse files Browse the repository at this point in the history
this commit removes the `strictNullChecks` violations found in
`in-memory-fs.spec.ts`. there are two types of changes found within this
file:
1. `fsItem`, a helper function in the suite, has been updated to set
   it's default values to `undefined` to adhere to `Partial<FsItem>`,
   fixing assignability issues with setting each field to null
2. retrieval of entries from the `items` map use optional chaining. this
   was deemed safe as we are not asserting against `undefined` in any of
   the `get` calls in said tests
  • Loading branch information
rwaskiewicz authored May 22, 2023
1 parent 21199d6 commit 0673f72
Showing 1 changed file with 35 additions and 35 deletions.
70 changes: 35 additions & 35 deletions src/compiler/sys/tests/in-memory-fs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ describe(`in-memory-fs, getCommitInstructions`, () => {
});

function fsItem(item: any): FsItem {
const defaultItem: FsItem = {
exists: null,
fileText: null,
size: null,
mtimeMs: null,
isDirectory: null,
isFile: null,
queueCopyFileToDest: null,
queueDeleteFromDisk: null,
queueWriteToDisk: null,
useCache: null,
const defaultItem: Partial<FsItem> = {
exists: undefined,
fileText: undefined,
size: undefined,
mtimeMs: undefined,
isDirectory: undefined,
isFile: undefined,
queueCopyFileToDest: undefined,
queueDeleteFromDisk: undefined,
queueWriteToDisk: undefined,
useCache: undefined,
};
return Object.assign(defaultItem, item);
}
Expand All @@ -40,9 +40,9 @@ describe(`in-memory-fs, getCommitInstructions`, () => {
expect(i.filesToWrite).toEqual([]);
expect(i.dirsToDelete).toEqual([`C:/dir1/dir2/dir3`, `C:/dir1/dir2`, `C:/dir1`]);
expect(i.dirsToEnsure).toEqual([]);
expect(items.get(`C:/dir1`).queueDeleteFromDisk).toBe(false);
expect(items.get(`C:/dir1/dir2`).queueDeleteFromDisk).toBe(false);
expect(items.get(`C:/dir1/dir2/dir3`).queueDeleteFromDisk).toBe(false);
expect(items.get(`C:/dir1`)?.queueDeleteFromDisk).toBe(false);
expect(items.get(`C:/dir1/dir2`)?.queueDeleteFromDisk).toBe(false);
expect(items.get(`C:/dir1/dir2/dir3`)?.queueDeleteFromDisk).toBe(false);
});

it(`dirsToDelete, sort longest to shortest, unix`, () => {
Expand All @@ -59,9 +59,9 @@ describe(`in-memory-fs, getCommitInstructions`, () => {
expect(i.filesToWrite).toEqual([]);
expect(i.dirsToDelete).toEqual([`/dir1/dir2/dir3`, `/dir1/dir2`, `/dir1`]);
expect(i.dirsToEnsure).toEqual([]);
expect(items.get(`/dir1`).queueDeleteFromDisk).toBe(false);
expect(items.get(`/dir1/dir2`).queueDeleteFromDisk).toBe(false);
expect(items.get(`/dir1/dir2/dir3`).queueDeleteFromDisk).toBe(false);
expect(items.get(`/dir1`)?.queueDeleteFromDisk).toBe(false);
expect(items.get(`/dir1/dir2`)?.queueDeleteFromDisk).toBe(false);
expect(items.get(`/dir1/dir2/dir3`)?.queueDeleteFromDisk).toBe(false);
});

it(`ensure dirs, sort shortest to longest, windows`, () => {
Expand All @@ -76,9 +76,9 @@ describe(`in-memory-fs, getCommitInstructions`, () => {
expect(i.filesToWrite).toEqual([`C:/dir1/dir2/dir3/file2.js`, `C:/dir1/dir2/file1.js`]);
expect(i.dirsToDelete).toEqual([]);
expect(i.dirsToEnsure).toEqual([`C:/dir1`, `C:/dir1/dir2`, `C:/dir1/dir2/dir3`]);
expect(items.get(`C:/dir1`).queueDeleteFromDisk).toBe(false);
expect(items.get(`C:/dir1/dir2/file1.js`).queueDeleteFromDisk).toBe(false);
expect(items.get(`C:/dir1/dir2/dir3/file2.js`).queueDeleteFromDisk).toBe(false);
expect(items.get(`C:/dir1`)?.queueDeleteFromDisk).toBe(false);
expect(items.get(`C:/dir1/dir2/file1.js`)?.queueDeleteFromDisk).toBe(false);
expect(items.get(`C:/dir1/dir2/dir3/file2.js`)?.queueDeleteFromDisk).toBe(false);
});

it(`ensure dirs, sort shortest to longest`, () => {
Expand All @@ -91,9 +91,9 @@ describe(`in-memory-fs, getCommitInstructions`, () => {
expect(i.filesToWrite).toEqual([`/dir1/dir2/dir3/file2.js`, `/dir1/dir2/file1.js`]);
expect(i.dirsToDelete).toEqual([]);
expect(i.dirsToEnsure).toEqual([`/dir1`, `/dir1/dir2`, `/dir1/dir2/dir3`]);
expect(items.get(`/dir1`).queueDeleteFromDisk).toBe(false);
expect(items.get(`/dir1/dir2/file1.js`).queueDeleteFromDisk).toBe(false);
expect(items.get(`/dir1/dir2/dir3/file2.js`).queueDeleteFromDisk).toBe(false);
expect(items.get(`/dir1`)?.queueDeleteFromDisk).toBe(false);
expect(items.get(`/dir1/dir2/file1.js`)?.queueDeleteFromDisk).toBe(false);
expect(items.get(`/dir1/dir2/dir3/file2.js`)?.queueDeleteFromDisk).toBe(false);
});

it(`do not delete a files/directory if we also want to ensure it`, () => {
Expand All @@ -104,7 +104,7 @@ describe(`in-memory-fs, getCommitInstructions`, () => {
expect(i.filesToWrite).toEqual([`/dir1/file1.js`]);
expect(i.dirsToDelete).toEqual([]);
expect(i.dirsToEnsure).toEqual([`/dir1`]);
expect(items.get(`/dir1/file1.js`).queueWriteToDisk).toBe(false);
expect(items.get(`/dir1/file1.js`)?.queueWriteToDisk).toBe(false);
});

it(`queueDeleteFromDisk`, () => {
Expand All @@ -117,10 +117,10 @@ describe(`in-memory-fs, getCommitInstructions`, () => {
expect(i.filesToWrite).toEqual([]);
expect(i.dirsToDelete).toEqual([`/dir1`]);
expect(i.dirsToEnsure).toEqual([]);
expect(items.get(`/dir1`).queueDeleteFromDisk).toBe(false);
expect(items.get(`/dir1/file1.js`).queueDeleteFromDisk).toBe(false);
expect(items.get(`/dir2/file2.js`).queueDeleteFromDisk).toBe(false);
expect(items.get(`/dir1`).queueDeleteFromDisk).toBe(false);
expect(items.get(`/dir1`)?.queueDeleteFromDisk).toBe(false);
expect(items.get(`/dir1/file1.js`)?.queueDeleteFromDisk).toBe(false);
expect(items.get(`/dir2/file2.js`)?.queueDeleteFromDisk).toBe(false);
expect(items.get(`/dir1`)?.queueDeleteFromDisk).toBe(false);
});

it(`write directory to disk`, () => {
Expand All @@ -130,7 +130,7 @@ describe(`in-memory-fs, getCommitInstructions`, () => {
expect(i.filesToWrite).toEqual([]);
expect(i.dirsToDelete).toEqual([]);
expect(i.dirsToEnsure).toEqual([`/dir1`]);
expect(items.get(`/dir1`).queueWriteToDisk).toBe(false);
expect(items.get(`/dir1`)?.queueWriteToDisk).toBe(false);
});

it(`write file queued even if it's also queueDeleteFromDisk`, () => {
Expand All @@ -140,7 +140,7 @@ describe(`in-memory-fs, getCommitInstructions`, () => {
expect(i.filesToWrite).toEqual([`/dir1/file1.js`]);
expect(i.dirsToDelete).toEqual([]);
expect(i.dirsToEnsure).toEqual([`/dir1`]);
expect(items.get(`/dir1/file1.js`).queueWriteToDisk).toBe(false);
expect(items.get(`/dir1/file1.js`)?.queueWriteToDisk).toBe(false);
});

it(`write file queued`, () => {
Expand All @@ -152,9 +152,9 @@ describe(`in-memory-fs, getCommitInstructions`, () => {
expect(i.filesToWrite).toEqual([`/dir1/file1.js`, `/dir1/file2.js`, `/dir2/file3.js`]);
expect(i.dirsToDelete).toEqual([]);
expect(i.dirsToEnsure).toEqual([`/dir1`, `/dir2`]);
expect(items.get(`/dir1/file1.js`).queueWriteToDisk).toBe(false);
expect(items.get(`/dir1/file2.js`).queueWriteToDisk).toBe(false);
expect(items.get(`/dir2/file3.js`).queueWriteToDisk).toBe(false);
expect(items.get(`/dir1/file1.js`)?.queueWriteToDisk).toBe(false);
expect(items.get(`/dir1/file2.js`)?.queueWriteToDisk).toBe(false);
expect(items.get(`/dir2/file3.js`)?.queueWriteToDisk).toBe(false);
});

it(`do nothing`, () => {
Expand Down Expand Up @@ -423,7 +423,7 @@ describe(`in-memory-fs`, () => {
await fs.commit();
fs.clearCache();

let content: string;
let content: string = '';
try {
content = await fs.readFile(`/dir/file.js`);
} catch (e) {
Expand Down Expand Up @@ -465,7 +465,7 @@ describe(`in-memory-fs`, () => {
await fs.commit();
fs.clearCache();

let content: string;
let content: string = '';
try {
content = fs.readFileSync(`/dir/file.js`);
} catch (e) {
Expand Down

0 comments on commit 0673f72

Please sign in to comment.