Skip to content

Commit a4357bb

Browse files
committed
test: added nuts for webapp
1 parent 872de98 commit a4357bb

File tree

16 files changed

+549
-0
lines changed

16 files changed

+549
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# WebApp DigitalExperienceBundle NUT Tests
2+
3+
This directory contains NUT (Non-Unit Tests) for testing web_app DigitalExperienceBundle deployments with path-based fullNames.
4+
5+
## Test Files
6+
7+
### 1. `webapp.nut.ts`
8+
9+
Basic deployment and retrieval tests for webapp bundles.
10+
11+
**What it tests**:
12+
13+
- Deploy webapp bundle without "not found in local project" warnings
14+
- Path-based fullNames for web_app files (e.g., `web_app/WebApp/src/App.js`)
15+
- Retrieve webapp bundle with path-based fullNames
16+
- .forceignore pattern matching for webapp files
17+
18+
## Test Project Structure
19+
20+
The test project includes:
21+
22+
```
23+
force-app/main/default/digitalExperiences/web_app/WebApp/
24+
├── webapp.json
25+
├── public/
26+
│ ├── index.html
27+
│ └── images/
28+
│ ├── icon.png
29+
│ ├── photo.jpg
30+
│ └── logo.svg
31+
└── src/
32+
├── App.css
33+
├── App.js
34+
├── index.css
35+
└── index.js
36+
```
37+
38+
## Running Tests
39+
40+
Run all webapp NUT tests:
41+
42+
```bash
43+
yarn test:nuts:deb-webapp
44+
```
45+
46+
Run individual tests:
47+
48+
```bash
49+
yarn mocha test/nuts/digitalExperienceBundleWithWebapps/webapp.nut.ts
50+
```
51+
52+
## Technical Details
53+
54+
### FullName Format
55+
56+
Web_app files use path-based fullNames:
57+
58+
```
59+
web_app/WebApp/src/App.js
60+
└──────┘└─────┘└────────┘
61+
baseType bundle relative path
62+
```
63+
64+
## Related Files
65+
66+
- **Implementation**: `/src/resolve/adapters/digitalExperienceSourceAdapter.ts`
67+
- **Deploy Logic**: `/src/client/deployMessages.ts`
68+
- **Path Name Util**: `/src/client/utils.ts` (`computeWebAppPathName`)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2025, Salesforce, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { join } from 'node:path';
18+
import { TestSessionOptions } from '@salesforce/cli-plugins-testkit/lib/testSession.js';
19+
import { registry } from '@salesforce/source-deploy-retrieve';
20+
import { assert } from 'chai';
21+
22+
export const SOURCE_BASE_RELATIVE_PATH = join('force-app', 'main', 'default');
23+
export const DEB_WEBAPP_NUTS_PATH = join(process.cwd(), 'test', 'nuts', 'digitalExperienceBundleWithWebapps');
24+
25+
export const TYPES = {
26+
DEB: registry.types.digitalexperiencebundle,
27+
} as const;
28+
29+
export const DIR_NAMES = {
30+
PROJECT: 'project',
31+
DIGITAL_EXPERIENCES: TYPES.DEB.directoryName,
32+
WEB_APP: 'web_app',
33+
WEBAPP_NAME: 'WebApp',
34+
} as const;
35+
36+
assert(DIR_NAMES.DIGITAL_EXPERIENCES);
37+
38+
export const WEBAPPS_RELATIVE_PATH = join(SOURCE_BASE_RELATIVE_PATH, DIR_NAMES.DIGITAL_EXPERIENCES, DIR_NAMES.WEB_APP);
39+
export const WEBAPP_RELATIVE_PATH = join(WEBAPPS_RELATIVE_PATH, DIR_NAMES.WEBAPP_NAME);
40+
41+
export const FULL_NAMES = {
42+
WEBAPP: `${DIR_NAMES.WEB_APP}/${DIR_NAMES.WEBAPP_NAME}`,
43+
} as const;
44+
45+
export const METADATA = {
46+
WEBAPP: `${TYPES.DEB.name}:${FULL_NAMES.WEBAPP}`,
47+
ALL_DEBS: TYPES.DEB.name,
48+
};
49+
50+
export const TEST_SESSION_OPTIONS: TestSessionOptions = {
51+
project: {
52+
sourceDir: join(DEB_WEBAPP_NUTS_PATH, DIR_NAMES.PROJECT),
53+
},
54+
devhubAuthStrategy: 'AUTO',
55+
scratchOrgs: [
56+
{
57+
setDefault: true,
58+
config: join('config', 'project-scratch-def.json'),
59+
},
60+
],
61+
};
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2025, Salesforce, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { join } from 'node:path';
18+
import * as fs from 'node:fs';
19+
import { expect } from 'chai';
20+
import { WEBAPP_RELATIVE_PATH } from './constants.js';
21+
22+
/**
23+
* Delete local webapp source
24+
*/
25+
export async function deleteLocalSource(sourceRelativePath: string, projectDir: string): Promise<void> {
26+
const fullPath = join(projectDir, sourceRelativePath);
27+
if (fs.existsSync(fullPath)) {
28+
await fs.promises.rm(fullPath, { recursive: true });
29+
await fs.promises.mkdir(fullPath, { recursive: true });
30+
}
31+
}
32+
33+
/**
34+
* Convert metadata string to array format for CLI commands
35+
*/
36+
export const metadataToArray = (metadata: string): string => `--metadata ${metadata.split(',').join(' --metadata ')}`;
37+
38+
/**
39+
* Verify webapp files exist locally after retrieve
40+
*/
41+
export function assertWebAppFilesExist(projectDir: string): void {
42+
const webappPath = join(projectDir, WEBAPP_RELATIVE_PATH);
43+
expect(fs.existsSync(webappPath), `WebApp directory should exist at ${webappPath}`).to.be.true;
44+
expect(fs.existsSync(join(webappPath, 'webapp.json')), 'webapp.json should exist').to.be.true;
45+
expect(fs.existsSync(join(webappPath, 'src', 'App.js')), 'src/App.js should exist').to.be.true;
46+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Salesforce DX Project: Next Steps
2+
3+
Now that you've created a Salesforce DX project, what's next? Here are some documentation resources to get you started.
4+
5+
## How Do You Plan to Deploy Your Changes?
6+
7+
Do you want to deploy a set of changes, or create a self-contained application? Choose
8+
a [development model](https://developer.salesforce.com/tools/vscode/en/user-guide/development-models).
9+
10+
## Configure Your Salesforce DX Project
11+
12+
The `sfdx-project.json` file contains useful configuration information for your project.
13+
See [Salesforce DX Project Configuration](https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_ws_config.htm)
14+
in the _Salesforce DX Developer Guide_ for details about this file.
15+
16+
## Read All About It
17+
18+
- [Salesforce Extensions Documentation](https://developer.salesforce.com/tools/vscode/)
19+
- [Salesforce CLI Setup Guide](https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_setup_intro.htm)
20+
- [Salesforce DX Developer Guide](https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_intro.htm)
21+
- [Salesforce CLI Command Reference](https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference.htm)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"orgName": "DEB Webapp NUT Org",
3+
"edition": "Developer",
4+
"features": ["EnableSetPasswordInApi", "Communities"],
5+
"settings": {
6+
"lightningExperienceSettings": {
7+
"enableS1DesktopEnabled": true
8+
},
9+
"mobileSettings": {
10+
"enableS1EncryptedStoragePref2": false
11+
},
12+
"experienceBundleSettings": {
13+
"enableExperienceBundleMetadata": true
14+
},
15+
"communitiesSettings": {
16+
"enableNetworksEnabled": true
17+
}
18+
}
19+
}
70 Bytes
Loading
Lines changed: 4 additions & 0 deletions
Loading
631 Bytes
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1" />
6+
<meta name="theme-color" content="#000000" />
7+
<meta name="description" content="Web App 2 - React Application" />
8+
<title>WebApp2</title>
9+
</head>
10+
<body>
11+
<noscript>You need to enable JavaScript to run this app.</noscript>
12+
<div id="root"></div>
13+
</body>
14+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.App {
2+
text-align: center;
3+
}
4+
5+
.App-header {
6+
background-color: #282c34;
7+
min-height: 100vh;
8+
display: flex;
9+
flex-direction: column;
10+
align-items: center;
11+
justify-content: center;
12+
font-size: calc(10px + 2vmin);
13+
color: white;
14+
}
15+
16+
.card {
17+
padding: 2rem;
18+
background-color: #1a1d23;
19+
border-radius: 8px;
20+
margin-top: 2rem;
21+
max-width: 600px;
22+
}
23+
24+
.card h2 {
25+
margin-top: 0;
26+
color: #61dafb;
27+
}
28+
29+
code {
30+
background-color: #1a1d23;
31+
padding: 0.2rem 0.4rem;
32+
border-radius: 4px;
33+
font-family: 'Courier New', monospace;
34+
color: #61dafb;
35+
}

0 commit comments

Comments
 (0)