Skip to content

Commit d6cb456

Browse files
fix: add NUT testing LWC bug (#70)
* fix: add NUT testing LWC bug * fix: update LWC creation step, fix compilation
1 parent 74feea9 commit d6cb456

File tree

6 files changed

+42
-3
lines changed

6 files changed

+42
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{
2+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<template> </template>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { LightningElement } from 'lwc';
2+
3+
export default class Mycomponent extends LightningElement {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>51.0</apiVersion>
4+
<isExposed>false</isExposed>
5+
</LightningComponentBundle>

test/nuts/nutshell.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import * as path from 'path';
1111
import * as os from 'os';
12-
import { copyFile } from 'fs/promises';
1312
import * as fg from 'fast-glob';
1413
import { exec } from 'shelljs';
1514
import { TestSession, execCmd } from '@salesforce/cli-plugins-testkit';
@@ -149,6 +148,15 @@ export class Nutshell extends AsyncCreatable<Nutshell.Options> {
149148
return this.execute('force:apex:class:create', options);
150149
}
151150

151+
/**
152+
* Create a Lightning Web Component
153+
*/
154+
public async createLWC(
155+
options: Partial<Nutshell.CommandOpts> = {}
156+
): Promise<Result<{ created: string[]; outputDir: string }>> {
157+
return this.execute('force:lightning:component:create', options);
158+
}
159+
152160
/**
153161
* Installs a package into the scratch org. This method uses shelljs instead of testkit because
154162
* we can't add plugin-package as a dev plugin yet.
@@ -332,10 +340,10 @@ export class Nutshell extends AsyncCreatable<Nutshell.Options> {
332340
const src = path.join(this.testMetadataFolder, file);
333341
this.debug(`addTestFiles: ${src} -> ${dest}`);
334342
try {
335-
await copyFile(src, dest);
343+
fs.copyFileSync(src, dest);
336344
} catch {
337345
await fs.mkdirp(path.dirname(dest));
338-
await copyFile(src, dest);
346+
fs.copyFileSync(src, dest);
339347
}
340348
}
341349
await this.trackFiles(this.testMetadataFiles);

test/nuts/seeds/retrieve.seed.ts

+20
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,26 @@ context('Retrieve NUTs [name: %REPO_NAME%] [exec: %EXECUTABLE%]', () => {
5757
});
5858
}
5959

60+
it('should ensure that -meta.xml file belongs to the .js not .css', async () => {
61+
// this will fail with toolbelt powered sfdx, but should pass with SDRL powered sfdx
62+
/**
63+
* NUT covering a specific bug in toolbelt
64+
* 1. create LWC and CSS component (mycomponent)
65+
* 2. deploy LWC
66+
* 3. delete LWC locally
67+
* 4. retrieve with -m LightningComponentBundle:mycomponent
68+
* the -meta.xml file would be associated with the .css file, not the .js file
69+
*/
70+
const lwcPath = path.join('force-app', 'main', 'default', 'lwc');
71+
// deploy the LWC
72+
await nutshell.deploy({ args: '--sourcepath force-app' });
73+
// delete the LWC locally
74+
await nutshell.deleteGlobs([lwcPath]);
75+
await nutshell.retrieve({ args: '--metadata LightningComponentBundle:mycomponent' });
76+
// ensure that the mycomponent.js-meta.xml file exists
77+
await nutshell.expect.fileToExist(`${path.join(lwcPath, 'mycomponent.js-meta.xml')}`);
78+
});
79+
6080
it('should throw an error if the metadata is not valid', async () => {
6181
const retrieve = await nutshell.retrieve({ args: '--metadata DOES_NOT_EXIST', exitCode: 1 });
6282
nutshell.expect.errorToHaveName(retrieve, 'UnsupportedType');

0 commit comments

Comments
 (0)