-
Notifications
You must be signed in to change notification settings - Fork 66
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
chore: Use correct config file to run lint on test files and refactor test code #165
Conversation
for (let i = 0; i < events.length; i++) { | ||
let eventType = events[i].type; | ||
let eventDetails = JSON.parse(events[i].details); | ||
for (const event of events) { |
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.
This not not so safe to do with arrays
Consider using Array.forEach
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.
Hey, could you explain why this isn't a safe operation with arrays? This was recommended by TSLint and I'm not able to find much information on why forEach
is preferred - although according to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of, it has compatibility issues with IE, so I will go ahead and make the change.
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.
I forget the reasons 100%, but I believe in some cases (and some browsers) for..of
returns the length
value as well.
for (let i = 0; i < record.length; i++) { | ||
expect(record.mock.calls[i][0]).toEqual(DOM_EVENT_TYPE); | ||
expect(record.mock.calls[i][1]).toMatchObject( | ||
for (const call of record.mock.calls) { |
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.
See above
Please use forEach
src/test-utils/smoke-test-utils.ts
Outdated
@@ -85,8 +87,8 @@ export const isEachEventIngested = async ( | |||
// Running tests in parallel require pagination logic, as several test cases have the same timestamp | |||
while (true) { | |||
const data = await rumClient.send(command); | |||
for (let i = 0; i < data.Events.length; i++) { | |||
ingestedEvents.add(JSON.parse(data.Events[i]).event_id); | |||
for (const event of data.Events) { |
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.
Same as all other comments related to for of
@@ -12,7 +12,7 @@ const getSession = jest.fn(() => ({ | |||
eventCount: 1 | |||
})); | |||
const getUserId = jest.fn(() => 'b'); | |||
const getAttributes = jest.fn(() => {}); | |||
const getAttributes = jest.fn(() => undefined); |
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.
nit: I think the intent with {}
(here and elsewhere) was to return an empty object.
Clearly it's not being used though... so could even just do
const getAttributes = jest.fn();
or omit getAttributes
.
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.
() => {}
does not return an empty object, it returns undefined
In order to return an empty object one has to do: () => ({})
(note the extra parenthesis)
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.
Yep, apparently {}
leads to undefined
(and unit tests prove the case to be so as well since all were passing).
I will do the following:
- first try out using
() => ({})
to create an empty object as maniator@ suggests, since that was our original intention. - remove unused references.
TODO: before merging, rename commit to be less than 50 characters |
for (let i = 0; i < events.length; i++) { | ||
let eventType = events[i].type; | ||
let eventDetails = JSON.parse(events[i].details); | ||
for (const event of events) { |
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.
TODO: use forEach
for (let i = 0; i < events.length; i++) { | ||
let eventType = events[i].type; | ||
let eventDetails = JSON.parse(events[i].details); | ||
for (const event of events) { |
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.
TODO: use forEach
for (let i = 0; i < events.length; i++) { | ||
let eventType = events[i].type; | ||
let eventDetails = JSON.parse(events[i].details); | ||
for (const event of events) { |
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.
TODO: use forEach
for (let i = 0; i < events.length; i++) { | ||
let eventType = events[i].type; | ||
let eventDetails = JSON.parse(events[i].details); | ||
for (const event of events) { |
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.
TODO: use forEach
for (let i = 0; i < events.length; i++) { | ||
let eventType = events[i].type; | ||
let eventDetails = JSON.parse(events[i].details); | ||
for (const event of events) { |
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.
TODO: use forEach
for (let i = 0; i < record.mock.calls.length; i++) { | ||
expect(record.mock.calls[i][0]).toEqual(DOM_EVENT_TYPE); | ||
expect(record.mock.calls[i][1]).toMatchObject( | ||
for (const call of record.mock.calls) { |
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.
TODO: use forEach
for (let i = 0; i < record.length; i++) { | ||
expect(record.mock.calls[i][0]).toEqual(DOM_EVENT_TYPE); | ||
expect(record.mock.calls[i][1]).toMatchObject( | ||
for (const call of record.mock.calls) { |
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.
TODO: use forEach
src/test-utils/smoke-test-utils.ts
Outdated
for (let i = 0; i < eventIds.length; i++) { | ||
if (!ingestedEvents.has(eventIds[i])) { | ||
throw new Error(`Event ${eventIds[i]} not ingested.`); | ||
for (const eventId of eventIds) { |
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.
TODO: use forEach
Issue
Previously, we did not run
lint
on test files. After the addition of #144 and #149 , we are runninglint
on staged files and the input for--project
wastsconfig.webpack.json
. Even thoughtsconfig.webpack.json
extended fromtsconfig.json
which defined project as all the files undersrc/
,tsconfig.webpack.json
overwrote the project to only include dependencies involved withindex-browser.ts
.As a result, any changes/addition of test files would fail in commit sessions, as it was recognized as "not included in the project".
Solution
There were two ways to go about this issue: (1) do not include test files (non-source code) under pre-commit (2) use
tsconfig.json
as input for--project
and refactor our test cases.Despite being test files, applying lint to test cases in the future and doing the refactoring will increase code quality - thus went with option (2).
This PR
This PR makes two major changes:
tsconfig.webpack.json
, usetsconfig.json
fornpm run lint
Notes
Since TSLint is deprecated as of 2018, we should migrate to ESLint. There will be a subsequent PR to migrate from TSLint to ESLint.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.