@strapi/typescript-utils 5.50.0 → 5.50.1
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.
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { generateSharedExtensionDefinition, emitDefinitions } = require('../../generators/utils');
|
|
4
|
+
|
|
5
|
+
const makeDefinition = (uid, name) => ({
|
|
6
|
+
uid,
|
|
7
|
+
definition: { name: { escapedText: name } },
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
describe('generateSharedExtensionDefinition', () => {
|
|
11
|
+
test('emits ambient module aug with TS-6-compliant `namespace` keyword (not legacy `module`)', () => {
|
|
12
|
+
const node = generateSharedExtensionDefinition('ContentTypeSchemas', [
|
|
13
|
+
makeDefinition('api::foo.foo', 'ApiFooFoo'),
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
const output = emitDefinitions([node]);
|
|
17
|
+
|
|
18
|
+
expect(output).toContain("declare module '@strapi/strapi'");
|
|
19
|
+
expect(output).toContain('export namespace Public');
|
|
20
|
+
expect(output).not.toMatch(/export\s+module\s+Public\b/);
|
|
21
|
+
expect(output).toContain("'api::foo.foo': ApiFooFoo");
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('emits empty namespace block when no definitions provided', () => {
|
|
25
|
+
const node = generateSharedExtensionDefinition('ContentTypeSchemas', []);
|
|
26
|
+
|
|
27
|
+
const output = emitDefinitions([node]);
|
|
28
|
+
|
|
29
|
+
expect(output).toContain('export namespace Public');
|
|
30
|
+
expect(output).not.toMatch(/export\s+module\s+Public\b/);
|
|
31
|
+
expect(output).not.toContain('ContentTypeSchemas');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('passes through registry name to interface declaration', () => {
|
|
35
|
+
const node = generateSharedExtensionDefinition('ComponentSchemas', [
|
|
36
|
+
makeDefinition('default.bar', 'DefaultBar'),
|
|
37
|
+
]);
|
|
38
|
+
|
|
39
|
+
const output = emitDefinitions([node]);
|
|
40
|
+
|
|
41
|
+
expect(output).toContain('export interface ComponentSchemas');
|
|
42
|
+
});
|
|
43
|
+
});
|
package/lib/generators/utils.js
CHANGED