Skip to content

Commit 3ca9af2

Browse files
committed
fix: doc telemetry unit tests fail in windows platform issues
1 parent fe76405 commit 3ca9af2

File tree

3 files changed

+32
-23
lines changed

3 files changed

+32
-23
lines changed

packages/core/src/test/amazonqDoc/controller.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { waitUntil } from '../../shared'
2323
import { FollowUpTypes } from '../../amazonq/commons/types'
2424
import { FileSystem } from '../../shared/fs/fs'
2525
import { ReadmeBuilder } from './mockContent'
26+
import * as path from 'path'
2627

2728
describe('Controller - Doc Generation', () => {
2829
const tabID = '123'
@@ -39,11 +40,11 @@ describe('Controller - Doc Generation', () => {
3940

4041
const getFilePaths = (controllerSetup: ControllerSetup): NewFileInfo[] => [
4142
{
42-
zipFilePath: 'README.md',
43-
relativePath: 'README.md',
43+
zipFilePath: path.normalize('README.md'),
44+
relativePath: path.normalize('README.md'),
4445
fileContent: generatedReadme,
4546
rejected: false,
46-
virtualMemoryUri: generateVirtualMemoryUri(uploadID, 'README.md', docScheme),
47+
virtualMemoryUri: generateVirtualMemoryUri(uploadID, path.normalize('README.md'), docScheme),
4748
workspaceFolder: controllerSetup.workspaceFolder,
4849
changeApplied: false,
4950
},
@@ -138,7 +139,7 @@ describe('Controller - Doc Generation', () => {
138139
codewhispererChat: 'connected',
139140
amazonQ: 'connected',
140141
})
141-
sinon.stub(FileSystem.prototype, 'exists').resolves(true)
142+
sinon.stub(FileSystem.prototype, 'exists').callsFake(async () => true)
142143
getSessionStub = sinon.stub(controllerSetup.sessionStorage, 'getSession').resolves(session)
143144
modifiedReadme = ReadmeBuilder.createReadmeWithRepoStructure()
144145
sinon
@@ -228,6 +229,7 @@ describe('Controller - Doc Generation', () => {
228229
})
229230
})
230231
it('should emit generation telemetry for README update', async () => {
232+
await updateFilePaths(session, modifiedReadme, uploadID, docScheme, controllerSetup.workspaceFolder)
231233
await performAction('update', getSessionStub)
232234

233235
const expectedEvent = createExpectedEvent({
@@ -269,6 +271,7 @@ describe('Controller - Doc Generation', () => {
269271
})
270272

271273
it('should emit acceptance telemetry for README update', async () => {
274+
await updateFilePaths(session, modifiedReadme, uploadID, docScheme, controllerSetup.workspaceFolder)
272275
await performAction('update', getSessionStub)
273276
await new Promise((resolve) => setTimeout(resolve, 100))
274277

@@ -289,6 +292,7 @@ describe('Controller - Doc Generation', () => {
289292
})
290293

291294
it('should emit generation telemetry for README edit', async () => {
295+
await updateFilePaths(session, modifiedReadme, uploadID, docScheme, controllerSetup.workspaceFolder)
292296
await performAction('edit', getSessionStub, 'add repository structure section')
293297

294298
const expectedEvent = createExpectedEvent({
@@ -305,6 +309,7 @@ describe('Controller - Doc Generation', () => {
305309
})
306310
})
307311
it('should emit acceptance telemetry for README edit', async () => {
312+
await updateFilePaths(session, modifiedReadme, uploadID, docScheme, controllerSetup.workspaceFolder)
308313
await performAction('edit', getSessionStub, 'add repository structure section')
309314
await new Promise((resolve) => setTimeout(resolve, 100))
310315

packages/core/src/test/amazonqDoc/mockContent.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,40 +43,44 @@ export class ReadmeBuilder {
4343
private sections: string[] = []
4444

4545
addSection(section: string): this {
46-
this.sections.push(section)
46+
this.sections.push(section.replace(/\r\n/g, '\n'))
4747
return this
4848
}
4949

5050
build(): string {
51-
return this.sections.join('\n\n')
51+
return this.sections.join('\n\n').replace(/\r\n/g, '\n')
5252
}
5353

5454
static createBaseReadme(): string {
5555
return new ReadmeBuilder()
56-
.addSection(ReadmeSections.HEADER)
57-
.addSection(ReadmeSections.GETTING_STARTED)
58-
.addSection(ReadmeSections.FEATURES)
59-
.addSection(ReadmeSections.LICENSE)
56+
.addSection(ReadmeBuilder.normalizeSection(ReadmeSections.HEADER))
57+
.addSection(ReadmeBuilder.normalizeSection(ReadmeSections.GETTING_STARTED))
58+
.addSection(ReadmeBuilder.normalizeSection(ReadmeSections.FEATURES))
59+
.addSection(ReadmeBuilder.normalizeSection(ReadmeSections.LICENSE))
6060
.build()
6161
}
6262

6363
static createReadmeWithRepoStructure(): string {
6464
return new ReadmeBuilder()
65-
.addSection(ReadmeSections.HEADER)
66-
.addSection(ReadmeSections.REPO_STRUCTURE)
67-
.addSection(ReadmeSections.GETTING_STARTED)
68-
.addSection(ReadmeSections.FEATURES)
69-
.addSection(ReadmeSections.LICENSE)
65+
.addSection(ReadmeBuilder.normalizeSection(ReadmeSections.HEADER))
66+
.addSection(ReadmeBuilder.normalizeSection(ReadmeSections.REPO_STRUCTURE))
67+
.addSection(ReadmeBuilder.normalizeSection(ReadmeSections.GETTING_STARTED))
68+
.addSection(ReadmeBuilder.normalizeSection(ReadmeSections.FEATURES))
69+
.addSection(ReadmeBuilder.normalizeSection(ReadmeSections.LICENSE))
7070
.build()
7171
}
7272

7373
static createReadmeWithDataFlow(): string {
7474
return new ReadmeBuilder()
75-
.addSection(ReadmeSections.HEADER)
76-
.addSection(ReadmeSections.GETTING_STARTED)
77-
.addSection(ReadmeSections.FEATURES)
78-
.addSection(ReadmeSections.DATA_FLOW)
79-
.addSection(ReadmeSections.LICENSE)
75+
.addSection(ReadmeBuilder.normalizeSection(ReadmeSections.HEADER))
76+
.addSection(ReadmeBuilder.normalizeSection(ReadmeSections.GETTING_STARTED))
77+
.addSection(ReadmeBuilder.normalizeSection(ReadmeSections.FEATURES))
78+
.addSection(ReadmeBuilder.normalizeSection(ReadmeSections.DATA_FLOW))
79+
.addSection(ReadmeBuilder.normalizeSection(ReadmeSections.LICENSE))
8080
.build()
8181
}
82+
83+
private static normalizeSection(section: string): string {
84+
return section.replace(/\r\n/g, '\n')
85+
}
8286
}

packages/core/src/test/amazonqDoc/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,11 @@ export async function updateFilePaths(
214214
) {
215215
const updatedFilePaths: NewFileInfo[] = [
216216
{
217-
zipFilePath: 'README.md',
218-
relativePath: 'README.md',
217+
zipFilePath: path.normalize('README.md'),
218+
relativePath: path.normalize('README.md'),
219219
fileContent: content,
220220
rejected: false,
221-
virtualMemoryUri: generateVirtualMemoryUri(uploadId, 'README.md', docScheme),
221+
virtualMemoryUri: generateVirtualMemoryUri(uploadId, path.normalize('README.md'), docScheme),
222222
workspaceFolder: workspaceFolder,
223223
changeApplied: false,
224224
},

0 commit comments

Comments
 (0)