-
Notifications
You must be signed in to change notification settings - Fork 170
Expand file tree
/
Copy pathwebApplicationsSourceAdapter.test.ts
More file actions
205 lines (186 loc) · 7.47 KB
/
Copy pathwebApplicationsSourceAdapter.test.ts
File metadata and controls
205 lines (186 loc) · 7.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
* Copyright 2026, Salesforce, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { join } from 'node:path';
import { assert, expect } from 'chai';
import { Messages, SfError } from '@salesforce/core';
import { ForceIgnore, RegistryAccess, SourceComponent, VirtualDirectory, VirtualTreeContainer, registry } from '../../../src';
import { WebApplicationsSourceAdapter } from '../../../src/resolve/adapters';
import { RegistryTestUtil } from '../registryTestUtil';
Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/source-deploy-retrieve', 'sdr');
describe('WebApplicationsSourceAdapter', () => {
const BASE_PATH = join('path', 'to', registry.types.webapplication.directoryName);
const APP_NAME = 'Zenith';
const APP_PATH = join(BASE_PATH, APP_NAME);
const META_FILE = join(APP_PATH, `${APP_NAME}.webapplication-meta.xml`);
const JSON_FILE = join(APP_PATH, 'webapplication.json');
const CONTENT_FILE = join(APP_PATH, 'src', 'index.html');
const registryAccess = new RegistryAccess();
const forceIgnore = new ForceIgnore();
const tree = VirtualTreeContainer.fromFilePaths([META_FILE, JSON_FILE, CONTENT_FILE]);
const adapter = new WebApplicationsSourceAdapter(registry.types.webapplication, registryAccess, forceIgnore, tree);
const expectedComponent = new SourceComponent(
{
name: APP_NAME,
type: registry.types.webapplication,
content: APP_PATH,
xml: META_FILE,
},
tree,
forceIgnore
);
it('should return a SourceComponent for the metadata xml', () => {
expect(adapter.getComponent(META_FILE)).to.deep.equal(expectedComponent);
});
it('should return a SourceComponent for the descriptor json', () => {
expect(adapter.getComponent(JSON_FILE)).to.deep.equal(expectedComponent);
});
it('should return a SourceComponent for any content file in the app', () => {
expect(adapter.getComponent(CONTENT_FILE)).to.deep.equal(expectedComponent);
});
it('should return a SourceComponent for the app directory', () => {
expect(adapter.getComponent(APP_PATH)).to.deep.equal(expectedComponent);
});
it('should throw ExpectedSourceFilesError if metadata xml is missing', () => {
const noXmlTree = VirtualTreeContainer.fromFilePaths([JSON_FILE, CONTENT_FILE]);
const noXmlAdapter = new WebApplicationsSourceAdapter(
registry.types.webapplication,
registryAccess,
forceIgnore,
noXmlTree
);
const expectedXmlPath = join(APP_PATH, `${APP_NAME}.webapplication-meta.xml`);
assert.throws(
() => noXmlAdapter.getComponent(APP_PATH),
SfError,
messages.getMessage('error_expected_source_files', [expectedXmlPath, registry.types.webapplication.name])
);
});
it('should throw ExpectedSourceFilesError if content files are missing', () => {
const noContentTree = VirtualTreeContainer.fromFilePaths([META_FILE, JSON_FILE]);
const noContentAdapter = new WebApplicationsSourceAdapter(
registry.types.webapplication,
registryAccess,
forceIgnore,
noContentTree
);
assert.throws(
() => noContentAdapter.getComponent(APP_PATH),
SfError,
messages.getMessage('error_expected_source_files', [APP_PATH, registry.types.webapplication.name])
);
});
it('should throw ExpectedSourceFilesError if webapplication.json is missing', () => {
const noJsonTree = VirtualTreeContainer.fromFilePaths([META_FILE, CONTENT_FILE]);
const noJsonAdapter = new WebApplicationsSourceAdapter(
registry.types.webapplication,
registryAccess,
forceIgnore,
noJsonTree
);
const expectedJsonPath = join(APP_PATH, 'webapplication.json');
assert.throws(
() => noJsonAdapter.getComponent(APP_PATH),
SfError,
messages.getMessage('error_expected_source_files', [expectedJsonPath, registry.types.webapplication.name])
);
});
it('should allow missing webapplication.json when resolving metadata', () => {
const metadataTree = VirtualTreeContainer.fromFilePaths([META_FILE]);
const metadataAdapter = new WebApplicationsSourceAdapter(
registry.types.webapplication,
registryAccess,
forceIgnore,
metadataTree
);
const expectedMetadataComponent = new SourceComponent(
{
name: APP_NAME,
type: registry.types.webapplication,
content: APP_PATH,
xml: META_FILE,
},
metadataTree,
forceIgnore
);
expect(metadataAdapter.getComponent(META_FILE, false)).to.deep.equal(expectedMetadataComponent);
});
it('should throw noSourceIgnore if webapplication.json is forceignored', () => {
const testUtil = new RegistryTestUtil();
const forceIgnore = testUtil.stubForceIgnore({
seed: APP_PATH,
deny: [JSON_FILE],
});
const ignoredAdapter = new WebApplicationsSourceAdapter(
registry.types.webapplication,
registryAccess,
forceIgnore,
tree
);
assert.throws(
() => ignoredAdapter.getComponent(APP_PATH),
SfError,
messages.getMessage('noSourceIgnore', [registry.types.webapplication.name, JSON_FILE])
);
testUtil.restore();
});
describe('app name case', () => {
const buildAdapterWithAppName = (appName: string) => {
const appPath = join(BASE_PATH, appName);
const metaFile = join(appPath, `${appName}.webapplication-meta.xml`);
const config = { outputDir: 'src', routing: { trailingSlash: 'auto', fallback: '/index.html' } };
const vfs: VirtualDirectory[] = [
{
dirPath: appPath,
children: [
`${appName}.webapplication-meta.xml`,
{ name: 'webapplication.json', data: Buffer.from(JSON.stringify(config)) },
'src',
],
},
{ dirPath: join(appPath, 'src'), children: ['index.html'] },
];
const t = new VirtualTreeContainer(vfs);
return {
adapter: new WebApplicationsSourceAdapter(registry.types.webapplication, registryAccess, forceIgnore, t),
appPath,
metaFile,
};
};
it('should preserve mixed-case app name (MyApp)', () => {
const { adapter, appPath, metaFile } = buildAdapterWithAppName('MyApp');
const comp = adapter.getComponent(appPath);
expect(comp).to.not.be.undefined;
expect(comp!.name).to.equal('MyApp');
expect(comp!.fullName).to.equal('MyApp');
expect(comp!.xml).to.equal(metaFile);
});
it('should preserve lowercase app name (myapp)', () => {
const { adapter, appPath } = buildAdapterWithAppName('myapp');
const comp = adapter.getComponent(appPath);
expect(comp).to.not.be.undefined;
expect(comp!.name).to.equal('myapp');
expect(comp!.fullName).to.equal('myapp');
});
it('should preserve uppercase app name (MYAPP)', () => {
const { adapter, appPath } = buildAdapterWithAppName('MYAPP');
const comp = adapter.getComponent(appPath);
expect(comp).to.not.be.undefined;
expect(comp!.name).to.equal('MYAPP');
expect(comp!.fullName).to.equal('MYAPP');
});
});
});