You've already forked pigallery2
mirror of
https://github.com/bpatrik/pigallery2.git
synced 2025-11-25 22:32:52 +02:00
Adding minimal Test for repository.md #1047
This commit is contained in:
@@ -30,10 +30,8 @@ export class ExtensionRepository {
|
|||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public repoMD(text: string): ExtensionListItem[] {
|
||||||
public async fetchList(): Promise<ExtensionListItem[]> {
|
const lines = text.split('\n');
|
||||||
const res = await (await fetch(Config.Extensions.repositoryUrl)).text();
|
|
||||||
const lines = res.split('\n');
|
|
||||||
lines.forEach(line => line.trim());
|
lines.forEach(line => line.trim());
|
||||||
const tableStartLine = lines.findIndex(l => l.startsWith('| **Name** |'));
|
const tableStartLine = lines.findIndex(l => l.startsWith('| **Name** |'));
|
||||||
const tableHeaderLines = 2;
|
const tableHeaderLines = 2;
|
||||||
@@ -62,7 +60,12 @@ export class ExtensionRepository {
|
|||||||
zipUrl: this.getUrlFromMDLink(entries[3])
|
zipUrl: this.getUrlFromMDLink(entries[3])
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
this.extensionsList = extensions;
|
return extensions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async fetchList(): Promise<ExtensionListItem[]> {
|
||||||
|
const res = await (await fetch(Config.Extensions.repositoryUrl)).text();
|
||||||
|
this.extensionsList = this.repoMD(res);
|
||||||
this.lastUpdate = new Date().getTime();
|
this.lastUpdate = new Date().getTime();
|
||||||
return this.extensionsList;
|
return this.extensionsList;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import {expect} from 'chai';
|
||||||
|
import { readFile } from 'fs/promises';
|
||||||
|
import {ExtensionRepository} from '../../../../../src/backend/model/extension/ExtensionRepository';
|
||||||
|
import {ProjectPath} from '../../../../../src/backend/ProjectPath';
|
||||||
|
import path = require('path');
|
||||||
|
|
||||||
|
// to help WebStorm to handle the test cases
|
||||||
|
declare let describe: any;
|
||||||
|
declare const after: any;
|
||||||
|
declare const before: any;
|
||||||
|
declare const it: any;
|
||||||
|
|
||||||
|
|
||||||
|
describe('ExtensionRepository', () => {
|
||||||
|
|
||||||
|
it('should parse MD repo file', async () => {
|
||||||
|
|
||||||
|
const text = await readFile(path.join(ProjectPath.Root,'extension/REPOSITORY.md'), 'utf8');
|
||||||
|
const extensions = (new ExtensionRepository()).repoMD(text);
|
||||||
|
expect(extensions[0].id).to.deep.equal('sample-extension');
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user