Skip to content

Commit ccf1883

Browse files
committed
refactor: add more helper functions in tests to avoid duplication
1 parent dcfd003 commit ccf1883

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

packages/core/src/testInteg/shared/utilities/workspaceUtils.test.ts

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,7 @@ describe('workspaceUtils', () => {
257257
await writeFile(['src', 'folder3', 'negate_test1'], fileContent)
258258
await writeFile(['src', 'folder3', 'negate_test6'], fileContent)
259259

260-
const result = (await collectFiles([workspaceFolder.uri.fsPath], [workspaceFolder]))
261-
// for some reason, uri created inline differ in subfields, so skipping them from assertion
262-
.map(({ fileUri, zipFilePath, ...r }) => ({ ...r }))
263-
264-
result.sort((l, r) => l.relativeFilePath.localeCompare(r.relativeFilePath))
260+
const result = processIndexResults(await collectFiles([workspaceFolder.uri.fsPath], [workspaceFolder]))
265261

266262
// non-posix filePath check here is important.
267263
assert.deepStrictEqual(
@@ -469,12 +465,6 @@ describe('workspaceUtils', () => {
469465
return toFile(fileContent, path.join(workspaceFolder.uri.fsPath, ...pathParts))
470466
}
471467

472-
// for some reason, uri created inline differ in subfields, so we skip them for assertion
473-
const processResults = (results: Omit<CollectFilesResultItem, 'fileContent'>[]) =>
474-
results
475-
.map(({ fileUri, ...r }) => ({ ...r }))
476-
.sort((l, r) => l.relativeFilePath.localeCompare(r.relativeFilePath))
477-
478468
beforeEach(async function () {
479469
workspaceFolder = await createTestWorkspaceFolder()
480470
sandbox.stub(vscode.workspace, 'workspaceFolders').value([workspaceFolder])
@@ -516,7 +506,7 @@ describe('workspaceUtils', () => {
516506
await writeFile(['src', 'folder3', 'negate_test1'], fileContent)
517507
await writeFile(['src', 'folder3', 'negate_test6'], fileContent)
518508

519-
const result = processResults(
509+
const result = processIndexResults(
520510
await collectFilesForIndex([workspaceFolder.uri.fsPath], [workspaceFolder], true)
521511
)
522512

@@ -527,13 +517,11 @@ describe('workspaceUtils', () => {
527517
workspaceFolder,
528518
relativeFilePath: path.join('src', 'folder2', 'a.js'),
529519
fileSizeBytes: 12,
530-
zipFilePath: path.join('src', 'folder2', 'a.js'),
531520
},
532521
{
533522
workspaceFolder,
534523
relativeFilePath: path.join('src', 'folder2', 'b.cs'),
535524
fileSizeBytes: 12,
536-
zipFilePath: path.join('src', 'folder2', 'b.cs'),
537525
},
538526
] satisfies typeof result,
539527
result
@@ -549,7 +537,7 @@ describe('workspaceUtils', () => {
549537
await writeFile([`a.js`], fileContent)
550538
await writeFile([`b.java`], fileContent)
551539

552-
const result = processResults(
540+
const result = processIndexResults(
553541
await collectFilesForIndex([workspaceFolder.uri.fsPath], [workspaceFolder], true)
554542
)
555543

@@ -560,13 +548,11 @@ describe('workspaceUtils', () => {
560548
workspaceFolder,
561549
relativeFilePath: 'a.js',
562550
fileSizeBytes: 14,
563-
zipFilePath: 'a.js',
564551
},
565552
{
566553
workspaceFolder,
567554
relativeFilePath: 'b.java',
568555
fileSizeBytes: 14,
569-
zipFilePath: 'b.java',
570556
},
571557
] satisfies typeof result,
572558
result
@@ -576,13 +562,13 @@ describe('workspaceUtils', () => {
576562
it('returns top level files when max size is reached', async function () {
577563
const fileContent = 'this is a file'
578564

579-
await writeFile(['path', 'to', 'file', 'a2.js'], fileContent)
580-
await writeFile(['path', 'to', 'file', `b2.java`], fileContent)
565+
await writeFile(['path', 'to', 'file', 'bot.js'], fileContent)
566+
await writeFile(['path', 'to', 'file', `bot.java`], fileContent)
581567

582-
await writeFile([`a.js`], fileContent)
583-
await writeFile([`b.java`], fileContent)
568+
await writeFile([`top.js`], fileContent)
569+
await writeFile([`top.java`], fileContent)
584570

585-
const result = processResults(
571+
const result = processIndexResults(
586572
await collectFilesForIndex([workspaceFolder.uri.fsPath], [workspaceFolder], true)
587573
)
588574

@@ -591,15 +577,13 @@ describe('workspaceUtils', () => {
591577
[
592578
{
593579
workspaceFolder,
594-
relativeFilePath: 'a.js',
580+
relativeFilePath: 'top.js',
595581
fileSizeBytes: 14,
596-
zipFilePath: 'a.js',
597582
},
598583
{
599584
workspaceFolder,
600-
relativeFilePath: 'b.java',
585+
relativeFilePath: 'top.java',
601586
fileSizeBytes: 14,
602-
zipFilePath: 'b.java',
603587
},
604588
] satisfies typeof result,
605589
result
@@ -618,3 +602,10 @@ describe('workspaceUtils', () => {
618602
})
619603
})
620604
})
605+
606+
// for some reason, uri created inline differ in subfields, so skipping them from assertion
607+
function processIndexResults(results: Omit<CollectFilesResultItem, 'fileContent'>[] | CollectFilesResultItem[]) {
608+
return results
609+
.map(({ zipFilePath, fileUri, ...r }) => ({ ...r }))
610+
.sort((l, r) => l.relativeFilePath.localeCompare(r.relativeFilePath))
611+
}

0 commit comments

Comments
 (0)