Skip to content
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

Closed
wants to merge 6 commits into from
Closed

[Jest] Migrate src/data/bucket/fill_bucket.test.ts #486

wants to merge 6 commits into from

Conversation

astridx
Copy link
Contributor

@astridx astridx commented Oct 15, 2021

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-jest
Because we need bable-jest for the external node modules anyway, I replaced jest-ts. If you accept this solution, then I will next handle all tests in which import.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 regarding MAX_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 411
In addition, parameters and types were expected, which I filled with possible values.

@github-actions
Copy link
Contributor

Bundle size report:

Size Change: 0 B
Total Size Before: 194 kB
Total Size After: 194 kB

Output file Before After Change
maplibre-gl.js 185 kB 185 kB 0 B
maplibre-gl.css 9.49 kB 9.49 kB 0 B
ℹ️ View Details No major changes

@HarelM
Copy link
Member

HarelM commented Oct 15, 2021

I'm not sure a full mock for the segment is actually needed.
Can't you spy only on the MAX... thing like it is done today?
the Segment mock seems a bit of an overkill to me - especially when we are talking about java script.
The meta.url seems to be related to the combination of ts-jest and babel-jest.
While don't I favor any of them specifically the following issues seems to be talking about them:
kulshekhar/ts-jest#1174 (comment)
Which leads to the following documentation on the support of esm.
https://kulshekhar.github.io/ts-jest/docs/guides/esm-support/
I'm not sure it solved the previous issue which caused us to use babel-jest in combination with ts-jest, but it might a better solution.
I needed to change a lot of places from __direname to this meta.url when migrating to node 14 so it would be nice to use "regular" code and not something specific to babel and some replacement.
Feel free to experiment with the above suggestion to enable ESM in ts-jest, I'll see if I can find some time later on this week if you don't beat me to it.
Sorry for opening this discussion again...


// 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'))));
Copy link
Member

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'))));

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +1 to +15
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};
};
Copy link
Member

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?

Copy link
Contributor Author

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.

@astridx
Copy link
Contributor Author

astridx commented Oct 16, 2021

I start a new try.

@astridx astridx closed this Oct 16, 2021
@astridx astridx deleted the jest_data_fill_bucket.test_2 branch October 16, 2021 16:51
@birkskyum birkskyum added this to the Transition from Tap to Jest milestone Jan 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants