-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Add survey event #26455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add survey event #26455
Changes from all commits
1904650
87ba7fc
fccf6a2
50eaaf3
e28c240
17780b3
e94e03f
002efcf
058b5fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2846,7 +2846,7 @@ namespace ts.projectSystem { | |
const session = createSession(host, { | ||
canUseEvents: true, | ||
eventHandler: e => { | ||
if (e.eventName === server.ConfigFileDiagEvent || e.eventName === server.ProjectsUpdatedInBackgroundEvent || e.eventName === server.ProjectInfoTelemetryEvent || e.eventName === server.OpenFileInfoTelemetryEvent || e.eventName === server.LargeFileReferencedEvent) { | ||
if (e.eventName === server.ConfigFileDiagEvent || e.eventName === server.ProjectsUpdatedInBackgroundEvent || e.eventName === server.ProjectInfoTelemetryEvent || e.eventName === server.OpenFileInfoTelemetryEvent || e.eventName === server.LargeFileReferencedEvent || e.eventName === server.SurveyReady) { | ||
return; | ||
} | ||
assert.equal(e.eventName, server.ProjectLanguageServiceStateEvent); | ||
|
@@ -3496,6 +3496,121 @@ namespace ts.projectSystem { | |
} | ||
}); | ||
|
||
function createSessionWithEventHandler(host: TestServerHost) { | ||
const surveyEvents: server.SurveyReady[] = []; | ||
const session = createSession(host, { | ||
eventHandler: e => { | ||
if (e.eventName === server.SurveyReady) { | ||
surveyEvents.push(e); | ||
} | ||
} | ||
}); | ||
|
||
return { session, verifySurveyReadyEvent }; | ||
|
||
function verifySurveyReadyEvent(numberOfEvents: number) { | ||
assert.equal(surveyEvents.length, numberOfEvents); | ||
const expectedEvents = numberOfEvents === 0 ? [] : [{ | ||
eventName: server.SurveyReady, | ||
data: { surveyId: "checkJs" } | ||
}]; | ||
assert.deepEqual(surveyEvents, expectedEvents); | ||
} | ||
} | ||
|
||
it("doesn't log an event when checkJs isn't set", () => { | ||
const projectRoot = "/user/username/projects/project"; | ||
const file: File = { | ||
path: `${projectRoot}/src/file.ts`, | ||
content: "export var y = 10;" | ||
}; | ||
const tsconfig: File = { | ||
path: `${projectRoot}/tsconfig.json`, | ||
content: JSON.stringify({ compilerOptions: { } }), | ||
}; | ||
const host = createServerHost([file, tsconfig]); | ||
const { session, verifySurveyReadyEvent } = createSessionWithEventHandler(host); | ||
const service = session.getProjectService(); | ||
openFilesForSession([file], session); | ||
checkNumberOfProjects(service, { configuredProjects: 1 }); | ||
const project = service.configuredProjects.get(tsconfig.path)!; | ||
checkProjectActualFiles(project, [file.path, tsconfig.path]); | ||
|
||
verifySurveyReadyEvent(0); | ||
}); | ||
|
||
it("logs an event when checkJs is set", () => { | ||
const projectRoot = "/user/username/projects/project"; | ||
const file: File = { | ||
path: `${projectRoot}/src/file.ts`, | ||
content: "export var y = 10;" | ||
}; | ||
const tsconfig: File = { | ||
path: `${projectRoot}/tsconfig.json`, | ||
content: JSON.stringify({ compilerOptions: { checkJs: true } }), | ||
}; | ||
const host = createServerHost([file, tsconfig]); | ||
const { session, verifySurveyReadyEvent } = createSessionWithEventHandler(host); | ||
openFilesForSession([file], session); | ||
|
||
verifySurveyReadyEvent(1); | ||
}); | ||
|
||
it("logs an event when checkJs is set, only the first time", () => { | ||
const projectRoot = "/user/username/projects/project"; | ||
const file: File = { | ||
path: `${projectRoot}/src/file.ts`, | ||
content: "export var y = 10;" | ||
}; | ||
const rando: File = { | ||
path: `/rando/calrissian.ts`, | ||
content: "export function f() { }" | ||
}; | ||
const tsconfig: File = { | ||
path: `${projectRoot}/tsconfig.json`, | ||
content: JSON.stringify({ compilerOptions: { checkJs: true } }), | ||
}; | ||
const host = createServerHost([file, tsconfig]); | ||
const { session, verifySurveyReadyEvent } = createSessionWithEventHandler(host); | ||
openFilesForSession([file], session); | ||
|
||
verifySurveyReadyEvent(1); | ||
|
||
closeFilesForSession([file], session); | ||
openFilesForSession([rando], session); | ||
openFilesForSession([file], session); | ||
|
||
verifySurveyReadyEvent(1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And verifySurveyReadyEvent(0) here ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, I only call createSessionWithEventHandler once, so I expect verifySurveyReadyEvent(1), verifySurveyReadyEvent(1) in the case that re-opening the project doesn't fire the survey event twice. It would be 1, then 2, if re-opening the project does fire the survey event twice. So I think this line of code is already correct. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's because createSessionWithEventHandler creates an array to push events into, so the length of the array never goes down as long as you are working with a |
||
}); | ||
|
||
it("logs an event when checkJs is set after closing and reopening", () => { | ||
const projectRoot = "/user/username/projects/project"; | ||
const file: File = { | ||
path: `${projectRoot}/src/file.ts`, | ||
content: "export var y = 10;" | ||
}; | ||
const rando: File = { | ||
path: `/rando/calrissian.ts`, | ||
content: "export function f() { }" | ||
}; | ||
const tsconfig: File = { | ||
path: `${projectRoot}/tsconfig.json`, | ||
content: JSON.stringify({ }), | ||
}; | ||
const host = createServerHost([file, tsconfig]); | ||
const { session, verifySurveyReadyEvent } = createSessionWithEventHandler(host); | ||
openFilesForSession([file], session); | ||
|
||
verifySurveyReadyEvent(0); | ||
|
||
closeFilesForSession([file], session); | ||
openFilesForSession([rando], session); | ||
host.writeFile(tsconfig.path, JSON.stringify({ compilerOptions: { checkJs: true } })); | ||
openFilesForSession([file], session); | ||
|
||
verifySurveyReadyEvent(1); | ||
}); | ||
|
||
describe("CompileOnSaveAffectedFileListRequest with and without projectFileName in request", () => { | ||
const projectRoot = "/user/username/projects/myproject"; | ||
const core: File = { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You want to check verifySurveyReadyEvent(1); here