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
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion babel.config.cjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
const { resolve } = require("path");

module.exports = (api) => {
api.cache(true);

return {
presets: [
["@babel/preset-env", { targets: { node: "current" } }]
[
"@babel/preset-env", { targets: { node: "current" } }],
"@babel/preset-typescript",
],
plugins: [
[
"search-and-replace",
{
rules: [
{
search: "import_meta_url",
replace: resolve(__dirname),
},
],
},
],
],
};
};
3 changes: 1 addition & 2 deletions jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ module.exports = {
"**/?(*.)+(spec|test).+(ts|tsx|js)"
],
"transform": {
"^.+\\.(ts|tsx)$": "ts-jest",
"^.+\\.(js)$": "babel-jest",
"^.+\\.(js|ts)$": "babel-jest",
"^.+\\.(glsl)$": "jest-raw-loader",
},
testEnvironment: "jsdom",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
},
"devDependencies": {
"@babel/core": "^7.15.4",
"@babel/preset-typescript": "^7.15.0",
"@mapbox/gazetteer": "^5.1.0",
"@mapbox/mapbox-gl-rtl-text": "^0.2.1",
"@mapbox/mvt-fixtures": "^3.6.0",
Expand Down Expand Up @@ -92,6 +93,7 @@
"babel-eslint": "^10.0.1",
"babel-jest": "^27.2.5",
"babelify": "^10.0.0",
"babel-plugin-search-and-replace": "^1.1.0",
"benchmark": "^2.1.4",
"browserify": "^17.0.0",
"canvas": "^2.6.1",
Expand Down Expand Up @@ -161,7 +163,6 @@
"tape": "^5.3.1",
"tape-filter": "^1.0.4",
"testem": "^3.5.0",
"ts-jest": "^27.0.5",
"ts-node": "^10.2.1",
"typescript": "^4.4.2"
},
Expand Down
8 changes: 4 additions & 4 deletions src/data/bucket/fill_bucket.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@

import fs from 'fs';
import path, {dirname} from 'path';
import path from 'path';
import Protobuf from 'pbf';
import {VectorTile} from '@mapbox/vector-tile';
import Point from '../../util/point';
import segment from '../../data/segment';
import FillBucket from './fill_bucket';
import FillStyleLayer from '../../style/style_layer/fill_style_layer';
import {fileURLToPath} from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));

const maplibreRootDirname = 'import_meta_url'; // replaced in babel.config.cjs

// 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.

const feature = vt.layers.water.feature(0);

function createPolygon(numPoints) {
Expand Down