@jjlmoya/utils-motor 1.12.0 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { existsSync, readdirSync, statSync } from 'node:fs';
|
|
2
|
+
import { basename, join } from 'node:path';
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
import { ALL_TOOLS } from '../tools';
|
|
5
|
+
import { CATEGORY_OG_IMAGE, getUtilityOgImage } from '../mfe/assets';
|
|
6
|
+
|
|
7
|
+
const categoryImageMatch = CATEGORY_OG_IMAGE.match(
|
|
8
|
+
/^(\/_utilities\/[^/]+\/images)\/([^/]+\.webp)\?version=(.+)$/,
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
if (!categoryImageMatch) {
|
|
12
|
+
throw new Error(`Unexpected CATEGORY_OG_IMAGE format: ${CATEGORY_OG_IMAGE}`);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const [, imageUrlRoot, categoryImage, assetVersion] = categoryImageMatch;
|
|
16
|
+
const assetRoot = join(process.cwd(), 'public', imageUrlRoot.slice(1));
|
|
17
|
+
const categorySlug = basename(categoryImage, '.webp');
|
|
18
|
+
|
|
19
|
+
describe('MFE asset contract', () => {
|
|
20
|
+
it('has one non-empty English-slug OG image per category and registered tool', async () => {
|
|
21
|
+
const expectedSlugs = new Set([categorySlug]);
|
|
22
|
+
|
|
23
|
+
for (const { entry } of ALL_TOOLS) {
|
|
24
|
+
const englishLoader = entry.i18n.en;
|
|
25
|
+
if (!englishLoader) throw new Error(`Missing English locale for ${entry.id}`);
|
|
26
|
+
|
|
27
|
+
const englishContent = await englishLoader();
|
|
28
|
+
expectedSlugs.add(englishContent.slug);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const actualSlugs = new Set(
|
|
32
|
+
readdirSync(assetRoot)
|
|
33
|
+
.filter((filename) => filename.endsWith('.webp'))
|
|
34
|
+
.map((filename) => filename.slice(0, -'.webp'.length)),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
expect(actualSlugs).toEqual(expectedSlugs);
|
|
38
|
+
|
|
39
|
+
for (const slug of expectedSlugs) {
|
|
40
|
+
const imagePath = join(assetRoot, `${slug}.webp`);
|
|
41
|
+
expect(existsSync(imagePath), `${imagePath} should exist`).toBe(true);
|
|
42
|
+
expect(statSync(imagePath).size, `${imagePath} should not be empty`).toBeGreaterThan(0);
|
|
43
|
+
expect(getUtilityOgImage(slug)).toBe(
|
|
44
|
+
`${imageUrlRoot}/${slug}.webp?version=${assetVersion}`,
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
}, 30000);
|
|
48
|
+
});
|