@exdst-sitecore-content-sdk/astro 0.0.24 → 0.0.25
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 +7 -12
- package/src/context.ts +1 -1
- package/src/client/sitecore-astro-client.test.ts +0 -267
- package/src/components/AstroImage.astro.test.ts +0 -541
- package/src/components/Date.astro.test.ts +0 -197
- package/src/components/EditingScripts.astro.test.ts +0 -267
- package/src/components/ErrorBoundary.astro.test.ts +0 -252
- package/src/components/ErrorComponent.astro.test.ts +0 -31
- package/src/components/FieldMetadata.astro.test.ts +0 -40
- package/src/components/File.astro.test.ts +0 -68
- package/src/components/HiddenRendering.astro.test.ts +0 -36
- package/src/components/Image.astro.test.ts +0 -438
- package/src/components/Link.astro.test.ts +0 -261
- package/src/components/MissingComponent.astro.test.ts +0 -21
- package/src/components/Placeholder/Placeholder.astro.test.ts +0 -1088
- package/src/components/Placeholder/PlaceholderMetadata.astro.test.ts +0 -228
- package/src/components/Placeholder/PlaceholderUtils.astro.test.ts +0 -149
- package/src/components/Placeholder/placeholder-utils.test.ts +0 -309
- package/src/components/RichText.astro.test.ts +0 -205
- package/src/components/Text.astro.test.ts +0 -273
- package/src/config/define-config.test.ts +0 -526
- package/src/config-cli/define-cli-config.test.ts +0 -67
- package/src/editing/editing-config-middleware.test.ts +0 -164
- package/src/editing/editing-render-middleware.test.ts +0 -1143
- package/src/editing/render-middleware.test.ts +0 -57
- package/src/editing/utils.test.ts +0 -1212
- package/src/enhancers/WithEmptyFieldEditingComponent.astro.test.ts +0 -380
- package/src/enhancers/WithFieldMetadata.astro.test.ts +0 -113
- package/src/middleware/middleware.test.ts +0 -520
- package/src/middleware/multisite-middleware.test.ts +0 -736
- package/src/middleware/robots-middleware.test.ts +0 -129
- package/src/middleware/sitemap-middleware.test.ts +0 -184
- package/src/tests/astro-helpers.ts +0 -61
- package/src/tests/helpers.ts +0 -46
- package/src/tests/personalizeData.ts +0 -63
- package/src/tests/test-components/CustomErrorComponent.astro +0 -3
- package/src/tests/test-components/CustomHiddenRendering.astro +0 -10
- package/src/tests/test-components/CustomMissingComponent.astro +0 -9
- package/src/tests/test-components/DownloadCallout.astro +0 -12
- package/src/tests/test-components/EmptyFieldEditingComponent.astro +0 -5
- package/src/tests/test-components/ErrorBoundaryWithError.astro +0 -10
- package/src/tests/test-components/Home.astro +0 -12
- package/src/tests/test-components/SxaRichText.astro +0 -23
- package/src/tests/test-components/SxaRichTextDefault.astro +0 -7
- package/src/tests/test-components/SxaRichTextWithTitle.astro +0 -8
- package/src/tests/test-components/TestComponent.astro +0 -9
- package/src/tests/test-components/TestComponentWithError.astro +0 -4
- package/src/tests/test-components/TestComponentWithField.astro +0 -17
- package/src/tests/test-components/TestHeader.astro +0 -8
- package/src/tests/test-components/TestLogo.astro +0 -5
- package/src/tests/test-components/TestParentWrapperComponent.astro +0 -5
- package/src/tests/test-components/TestWrapperComponent.astro +0 -5
- package/src/tests/test-components/generate-map/Button.astro +0 -4
- package/src/tests/test-components/generate-map/Link.astro +0 -4
- package/src/tests/test-components/map-components/Bar.astro +0 -0
- package/src/tests/test-components/map-components/Baz.astro +0 -0
- package/src/tests/test-components/map-components/Foo.astro +0 -0
- package/src/tests/test-components/map-components/Hero.variant.astro +0 -0
- package/src/tests/test-components/map-components/NotComponent.bsx +0 -0
- package/src/tests/test-components/map-components/Qux.astro +0 -0
- package/src/tests/test-components/map-components/folded/Folded.astro +0 -0
- package/src/tests/test-components/map-components/folded/random-file-2.docx +0 -0
- package/src/tests/test-components/map-components/random-file.txt +0 -0
- package/src/tests/test-data/metadata-data.ts +0 -86
- package/src/tests/test-data/normal-mode-data.ts +0 -466
- package/src/tests/vitest.setup.ts +0 -4
- package/src/tools/generate-map.test.ts +0 -201
- package/src/tools/templating/components.test.ts +0 -318
- package/src/tools/templating/default-component.test.ts +0 -31
- package/src/utils/utils.test.ts +0 -111
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
/* eslint-disable quotes */
|
|
2
|
-
/* eslint-disable no-unused-expressions, @typescript-eslint/no-unused-expressions */
|
|
3
|
-
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import * as chai from 'chai';
|
|
6
|
-
import sinonChai from 'sinon-chai';
|
|
7
|
-
import { expect } from 'chai';
|
|
8
|
-
import sinon from 'sinon';
|
|
9
|
-
|
|
10
|
-
chai.use(sinonChai);
|
|
11
|
-
import { generateMap } from './generate-map';
|
|
12
|
-
import fs from 'fs';
|
|
13
|
-
import { ComponentImport } from '@sitecore-content-sdk/content/tools';
|
|
14
|
-
|
|
15
|
-
describe('generateMap', () => {
|
|
16
|
-
const sandbox = sinon.createSandbox();
|
|
17
|
-
|
|
18
|
-
describe('generateMap', () => {
|
|
19
|
-
const fakePackages: ComponentImport[] = [
|
|
20
|
-
{
|
|
21
|
-
importName: 'MyLib',
|
|
22
|
-
importInfo: {
|
|
23
|
-
importFrom: '@my/lib',
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
importName: 'OtherLib',
|
|
28
|
-
importInfo: {
|
|
29
|
-
importFrom: '@other/lib',
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
];
|
|
33
|
-
|
|
34
|
-
beforeEach(() => {
|
|
35
|
-
sandbox.stub(fs, 'writeFileSync');
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
afterEach(() => {
|
|
39
|
-
sandbox.restore();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('should write componentMap.ts file with components from "paths" parameter', () => {
|
|
43
|
-
const paths = ['src/tests/test-components/generate-map'];
|
|
44
|
-
generateMap({ paths });
|
|
45
|
-
|
|
46
|
-
expect(fs.writeFileSync).to.have.been.calledOnce;
|
|
47
|
-
const [dest, content] = (fs.writeFileSync as sinon.SinonStub).getCall(0).args;
|
|
48
|
-
expect(dest).to.equal(path.join(process.cwd(), '.sitecore', 'component-map.ts'));
|
|
49
|
-
|
|
50
|
-
expect(content).to.include(
|
|
51
|
-
"import type { AstroContentSdkComponent } from '@exdst-sitecore-content-sdk/astro';"
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
expect(content).to.include(
|
|
55
|
-
"import Button from 'src/tests/test-components/generate-map/Button.astro';"
|
|
56
|
-
);
|
|
57
|
-
expect(content).to.include(
|
|
58
|
-
"import Link from 'src/tests/test-components/generate-map/Link.astro';"
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
expect(content).to.include('new Map');
|
|
62
|
-
expect(content).to.include("['Button', Button]");
|
|
63
|
-
expect(content).to.include("['Link', Link]");
|
|
64
|
-
expect(content).to.include('export default componentMap;');
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('should use template from custom componentMap function, when provided', () => {
|
|
68
|
-
const paths = ['src/tests/test-components/generate-map'];
|
|
69
|
-
const customTemplate = sinon.stub().returns('// custom template output');
|
|
70
|
-
const fakePackages = [
|
|
71
|
-
{
|
|
72
|
-
importName: 'CustomLib',
|
|
73
|
-
importInfo: {
|
|
74
|
-
importFrom: '@custom/lib',
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
];
|
|
78
|
-
generateMap({ paths, componentImports: fakePackages, mapTemplate: customTemplate });
|
|
79
|
-
|
|
80
|
-
expect(customTemplate).to.have.been.calledOnce;
|
|
81
|
-
const [componentsArg, packagesArg] = customTemplate.getCall(0).args;
|
|
82
|
-
expect(packagesArg).to.deep.equal(fakePackages);
|
|
83
|
-
expect(componentsArg.map((c: any) => c.componentName)).to.include.members(['Button', 'Link']);
|
|
84
|
-
|
|
85
|
-
expect(fs.writeFileSync).to.have.been.calledOnce;
|
|
86
|
-
const [, content] = (fs.writeFileSync as sinon.SinonStub).getCall(0).args;
|
|
87
|
-
expect(content).to.equal('// custom template output');
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('should generate an empty component map if no components are found', () => {
|
|
91
|
-
const paths = ['src/tests/test-components/generate-map-empty'];
|
|
92
|
-
generateMap({ paths });
|
|
93
|
-
|
|
94
|
-
expect(fs.writeFileSync).to.have.been.calledOnce;
|
|
95
|
-
const [, content] = (fs.writeFileSync as sinon.SinonStub).getCall(0).args;
|
|
96
|
-
expect(content).to.include(
|
|
97
|
-
'export const componentMap = new Map<string, AstroContentSdkComponent>(['
|
|
98
|
-
);
|
|
99
|
-
expect(content).to.not.match(/\['Button'[\s\S]*Button/);
|
|
100
|
-
expect(content).to.not.match(/\['Link'[\s\S]*Link/);
|
|
101
|
-
expect(content).to.include('export default componentMap;');
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('should handle multiple paths and merge their components', () => {
|
|
105
|
-
const paths = [
|
|
106
|
-
'src/tests/test-components/generate-map',
|
|
107
|
-
'src/tests/test-components/map-components',
|
|
108
|
-
];
|
|
109
|
-
|
|
110
|
-
generateMap({ paths });
|
|
111
|
-
|
|
112
|
-
expect(fs.writeFileSync).to.have.been.calledOnce;
|
|
113
|
-
const [mainDest, content] = (fs.writeFileSync as sinon.SinonStub).getCall(0).args;
|
|
114
|
-
expect(mainDest).to.equal(path.join(process.cwd(), '.sitecore', 'component-map.ts'));
|
|
115
|
-
|
|
116
|
-
expect(content).to.include('new Map');
|
|
117
|
-
|
|
118
|
-
expect(content).to.include(
|
|
119
|
-
"import Button from 'src/tests/test-components/generate-map/Button.astro';"
|
|
120
|
-
);
|
|
121
|
-
expect(content).to.include(
|
|
122
|
-
"import Link from 'src/tests/test-components/generate-map/Link.astro';"
|
|
123
|
-
);
|
|
124
|
-
expect(content).to.include(
|
|
125
|
-
"import Bar from 'src/tests/test-components/map-components/Bar.astro';"
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
expect(content).to.include("['Button', Button]");
|
|
129
|
-
expect(content).to.include("['Link', Link]");
|
|
130
|
-
expect(content).to.include("['Bar', Bar]");
|
|
131
|
-
expect(content).to.include('export default componentMap;');
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it('should not fail if packages is undefined', () => {
|
|
135
|
-
const paths = ['src/components'];
|
|
136
|
-
expect(() => generateMap({ paths, componentImports: undefined })).to.not.throw();
|
|
137
|
-
expect(fs.writeFileSync).to.have.been.calledOnce;
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it('should write componentMap.ts file with components from "paths" and "packages" parameters, when provided', () => {
|
|
141
|
-
const paths = ['src/components'];
|
|
142
|
-
generateMap({ paths, componentImports: fakePackages });
|
|
143
|
-
|
|
144
|
-
expect(fs.writeFileSync).to.have.been.calledOnce;
|
|
145
|
-
const [, content] = (fs.writeFileSync as sinon.SinonStub).getCall(0).args;
|
|
146
|
-
expect(content).to.include("import MyLib from '@my/lib';");
|
|
147
|
-
expect(content).to.include("import OtherLib from '@other/lib';");
|
|
148
|
-
|
|
149
|
-
expect(content).to.include(
|
|
150
|
-
'export const componentMap = new Map<string, AstroContentSdkComponent>(['
|
|
151
|
-
);
|
|
152
|
-
expect(content).to.include("['MyLib', MyLib],");
|
|
153
|
-
expect(content).to.include("['OtherLib', OtherLib],");
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it('should use custom destination when provided', () => {
|
|
157
|
-
const paths = ['src/components'];
|
|
158
|
-
const customDir = path.join(process.cwd(), 'custom/path');
|
|
159
|
-
const mainDest = path.join(customDir, 'component-map.ts');
|
|
160
|
-
|
|
161
|
-
generateMap({ paths, destination: 'custom/path', includeVariants: false });
|
|
162
|
-
|
|
163
|
-
expect(fs.writeFileSync).to.have.been.calledOnce;
|
|
164
|
-
|
|
165
|
-
const encodingArg = sinon.match.string.or(sinon.match.has('encoding'));
|
|
166
|
-
|
|
167
|
-
expect(fs.writeFileSync).to.have.been.calledWithMatch(
|
|
168
|
-
mainDest,
|
|
169
|
-
sinon.match.string,
|
|
170
|
-
encodingArg
|
|
171
|
-
);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it('should pass exclude param into component collection call', () => {
|
|
175
|
-
const paths = ['src/tests/test-components/generate-map'];
|
|
176
|
-
const exclude = ['src/tests/test-components/generate-map/Button.*'];
|
|
177
|
-
generateMap({ paths, exclude });
|
|
178
|
-
|
|
179
|
-
expect(fs.writeFileSync).to.have.been.calledOnce;
|
|
180
|
-
const [, content] = (fs.writeFileSync as sinon.SinonStub).getCall(0).args;
|
|
181
|
-
|
|
182
|
-
expect(content).to.include(
|
|
183
|
-
"import Link from 'src/tests/test-components/generate-map/Link.astro';"
|
|
184
|
-
);
|
|
185
|
-
expect(content).to.not.include('Button');
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it('should throw error when destination cannot be written to', async () => {
|
|
189
|
-
(fs.writeFileSync as sinon.SinonStub).throws(new Error('Disk full'));
|
|
190
|
-
const paths = ['src/components'];
|
|
191
|
-
let errorCaught = null;
|
|
192
|
-
try {
|
|
193
|
-
generateMap({ paths });
|
|
194
|
-
} catch (err) {
|
|
195
|
-
errorCaught = err;
|
|
196
|
-
}
|
|
197
|
-
expect(errorCaught).to.be.an('error');
|
|
198
|
-
expect((errorCaught as Error).message).to.equal('Disk full');
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
});
|
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-unused-expressions */
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
import sinon from 'sinon';
|
|
4
|
-
import { getComponentList } from './components';
|
|
5
|
-
import { ComponentFile } from '@sitecore-content-sdk/content/tools';
|
|
6
|
-
import path from 'path';
|
|
7
|
-
|
|
8
|
-
describe('components', () => {
|
|
9
|
-
const sandbox = sinon.createSandbox();
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
sandbox.restore();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
describe('getComponentList', () => {
|
|
15
|
-
afterEach(() => {
|
|
16
|
-
sandbox.restore();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('should return results when one of "paths" is a glob pattern', () => {
|
|
20
|
-
const items = [
|
|
21
|
-
{
|
|
22
|
-
importPath: 'src/tests/test-components/map-components/Qux',
|
|
23
|
-
filePath: path.normalize('src/tests/test-components/map-components/Qux.astro'),
|
|
24
|
-
componentName: 'Qux',
|
|
25
|
-
moduleName: 'Qux',
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
importPath: 'src/tests/test-components/map-components/Foo',
|
|
29
|
-
filePath: path.normalize('src/tests/test-components/map-components/Foo.astro'),
|
|
30
|
-
componentName: 'Foo',
|
|
31
|
-
moduleName: 'Foo',
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
importPath: 'src/tests/test-components/map-components/Baz',
|
|
35
|
-
filePath: path.normalize('src/tests/test-components/map-components/Baz.astro'),
|
|
36
|
-
componentName: 'Baz',
|
|
37
|
-
moduleName: 'Baz',
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
importPath: 'src/tests/test-components/map-components/Bar',
|
|
41
|
-
filePath: path.normalize('src/tests/test-components/map-components/Bar.astro'),
|
|
42
|
-
componentName: 'Bar',
|
|
43
|
-
moduleName: 'Bar',
|
|
44
|
-
},
|
|
45
|
-
] as ComponentFile[];
|
|
46
|
-
|
|
47
|
-
const result = getComponentList(
|
|
48
|
-
['src/tests/test-components/map-components/*.astro'],
|
|
49
|
-
['**/*.test.*'],
|
|
50
|
-
false
|
|
51
|
-
);
|
|
52
|
-
expect(result).to.deep.equal(items);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('should return results with all folded paths when path is a non-glob path', () => {
|
|
56
|
-
const items = [
|
|
57
|
-
{
|
|
58
|
-
importPath: 'src/tests/test-components/map-components/Qux',
|
|
59
|
-
filePath: path.normalize('src/tests/test-components/map-components/Qux.astro'),
|
|
60
|
-
componentName: 'Qux',
|
|
61
|
-
moduleName: 'Qux',
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
importPath: 'src/tests/test-components/map-components/Foo',
|
|
65
|
-
filePath: path.normalize('src/tests/test-components/map-components/Foo.astro'),
|
|
66
|
-
componentName: 'Foo',
|
|
67
|
-
moduleName: 'Foo',
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
importPath: 'src/tests/test-components/map-components/Baz',
|
|
71
|
-
filePath: path.normalize('src/tests/test-components/map-components/Baz.astro'),
|
|
72
|
-
componentName: 'Baz',
|
|
73
|
-
moduleName: 'Baz',
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
importPath: 'src/tests/test-components/map-components/Bar',
|
|
77
|
-
filePath: path.normalize('src/tests/test-components/map-components/Bar.astro'),
|
|
78
|
-
componentName: 'Bar',
|
|
79
|
-
moduleName: 'Bar',
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
importPath: 'src/tests/test-components/map-components/folded/Folded',
|
|
83
|
-
filePath: path.normalize('src/tests/test-components/map-components/folded/Folded.astro'),
|
|
84
|
-
componentName: 'Folded',
|
|
85
|
-
moduleName: 'Folded',
|
|
86
|
-
},
|
|
87
|
-
] as ComponentFile[];
|
|
88
|
-
|
|
89
|
-
const result = getComponentList(
|
|
90
|
-
['src/tests/test-components/map-components'],
|
|
91
|
-
['**/*.test.*'],
|
|
92
|
-
false
|
|
93
|
-
);
|
|
94
|
-
expect(result).to.deep.equal(items);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('should filter out results that are not components', () => {
|
|
98
|
-
const items = [
|
|
99
|
-
{
|
|
100
|
-
importPath: 'src/tests/test-components/map-components/Qux',
|
|
101
|
-
filePath: path.normalize('src/tests/test-components/map-components/Qux.astro'),
|
|
102
|
-
componentName: 'Qux',
|
|
103
|
-
moduleName: 'Qux',
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
importPath: 'src/tests/test-components/map-components/Foo',
|
|
107
|
-
filePath: path.normalize('src/tests/test-components/map-components/Foo.astro'),
|
|
108
|
-
componentName: 'Foo',
|
|
109
|
-
moduleName: 'Foo',
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
importPath: 'src/tests/test-components/map-components/Baz',
|
|
113
|
-
filePath: path.normalize('src/tests/test-components/map-components/Baz.astro'),
|
|
114
|
-
componentName: 'Baz',
|
|
115
|
-
moduleName: 'Baz',
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
importPath: 'src/tests/test-components/map-components/Bar',
|
|
119
|
-
filePath: path.normalize('src/tests/test-components/map-components/Bar.astro'),
|
|
120
|
-
componentName: 'Bar',
|
|
121
|
-
moduleName: 'Bar',
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
importPath: 'src/tests/test-components/map-components/folded/Folded',
|
|
125
|
-
filePath: path.normalize('src/tests/test-components/map-components/folded/Folded.astro'),
|
|
126
|
-
componentName: 'Folded',
|
|
127
|
-
moduleName: 'Folded',
|
|
128
|
-
},
|
|
129
|
-
] as ComponentFile[];
|
|
130
|
-
|
|
131
|
-
const result = getComponentList(['src/tests/test-components/map-components/**/*']);
|
|
132
|
-
expect(result).to.deep.equal(items);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('should return result when "paths" contain exact paths to Astro components', () => {
|
|
136
|
-
const items = [
|
|
137
|
-
{
|
|
138
|
-
importPath: 'src/tests/test-components/map-components/Foo',
|
|
139
|
-
filePath: path.normalize('src/tests/test-components/map-components/Foo.astro'),
|
|
140
|
-
componentName: 'Foo',
|
|
141
|
-
moduleName: 'Foo',
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
importPath: 'src/tests/test-components/map-components/Bar',
|
|
145
|
-
filePath: path.normalize('src/tests/test-components/map-components/Bar.astro'),
|
|
146
|
-
componentName: 'Bar',
|
|
147
|
-
moduleName: 'Bar',
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
importPath: 'src/tests/test-components/map-components/Baz',
|
|
151
|
-
filePath: path.normalize('src/tests/test-components/map-components/Baz.astro'),
|
|
152
|
-
componentName: 'Baz',
|
|
153
|
-
moduleName: 'Baz',
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
importPath: 'src/tests/test-components/map-components/Qux',
|
|
157
|
-
filePath: path.normalize('src/tests/test-components/map-components/Qux.astro'),
|
|
158
|
-
componentName: 'Qux',
|
|
159
|
-
moduleName: 'Qux',
|
|
160
|
-
},
|
|
161
|
-
];
|
|
162
|
-
|
|
163
|
-
const result = getComponentList([
|
|
164
|
-
'src/tests/test-components/map-components/Foo.astro',
|
|
165
|
-
'src/tests/test-components/map-components/Bar.astro',
|
|
166
|
-
'src/tests/test-components/map-components/Baz.astro',
|
|
167
|
-
'src/tests/test-components/map-components/Qux.astro',
|
|
168
|
-
]);
|
|
169
|
-
expect(result).to.deep.equal(items);
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it('should return filtered results when "exclude" contains a glob pattern', () => {
|
|
173
|
-
const exclude = ['**/test-components/map-components/**'];
|
|
174
|
-
expect(getComponentList(['src/tests/test-components/map-components/*.astro'], exclude)).to.be
|
|
175
|
-
.empty;
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
it('should return variants in results when includeVariants is true', () => {
|
|
179
|
-
sandbox.stub(console, 'debug');
|
|
180
|
-
|
|
181
|
-
const items = [
|
|
182
|
-
{
|
|
183
|
-
importPath: 'src/tests/test-components/map-components/Qux',
|
|
184
|
-
filePath: path.normalize('src/tests/test-components/map-components/Qux.astro'),
|
|
185
|
-
componentName: 'Qux',
|
|
186
|
-
moduleName: 'Qux',
|
|
187
|
-
},
|
|
188
|
-
// variant component
|
|
189
|
-
{
|
|
190
|
-
importPath: 'src/tests/test-components/map-components/Hero.variant',
|
|
191
|
-
filePath: path.normalize('src/tests/test-components/map-components/Hero.variant.astro'),
|
|
192
|
-
componentName: 'Hero.variant',
|
|
193
|
-
moduleName: 'Herovariant',
|
|
194
|
-
},
|
|
195
|
-
{
|
|
196
|
-
importPath: 'src/tests/test-components/map-components/Foo',
|
|
197
|
-
filePath: path.normalize('src/tests/test-components/map-components/Foo.astro'),
|
|
198
|
-
componentName: 'Foo',
|
|
199
|
-
moduleName: 'Foo',
|
|
200
|
-
},
|
|
201
|
-
{
|
|
202
|
-
importPath: 'src/tests/test-components/map-components/Baz',
|
|
203
|
-
filePath: path.normalize('src/tests/test-components/map-components/Baz.astro'),
|
|
204
|
-
componentName: 'Baz',
|
|
205
|
-
moduleName: 'Baz',
|
|
206
|
-
},
|
|
207
|
-
{
|
|
208
|
-
importPath: 'src/tests/test-components/map-components/Bar',
|
|
209
|
-
filePath: path.normalize('src/tests/test-components/map-components/Bar.astro'),
|
|
210
|
-
componentName: 'Bar',
|
|
211
|
-
moduleName: 'Bar',
|
|
212
|
-
},
|
|
213
|
-
{
|
|
214
|
-
importPath: 'src/tests/test-components/map-components/folded/Folded',
|
|
215
|
-
filePath: path.normalize('src/tests/test-components/map-components/folded/Folded.astro'),
|
|
216
|
-
componentName: 'Folded',
|
|
217
|
-
moduleName: 'Folded',
|
|
218
|
-
},
|
|
219
|
-
] as ComponentFile[];
|
|
220
|
-
|
|
221
|
-
const result = getComponentList(
|
|
222
|
-
['src/tests/test-components/map-components'],
|
|
223
|
-
['**/*.test.*'],
|
|
224
|
-
true
|
|
225
|
-
);
|
|
226
|
-
expect(result).to.deep.equal(items);
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
it('should return filtered results when "exclude" contains an exact path', () => {
|
|
230
|
-
const exclude = ['src/tests/test-components/map-components/Foo.astro'];
|
|
231
|
-
getComponentList(['src/tests/test-components/map-components/*.astro'], exclude);
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
it('should return correct result in unix file systems', () => {
|
|
235
|
-
const stubbedPaths = [
|
|
236
|
-
'src/tests/test-components/map-components/Foo.astro',
|
|
237
|
-
'src/tests/test-components/map-components/Bar.astro',
|
|
238
|
-
'src/tests/test-components/map-components/Baz.astro',
|
|
239
|
-
'src/tests/test-components/map-components/Qux.astro',
|
|
240
|
-
];
|
|
241
|
-
const expected = [
|
|
242
|
-
{
|
|
243
|
-
importPath: 'src/tests/test-components/map-components/Foo',
|
|
244
|
-
filePath: 'src/tests/test-components/map-components/Foo.astro',
|
|
245
|
-
componentName: 'Foo',
|
|
246
|
-
moduleName: 'Foo',
|
|
247
|
-
},
|
|
248
|
-
{
|
|
249
|
-
importPath: 'src/tests/test-components/map-components/Bar',
|
|
250
|
-
filePath: 'src/tests/test-components/map-components/Bar.astro',
|
|
251
|
-
componentName: 'Bar',
|
|
252
|
-
moduleName: 'Bar',
|
|
253
|
-
},
|
|
254
|
-
{
|
|
255
|
-
importPath: 'src/tests/test-components/map-components/Baz',
|
|
256
|
-
filePath: 'src/tests/test-components/map-components/Baz.astro',
|
|
257
|
-
componentName: 'Baz',
|
|
258
|
-
moduleName: 'Baz',
|
|
259
|
-
},
|
|
260
|
-
{
|
|
261
|
-
importPath: 'src/tests/test-components/map-components/Qux',
|
|
262
|
-
filePath: 'src/tests/test-components/map-components/Qux.astro',
|
|
263
|
-
componentName: 'Qux',
|
|
264
|
-
moduleName: 'Qux',
|
|
265
|
-
},
|
|
266
|
-
];
|
|
267
|
-
|
|
268
|
-
const globSyncStub = sandbox.stub(require('glob'), 'sync').returns(stubbedPaths);
|
|
269
|
-
|
|
270
|
-
const result = getComponentList(['src/tests/test-components/map-components/*.astro']);
|
|
271
|
-
expect(result).to.deep.equal(expected);
|
|
272
|
-
|
|
273
|
-
globSyncStub.restore();
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
it('should return correct result in windows file systems', () => {
|
|
277
|
-
const stubbedPaths = [
|
|
278
|
-
'src\\tests\\test-components\\map-components\\Foo.astro',
|
|
279
|
-
'src\\tests\\test-components\\map-components\\Bar.astro',
|
|
280
|
-
'src\\tests\\test-components\\map-components\\Baz.astro',
|
|
281
|
-
'src\\tests\\test-components\\map-components\\Qux.astro',
|
|
282
|
-
];
|
|
283
|
-
const expected = [
|
|
284
|
-
{
|
|
285
|
-
importPath: 'src/tests/test-components/map-components/Foo',
|
|
286
|
-
filePath: 'src\\tests\\test-components\\map-components\\Foo.astro',
|
|
287
|
-
componentName: 'Foo',
|
|
288
|
-
moduleName: 'Foo',
|
|
289
|
-
},
|
|
290
|
-
{
|
|
291
|
-
importPath: 'src/tests/test-components/map-components/Bar',
|
|
292
|
-
filePath: 'src\\tests\\test-components\\map-components\\Bar.astro',
|
|
293
|
-
componentName: 'Bar',
|
|
294
|
-
moduleName: 'Bar',
|
|
295
|
-
},
|
|
296
|
-
{
|
|
297
|
-
importPath: 'src/tests/test-components/map-components/Baz',
|
|
298
|
-
filePath: 'src\\tests\\test-components\\map-components\\Baz.astro',
|
|
299
|
-
componentName: 'Baz',
|
|
300
|
-
moduleName: 'Baz',
|
|
301
|
-
},
|
|
302
|
-
{
|
|
303
|
-
importPath: 'src/tests/test-components/map-components/Qux',
|
|
304
|
-
filePath: 'src\\tests\\test-components\\map-components\\Qux.astro',
|
|
305
|
-
componentName: 'Qux',
|
|
306
|
-
moduleName: 'Qux',
|
|
307
|
-
},
|
|
308
|
-
];
|
|
309
|
-
|
|
310
|
-
const globSyncStub = sandbox.stub(require('glob'), 'sync').returns(stubbedPaths);
|
|
311
|
-
|
|
312
|
-
const result = getComponentList(['src/tests/test-components/map-components/*.astro']);
|
|
313
|
-
expect(result).to.deep.equal(expected);
|
|
314
|
-
|
|
315
|
-
globSyncStub.restore();
|
|
316
|
-
});
|
|
317
|
-
});
|
|
318
|
-
});
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-unused-expressions, @typescript-eslint/no-unused-expressions */
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
import { defaultTemplate } from './default-component';
|
|
4
|
-
import chalk from 'chalk';
|
|
5
|
-
|
|
6
|
-
describe('default-component', () => {
|
|
7
|
-
describe('generateTemplate', () => {
|
|
8
|
-
it('should generate a template with the given component name', () => {
|
|
9
|
-
const componentName = 'TestComponent';
|
|
10
|
-
const template = defaultTemplate.generateTemplate(componentName);
|
|
11
|
-
expect(template).to.include(`export type ${componentName}Props`);
|
|
12
|
-
expect(template).to.include(`<p>${componentName} Component</p>`);
|
|
13
|
-
});
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
describe('getNextSteps', () => {
|
|
17
|
-
it('should return an empty array if no componentOutputPath is provided', () => {
|
|
18
|
-
const nextSteps = defaultTemplate.getNextSteps && defaultTemplate.getNextSteps('');
|
|
19
|
-
expect(nextSteps).to.be.an('array').that.is.empty;
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('should return an array with next steps if componentOutputPath is provided', () => {
|
|
23
|
-
const componentOutputPath = 'src/components/TestComponent.astro';
|
|
24
|
-
const nextSteps =
|
|
25
|
-
defaultTemplate.getNextSteps && defaultTemplate.getNextSteps(componentOutputPath);
|
|
26
|
-
expect(nextSteps)
|
|
27
|
-
.to.be.an('array')
|
|
28
|
-
.that.includes(`* Implement the Astro component in ${chalk.green(componentOutputPath)}`);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
});
|
package/src/utils/utils.test.ts
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-unused-expressions */
|
|
2
|
-
import { expect, use } from 'chai';
|
|
3
|
-
import spies from 'chai-spies';
|
|
4
|
-
import { addClassName, extractPath, getEditingSecret, removeLanguageFromPath } from './utils';
|
|
5
|
-
|
|
6
|
-
use(spies);
|
|
7
|
-
|
|
8
|
-
describe('utils', () => {
|
|
9
|
-
describe('getEditingSecret', () => {
|
|
10
|
-
afterEach(() => {
|
|
11
|
-
delete process.env.SITECORE_EDITING_SECRET;
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('should throw if env variable missing', () => {
|
|
15
|
-
expect(() => getEditingSecret()).to.throw();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('should return env variable', () => {
|
|
19
|
-
const secret = '1234abcd';
|
|
20
|
-
process.env.SITECORE_EDITING_SECRET = secret;
|
|
21
|
-
const result = getEditingSecret();
|
|
22
|
-
expect(result).to.equal(secret);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
describe('addClassName', () => {
|
|
28
|
-
it('should add class attribute value to className', () => {
|
|
29
|
-
const modifiableAttrs = {
|
|
30
|
-
className: 'first-class',
|
|
31
|
-
class: 'second-class',
|
|
32
|
-
};
|
|
33
|
-
addClassName(modifiableAttrs);
|
|
34
|
-
expect(modifiableAttrs).to.deep.equal({
|
|
35
|
-
className: 'first-class second-class',
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('should convert class attribute value to className when className is absent', () => {
|
|
40
|
-
const modifiableAttrs = {
|
|
41
|
-
class: 'second-class',
|
|
42
|
-
};
|
|
43
|
-
addClassName(modifiableAttrs);
|
|
44
|
-
expect(modifiableAttrs).to.deep.equal({
|
|
45
|
-
className: 'second-class',
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('should keep attributes unchanged when class is absent', () => {
|
|
50
|
-
const modifiableAttrs = {
|
|
51
|
-
className: 'first-class',
|
|
52
|
-
id: 'image',
|
|
53
|
-
};
|
|
54
|
-
addClassName(modifiableAttrs);
|
|
55
|
-
expect(modifiableAttrs).to.deep.equal({
|
|
56
|
-
className: 'first-class',
|
|
57
|
-
id: 'image',
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
describe('extractPath', () => {
|
|
63
|
-
it('should return root slash when params are undefined', () => {
|
|
64
|
-
const result = extractPath(undefined as unknown as Record<string, string | undefined>);
|
|
65
|
-
expect(result).to.equal('/');
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('should join path segments when path is an array', () => {
|
|
69
|
-
const result = extractPath({ path: ['about', 'team'] as unknown as string });
|
|
70
|
-
expect(result).to.equal('about/team');
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('should return path when path is a string', () => {
|
|
74
|
-
const result = extractPath({ path: 'about' });
|
|
75
|
-
expect(result).to.equal('about');
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('should return root slash when path is missing', () => {
|
|
79
|
-
const result = extractPath({});
|
|
80
|
-
expect(result).to.equal('/');
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
describe('removeLanguageFromPath', () => {
|
|
85
|
-
const languages = ['en', 'fr', 'de-DE'];
|
|
86
|
-
|
|
87
|
-
it('should remove a leading language segment', () => {
|
|
88
|
-
const result = removeLanguageFromPath('en/About', languages);
|
|
89
|
-
expect(result).to.equal('About');
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('should remove a language segment following a _site_ segment', () => {
|
|
93
|
-
const result = removeLanguageFromPath('_site_Basic/en/About', languages);
|
|
94
|
-
expect(result).to.equal('_site_Basic/About');
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('should match languages case-insensitively', () => {
|
|
98
|
-
const result = removeLanguageFromPath('_site_Basic/FR/About', languages);
|
|
99
|
-
expect(result).to.equal('_site_Basic/About');
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('should return root slash when path only contains a language segment', () => {
|
|
103
|
-
const result = removeLanguageFromPath('en', languages);
|
|
104
|
-
expect(result).to.equal('/');
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('should leave path unchanged when no supported language is found', () => {
|
|
108
|
-
const result = removeLanguageFromPath('es/About', languages);
|
|
109
|
-
expect(result).to.equal('es/About');
|
|
110
|
-
});
|
|
111
|
-
});
|