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
[Jest] Migrate src/data/bucket/fill_bucket.test.ts
#486
Conversation
Bundle size report: Size Change: 0 B
ℹ️ View DetailsNo major changes |
I'm not sure a full mock for the segment is actually needed. |
|
||
// Load a fill feature from fixture tile. | ||
const vt = new VectorTile(new Protobuf(fs.readFileSync(path.join(__dirname, '/../../fixtures/mbsv5-6-18-23.vector.pbf')))); | ||
const vt = new VectorTile(new Protobuf(fs.readFileSync(path.join(maplibreRootDirname, '/test/fixtures/mbsv5-6-18-23.vector.pbf')))); |
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 came across the same problem in another place. Rather than changing jest I would recommend to use this:
const vt = new VectorTile(new Protobuf(fs.readFileSync(path.resolve(__dirname, '../../../test/fixtures/mbsv5-6-18-23.vector.pbf'))));
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.
import {warnOnce} from '../../util/util'; | ||
|
||
import {register} from '../../util/web_worker_transfer'; | ||
|
||
import type VertexArrayObject from '../../render/vertex_array_object'; | ||
import type {StructArray} from '../../util/struct_array'; | ||
|
||
export type Segment = { | ||
sortKey?: number; | ||
vertexOffset: number; | ||
primitiveOffset: number; | ||
vertexLength: number; | ||
primitiveLength: number; | ||
vaos: {[_: string]: VertexArrayObject}; | ||
}; |
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.
Where is this code from?
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 copied the original file src/data/segment.ts
and only changed the relevant part.
I start a new try. |
This test was quite complicated for me and I am interested in your feedback.
Commit: 1-3
The first 3 commits are straightforward.
Commit:
import.meta.url
If I am right Jest does not know
import.meta.url
. I found a workaround in stackoverflow. Please see: https://stackoverflow.com/questions/64961387/how-to-use-import-meta-when-testing-with-jestBecause we need
bable-jest
for the external node modules anyway, I replacedjest-ts
. If you accept this solution, then I will next handle all tests in whichimport.meta.url
is used in the same way. (Edit: I just noticed that the package.lock.json landed one commit too late.)Commit: add mock for segement | tests are know fine
I created a manuell mock for
segment.ts
. This mock is used in all tests in this file. In some tests a warning is displayed regardingMAX_VERTEX_ARRAY_LENGTH
. That is why I catch the warnings from the console.After creating the mock für
segement
,npm run test-jest
was fine. But my IDE shows warnings.Commit: add expectations and fix typescript warnings of my ide
There were no expectations in the first part of the tests. It was probably only to test that no error occurs. I have extended expectations regarding
bucket.layoutVertexArray.length
. In the last case (/test/fixtures/mbsv5-6-18-23.vector.pbf) I trusted the test result. I did not count the 411In addition, parameters and types were expected, which I filled with possible values.