forked from MapComplete/MapComplete
		
	Fix partial compilation, fix tests
This commit is contained in:
		
							parent
							
								
									9f41e719f2
								
							
						
					
					
						commit
						a08a49abb2
					
				
					 3 changed files with 36 additions and 34 deletions
				
			
		| 
						 | 
					@ -31,6 +31,7 @@ import {FixedUiElement} from "../../UI/Base/FixedUiElement";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default class LayerConfig extends WithContextLoader {
 | 
					export default class LayerConfig extends WithContextLoader {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static readonly syncSelectionAllowed = ["no", "local", "theme-only", "global"] as const;
 | 
				
			||||||
    public readonly id: string;
 | 
					    public readonly id: string;
 | 
				
			||||||
    public readonly name: Translation;
 | 
					    public readonly name: Translation;
 | 
				
			||||||
    public readonly description: Translation;
 | 
					    public readonly description: Translation;
 | 
				
			||||||
| 
						 | 
					@ -44,10 +45,8 @@ export default class LayerConfig extends WithContextLoader {
 | 
				
			||||||
    public readonly maxzoom: number;
 | 
					    public readonly maxzoom: number;
 | 
				
			||||||
    public readonly title?: TagRenderingConfig;
 | 
					    public readonly title?: TagRenderingConfig;
 | 
				
			||||||
    public readonly titleIcons: TagRenderingConfig[];
 | 
					    public readonly titleIcons: TagRenderingConfig[];
 | 
				
			||||||
 | 
					 | 
				
			||||||
    public readonly mapRendering: PointRenderingConfig[]
 | 
					    public readonly mapRendering: PointRenderingConfig[]
 | 
				
			||||||
    public readonly lineRendering: LineRenderingConfig[]
 | 
					    public readonly lineRendering: LineRenderingConfig[]
 | 
				
			||||||
 | 
					 | 
				
			||||||
    public readonly units: Unit[];
 | 
					    public readonly units: Unit[];
 | 
				
			||||||
    public readonly deletion: DeleteConfig | null;
 | 
					    public readonly deletion: DeleteConfig | null;
 | 
				
			||||||
    public readonly allowMove: MoveConfig | null
 | 
					    public readonly allowMove: MoveConfig | null
 | 
				
			||||||
| 
						 | 
					@ -57,15 +56,11 @@ export default class LayerConfig extends WithContextLoader {
 | 
				
			||||||
     * In seconds
 | 
					     * In seconds
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public readonly maxAgeOfCache: number
 | 
					    public readonly maxAgeOfCache: number
 | 
				
			||||||
 | 
					 | 
				
			||||||
    public readonly presets: PresetConfig[];
 | 
					    public readonly presets: PresetConfig[];
 | 
				
			||||||
 | 
					 | 
				
			||||||
    public readonly tagRenderings: TagRenderingConfig[];
 | 
					    public readonly tagRenderings: TagRenderingConfig[];
 | 
				
			||||||
    public readonly filters: FilterConfig[];
 | 
					    public readonly filters: FilterConfig[];
 | 
				
			||||||
    public readonly filterIsSameAs: string;
 | 
					    public readonly filterIsSameAs: string;
 | 
				
			||||||
    public readonly forceLoad: boolean;
 | 
					    public readonly forceLoad: boolean;
 | 
				
			||||||
 | 
					 | 
				
			||||||
    public static readonly syncSelectionAllowed =  ["no" , "local" , "theme-only" , "global"] as const;
 | 
					 | 
				
			||||||
    public readonly syncSelection: (typeof LayerConfig.syncSelectionAllowed)[number] // this is a trick to conver a constant array of strings into a type union of these values
 | 
					    public readonly syncSelection: (typeof LayerConfig.syncSelectionAllowed)[number] // this is a trick to conver a constant array of strings into a type union of these values
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    constructor(
 | 
					    constructor(
 | 
				
			||||||
| 
						 | 
					@ -78,14 +73,20 @@ export default class LayerConfig extends WithContextLoader {
 | 
				
			||||||
        super(json, context)
 | 
					        super(json, context)
 | 
				
			||||||
        this.id = json.id;
 | 
					        this.id = json.id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (typeof json === "string") {
 | 
				
			||||||
 | 
					            throw `Not a valid layer: the layerConfig is a string. 'npm run generate:layeroverview' might be needed (at ${context})`
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (json.id === undefined) {
 | 
					        if (json.id === undefined) {
 | 
				
			||||||
            throw "Not a valid layer: id is undefined: " + JSON.stringify(json)
 | 
					            throw `Not a valid layer: id is undefined: ${JSON.stringify(json)} (At ${context})`
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (json.source === undefined) {
 | 
					        if (json.source === undefined) {
 | 
				
			||||||
            throw "Layer " + this.id + " does not define a source section (" + context + ")"
 | 
					            throw "Layer " + this.id + " does not define a source section (" + context + ")"
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (json.source.osmTags === undefined) {
 | 
					        if (json.source.osmTags === undefined) {
 | 
				
			||||||
            throw "Layer " + this.id + " does not define a osmTags in the source section - these should always be present, even for geojson layers (" + context + ")"
 | 
					            throw "Layer " + this.id + " does not define a osmTags in the source section - these should always be present, even for geojson layers (" + context + ")"
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -313,7 +313,7 @@ class LayerOverviewUtils {
 | 
				
			||||||
                const usedLayers = Array.from(LayerOverviewUtils.extractLayerIdsFrom(themeFile, false))
 | 
					                const usedLayers = Array.from(LayerOverviewUtils.extractLayerIdsFrom(themeFile, false))
 | 
				
			||||||
                    .map(id => LayerOverviewUtils.layerPath + id + ".json")
 | 
					                    .map(id => LayerOverviewUtils.layerPath + id + ".json")
 | 
				
			||||||
                if (!forceReload && !this.shouldBeUpdated([themePath, ...usedLayers], targetPath)) {
 | 
					                if (!forceReload && !this.shouldBeUpdated([themePath, ...usedLayers], targetPath)) {
 | 
				
			||||||
                    fixed.set(themeFile.id, themeFile)
 | 
					                    fixed.set(themeFile.id, JSON.parse(readFileSync(LayerOverviewUtils.themePath+themeFile.id+".json", 'utf8')))
 | 
				
			||||||
                    skippedThemes.push(themeFile.id)
 | 
					                    skippedThemes.push(themeFile.id)
 | 
				
			||||||
                    continue;
 | 
					                    continue;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -29,26 +29,27 @@ describe("GenerateCache", () => {
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
        it("should generate a cached file for the Natuurpunt-theme", async () => {
 | 
					        it("should generate a cached file for the Natuurpunt-theme", async () => {
 | 
				
			||||||
            // We use /var/tmp instead of /tmp, as more OS's (such as MAC) have this
 | 
					            // We use /var/tmp instead of /tmp, as more OS's (such as MAC) have this
 | 
				
			||||||
            if(!existsSync("/var/tmp")){
 | 
					            const dir = "/var/tmp/"
 | 
				
			||||||
 | 
					            if(!existsSync(dir)){
 | 
				
			||||||
                console.log("Not executing caching test: no temp directory found")
 | 
					                console.log("Not executing caching test: no temp directory found")
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            if (existsSync("/var/tmp/np-cache")) {
 | 
					            if (existsSync(dir+"/np-cache")) {
 | 
				
			||||||
                ScriptUtils.readDirRecSync("/var/tmp/np-cache").forEach(p => unlinkSync(p))
 | 
					                ScriptUtils.readDirRecSync(dir+"np-cache").forEach(p => unlinkSync(p))
 | 
				
			||||||
                rmdirSync("/var/tmp/np-cache")
 | 
					                rmdirSync(dir+"np-cache")
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            mkdirSync("/var/tmp/np-cache")
 | 
					            mkdirSync(dir+"np-cache")
 | 
				
			||||||
            initDownloads(
 | 
					            initDownloads(
 | 
				
			||||||
                "(nwr%5B%22amenity%22%3D%22toilets%22%5D%3Bnwr%5B%22amenity%22%3D%22parking%22%5D%3Bnwr%5B%22amenity%22%3D%22bench%22%5D%3Bnwr%5B%22id%22%3D%22location_track%22%5D%3Bnwr%5B%22id%22%3D%22gps%22%5D%3Bnwr%5B%22information%22%3D%22board%22%5D%3Bnwr%5B%22leisure%22%3D%22picnic_table%22%5D%3Bnwr%5B%22man_made%22%3D%22watermill%22%5D%3Bnwr%5B%22user%3Ahome%22%3D%22yes%22%5D%3Bnwr%5B%22user%3Alocation%22%3D%22yes%22%5D%3Bnwr%5B%22leisure%22%3D%22nature_reserve%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22boundary%22%3D%22protected_area%22%5D%5B%22protect_class%22!%3D%2298%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22information%22%3D%22visitor_centre%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22information%22%3D%22office%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22route%22~%22%5E.*foot.*%24%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22route%22~%22%5E.*hiking.*%24%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22route%22~%22%5E.*bycicle.*%24%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22route%22~%22%5E.*horse.*%24%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22leisure%22%3D%22bird_hide%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22amenity%22%3D%22drinking_water%22%5D%5B%22access%22!%3D%22permissive%22%5D%5B%22access%22!%3D%22private%22%5D%3B)%3Bout%20body%3Bout%20meta%3B%3E%3Bout%20skel%20qt%3B"
 | 
					                "(nwr%5B%22amenity%22%3D%22toilets%22%5D%3Bnwr%5B%22amenity%22%3D%22parking%22%5D%3Bnwr%5B%22amenity%22%3D%22bench%22%5D%3Bnwr%5B%22id%22%3D%22location_track%22%5D%3Bnwr%5B%22id%22%3D%22gps%22%5D%3Bnwr%5B%22information%22%3D%22board%22%5D%3Bnwr%5B%22leisure%22%3D%22picnic_table%22%5D%3Bnwr%5B%22man_made%22%3D%22watermill%22%5D%3Bnwr%5B%22user%3Ahome%22%3D%22yes%22%5D%3Bnwr%5B%22user%3Alocation%22%3D%22yes%22%5D%3Bnwr%5B%22leisure%22%3D%22nature_reserve%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22boundary%22%3D%22protected_area%22%5D%5B%22protect_class%22!%3D%2298%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22information%22%3D%22visitor_centre%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22information%22%3D%22office%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22route%22~%22%5E.*foot.*%24%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22route%22~%22%5E.*hiking.*%24%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22route%22~%22%5E.*bycicle.*%24%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22route%22~%22%5E.*horse.*%24%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22leisure%22%3D%22bird_hide%22%5D%5B%22operator%22~%22%5E.*%5BnN%5Datuurpunt.*%24%22%5D%3Bnwr%5B%22amenity%22%3D%22drinking_water%22%5D%5B%22access%22!%3D%22permissive%22%5D%5B%22access%22!%3D%22private%22%5D%3B)%3Bout%20body%3Bout%20meta%3B%3E%3Bout%20skel%20qt%3B"
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
            await main([
 | 
					            await main([
 | 
				
			||||||
                "natuurpunt",
 | 
					                "natuurpunt",
 | 
				
			||||||
                "12",
 | 
					                "12",
 | 
				
			||||||
                "/var/tmp/np-cache",
 | 
					                dir+"np-cache",
 | 
				
			||||||
                "51.15423567022531", "3.250579833984375", "51.162821593316934", "3.262810707092285",
 | 
					                "51.15423567022531", "3.250579833984375", "51.162821593316934", "3.262810707092285",
 | 
				
			||||||
                "--generate-point-overview", "nature_reserve,visitor_information_centre"
 | 
					                "--generate-point-overview", "nature_reserve,visitor_information_centre"
 | 
				
			||||||
            ])
 | 
					            ])
 | 
				
			||||||
            await ScriptUtils.sleep(500)
 | 
					            await ScriptUtils.sleep(500)
 | 
				
			||||||
            const birdhides = JSON.parse(readFileSync("/var/tmp/np-cache/natuurpunt_birdhide_12_2085_1368.geojson", "UTF8"))
 | 
					            const birdhides = JSON.parse(readFileSync(dir+"np-cache/natuurpunt_birdhide_12_2085_1368.geojson", "UTF8"))
 | 
				
			||||||
            expect(birdhides.features.length).deep.equal(5)
 | 
					            expect(birdhides.features.length).deep.equal(5)
 | 
				
			||||||
            expect(birdhides.features.some(f => f.properties.id === "node/5158056232"), "Didn't find birdhide node/5158056232 ").true
 | 
					            expect(birdhides.features.some(f => f.properties.id === "node/5158056232"), "Didn't find birdhide node/5158056232 ").true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue