Export only the d3 functions we use in tests

(re: #4379)

This trims a bit more off the iD bundle size
This commit is contained in:
Bryan Housel
2020-02-22 15:07:09 -05:00
parent fafdb76835
commit 4d0ef1bafc
6 changed files with 66 additions and 57 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
+16 -3
View File
@@ -1,6 +1,3 @@
import * as d3 from 'd3'; // remove someday, see #4379
export { d3 };
export * from './actions/index';
export * from './behavior/index';
export * from './core/index';
@@ -23,3 +20,19 @@ export * from './util/index';
export * from './validations/index';
export let debug = false;
// reexport just what our tests use, see #4379
import * as D3 from 'd3';
export let d3 = {
customEvent: D3.customEvent,
dispatch: D3.dispatch,
event: D3.event,
geoMercator: D3.geoMercator,
geoProjection: D3.geoProjection,
polygonArea: D3.polygonArea,
polygonCentroid: D3.polygonCentroid,
select: D3.select,
selectAll: D3.selectAll,
timerFlush: D3.timerFlush
};
+1 -1
View File
@@ -129,7 +129,7 @@ describe('iD.actionOrthogonalize', function () {
});
it('preserves the shape of skinny quads', function () {
var projection = iD.d3.geoMercator();
var projection = d3.geoMercator();
var tests = [[
[-77.0339864831478, 38.8616391227204],
[-77.0209775298677, 38.8613609264884],
+46 -50
View File
@@ -31,8 +31,8 @@ describe('iD.osmChangeset', function () {
describe('#osmChangeJXON', function() {
it('converts change data to JXON', function() {
var changeset = iD.osmChangeset(),
jxon = changeset.osmChangeJXON({ created: [], modified: [], deleted: [] });
var changeset = iD.osmChangeset();
var jxon = changeset.osmChangeJXON({ created: [], modified: [], deleted: [] });
expect(jxon).to.eql({
osmChange: {
@@ -46,58 +46,55 @@ describe('iD.osmChangeset', function () {
});
it('includes creations ordered by nodes, ways, relations', function() {
var n = iD.osmNode({ loc: [0, 0] }),
w = iD.osmWay(),
r = iD.osmRelation(),
c = iD.osmChangeset({ id: '1234' }),
changes = { created: [r, w, n], modified: [], deleted: [] },
jxon = c.osmChangeJXON(changes);
var n = iD.osmNode({ loc: [0, 0] });
var w = iD.osmWay();
var r = iD.osmRelation();
var c = iD.osmChangeset({ id: '1234' });
var changes = { created: [r, w, n], modified: [], deleted: [] };
var jxon = c.osmChangeJXON(changes);
expect(d3.entries(jxon.osmChange.create)).to.eql([
{ key: 'node', value: [n.asJXON('1234').node] },
{ key: 'way', value: [w.asJXON('1234').way] },
{ key: 'relation', value: [r.asJXON('1234').relation] }
]);
var result = jxon.osmChange.create;
expect(result.node).to.eql([n.asJXON('1234').node]);
expect(result.way).to.eql([w.asJXON('1234').way]);
expect(result.relation).to.eql([r.asJXON('1234').relation]);
});
it('includes creations ordered by dependencies', function() {
var n = iD.osmNode({ loc: [0, 0] }),
w = iD.osmWay({nodes: [n.id]}),
r1 = iD.osmRelation({ members: [{ id: w.id, type: 'way' }] }),
r2 = iD.osmRelation({ members: [{ id: r1.id, type: 'relation' }] }),
c = iD.osmChangeset({ id: '1234' }),
changes = { created: [r2, r1, w, n], modified: [], deleted: [] },
jxon = c.osmChangeJXON(changes);
var n = iD.osmNode({ loc: [0, 0] });
var w = iD.osmWay({nodes: [n.id]});
var r1 = iD.osmRelation({ members: [{ id: w.id, type: 'way' }] });
var r2 = iD.osmRelation({ members: [{ id: r1.id, type: 'relation' }] });
var c = iD.osmChangeset({ id: '1234' });
var changes = { created: [r2, r1, w, n], modified: [], deleted: [] };
var jxon = c.osmChangeJXON(changes);
expect(d3.entries(jxon.osmChange.create)).to.eql([
{ key: 'node', value: [n.asJXON('1234').node] },
{ key: 'way', value: [w.asJXON('1234').way] },
{ key: 'relation', value: [r1.asJXON('1234').relation, r2.asJXON('1234').relation] },
]);
var result = jxon.osmChange.create;
expect(result.node).to.eql([n.asJXON('1234').node]);
expect(result.way).to.eql([w.asJXON('1234').way]);
expect(result.relation).to.eql([r1.asJXON('1234').relation, r2.asJXON('1234').relation]);
});
it('includes creations ignoring circular dependencies', function() {
var r1 = iD.osmRelation(),
r2 = iD.osmRelation(),
c = iD.osmChangeset({ id: '1234' }),
changes, jxon;
var r1 = iD.osmRelation();
var r2 = iD.osmRelation();
var c = iD.osmChangeset({ id: '1234' });
var changes, jxon;
r1.addMember({ id: r2.id, type: 'relation' });
r2.addMember({ id: r1.id, type: 'relation' });
changes = { created: [r1,r2], modified: [], deleted: [] };
jxon = c.osmChangeJXON(changes);
expect(d3.entries(jxon.osmChange.create)).to.eql([
{ key: 'relation', value: [r1.asJXON('1234').relation, r2.asJXON('1234').relation] },
]);
var result = jxon.osmChange.create;
expect(result.relation).to.eql([r1.asJXON('1234').relation, r2.asJXON('1234').relation]);
});
it('includes modifications', function() {
var n = iD.osmNode({ loc: [0, 0] }),
w = iD.osmWay(),
r = iD.osmRelation(),
c = iD.osmChangeset({ id: '1234' }),
changes = { created: [], modified: [r, w, n], deleted: [] },
jxon = c.osmChangeJXON(changes);
var n = iD.osmNode({ loc: [0, 0] });
var w = iD.osmWay();
var r = iD.osmRelation();
var c = iD.osmChangeset({ id: '1234' });
var changes = { created: [], modified: [r, w, n], deleted: [] };
var jxon = c.osmChangeJXON(changes);
expect(jxon.osmChange.modify).to.eql({
node: [n.asJXON('1234').node],
@@ -107,19 +104,18 @@ describe('iD.osmChangeset', function () {
});
it('includes deletions ordered by relations, ways, nodes', function() {
var n = iD.osmNode({ loc: [0, 0] }),
w = iD.osmWay(),
r = iD.osmRelation(),
c = iD.osmChangeset({ id: '1234' }),
changes = { created: [], modified: [], deleted: [n, w, r] },
jxon = c.osmChangeJXON(changes);
var n = iD.osmNode({ loc: [0, 0] });
var w = iD.osmWay();
var r = iD.osmRelation();
var c = iD.osmChangeset({ id: '1234' });
var changes = { created: [], modified: [], deleted: [n, w, r] };
var jxon = c.osmChangeJXON(changes);
expect(d3.entries(jxon.osmChange.delete)).to.eql([
{ key: 'relation', value: [r.asJXON('1234').relation] },
{ key: 'way', value: [w.asJXON('1234').way] },
{ key: 'node', value: [n.asJXON('1234').node] },
{ key: '@if-unused', value: true }
]);
var result = jxon.osmChange.delete;
expect(result.node).to.eql([n.asJXON('1234').node]);
expect(result.way).to.eql([w.asJXON('1234').way]);
expect(result.relation).to.eql([r.asJXON('1234').relation]);
expect(result['@if-unused']).to.eql(true);
});
});
+1 -1
View File
@@ -26,7 +26,7 @@ iD.data.discarded = {};
mocha.setup({
timeout: 60000, // 1 minute
timeout: 5000, // 5 sec
ui: 'bdd',
globals: [
'__onresize.tail-size',
+1 -1
View File
@@ -15,7 +15,7 @@ describe('uiCombobox', function() {
var start = input.property('selectionStart');
var finis = input.property('selectionEnd');
iD.d3.customEvent(happen.makeEvent({
d3.customEvent(happen.makeEvent({
type: 'keydown',
keyCode: keyCode
}), input.on('keydown.combo-input'));