Skip to content

Commit

Permalink
fix: add NUT testing LWC bug (#70)
Browse files Browse the repository at this point in the history
* fix: add NUT testing LWC bug

* fix: update LWC creation step, fix compilation
  • Loading branch information
WillieRuemmele authored Apr 29, 2021
1 parent 74feea9 commit d6cb456
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<template> </template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { LightningElement } from 'lwc';

export default class Mycomponent extends LightningElement {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>51.0</apiVersion>
<isExposed>false</isExposed>
</LightningComponentBundle>
14 changes: 11 additions & 3 deletions test/nuts/nutshell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

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

/**
* Create a Lightning Web Component
*/
public async createLWC(
options: Partial<Nutshell.CommandOpts> = {}
): Promise<Result<{ created: string[]; outputDir: string }>> {
return this.execute('force:lightning:component:create', options);
}

/**
* Installs a package into the scratch org. This method uses shelljs instead of testkit because
* we can't add plugin-package as a dev plugin yet.
Expand Down Expand Up @@ -332,10 +340,10 @@ export class Nutshell extends AsyncCreatable<Nutshell.Options> {
const src = path.join(this.testMetadataFolder, file);
this.debug(`addTestFiles: ${src} -> ${dest}`);
try {
await copyFile(src, dest);
fs.copyFileSync(src, dest);
} catch {
await fs.mkdirp(path.dirname(dest));
await copyFile(src, dest);
fs.copyFileSync(src, dest);
}
}
await this.trackFiles(this.testMetadataFiles);
Expand Down
20 changes: 20 additions & 0 deletions test/nuts/seeds/retrieve.seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,26 @@ context('Retrieve NUTs [name: %REPO_NAME%] [exec: %EXECUTABLE%]', () => {
});
}

it('should ensure that -meta.xml file belongs to the .js not .css', async () => {
// this will fail with toolbelt powered sfdx, but should pass with SDRL powered sfdx
/**
* NUT covering a specific bug in toolbelt
* 1. create LWC and CSS component (mycomponent)
* 2. deploy LWC
* 3. delete LWC locally
* 4. retrieve with -m LightningComponentBundle:mycomponent
* the -meta.xml file would be associated with the .css file, not the .js file
*/
const lwcPath = path.join('force-app', 'main', 'default', 'lwc');
// deploy the LWC
await nutshell.deploy({ args: '--sourcepath force-app' });
// delete the LWC locally
await nutshell.deleteGlobs([lwcPath]);
await nutshell.retrieve({ args: '--metadata LightningComponentBundle:mycomponent' });
// ensure that the mycomponent.js-meta.xml file exists
await nutshell.expect.fileToExist(`${path.join(lwcPath, 'mycomponent.js-meta.xml')}`);
});

it('should throw an error if the metadata is not valid', async () => {
const retrieve = await nutshell.retrieve({ args: '--metadata DOES_NOT_EXIST', exitCode: 1 });
nutshell.expect.errorToHaveName(retrieve, 'UnsupportedType');
Expand Down

0 comments on commit d6cb456

Please sign in to comment.