UNPKG

@sports-alliance/sports-lib

Version:

A Library to for importing / exporting and processing GPX, TCX, FIT and JSON files from services such as Strava, Movescount, Garmin, Polar etc

102 lines (101 loc) 4.54 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); const fs = __importStar(require("fs")); const path = __importStar(require("path")); const data_store_1 = require("./data.store"); describe('DataStore Export Verification', () => { const dataDir = __dirname; const files = fs.readdirSync(dataDir); // Files that are not data classes or should be ignored const ignoredFiles = [ 'data.store.ts', 'data.store.spec.ts', 'data.store.export.spec.ts', 'data.interface.ts', 'data.json.interface.ts', 'data.position.interface.ts', 'data.spec.ts', 'data.ts', // Base class 'data.string.ts', // Base class 'data.number.ts', // Base class 'data.boolean.ts', // Base class 'data.percent.ts', // Base class or abstract? 'data.array.ts', // Base class 'data.balance.ts' // interface/base ]; files.forEach(file => { // Only verify regular TS files related to data if (!file.endsWith('.ts') || file.endsWith('.d.ts') || file.endsWith('.spec.ts')) { return; } // Check if file starts with data if (!file.startsWith('data')) { return; } if (ignoredFiles.includes(file)) { return; } it(`should export data classes from ${file} in DataStore`, () => { const modulePath = path.join(dataDir, file); // Verify file exists before requiring to avoid weird errors if (fs.existsSync(modulePath)) { const moduleExport = require(modulePath); Object.keys(moduleExport).forEach(key => { const ExportedItem = moduleExport[key]; // Check if it looks like a Data class // 1. It's a function (class constructor) // 2. Name starts with Data // 3. It is not an abstract class (we use a simple heuristic or explicit ignore list if needed) // Simple heuristic: if it has a static 'type' property, it probably should be in DataStore. if (typeof ExportedItem === 'function' && key.startsWith('Data')) { // Check for static 'type' property which usually indicates a concrete data class if (ExportedItem.type) { expect(data_store_1.DataStore[key]).toBeDefined(); // verify it points to the same class expect(data_store_1.DataStore[key]).toBe(ExportedItem); } else { // If it doesn't have a 'type', it acts like a base class (e.g. DataQuantity) // We can log it or ignore it. // For now, let's assume if it's named Data*, it might be relevant, // but strictly enforcing presence in DataStore usually requires the 'type' to be useful for the loader. } } }); } }); }); });