From ba85d468ec00ff113d5ff711fbf7d84e6b8beda5 Mon Sep 17 00:00:00 2001 From: Jose David Rodriguez Velasco Date: Mon, 1 Nov 2021 11:12:47 -0700 Subject: [PATCH] fix: remove .html file validation (#39) It may be that the component module is using the render method (importing its own html files) or that the component inherits from another component and does not overrides the template (headless actions) --- messages/create.json | 1 - .../force/lightning/lwc/test/create.ts | 5 ----- test/commands/lwc/test/create.test.ts | 18 ++++++++++++++++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/messages/create.json b/messages/create.json index 7cca652..b5b1862 100644 --- a/messages/create.json +++ b/messages/create.json @@ -7,6 +7,5 @@ "errorFileNotFound": "File not found: '%s'.", "errorFileNotJs": "File must be a JavaScript file. The '.js' extension was not found: '%s'.", "errorFileExists": "Test file already exists: '%s'.", - "errorHtmlFileNotFound": "No corresponding HTML file found for '%s'. This command only supports Lightning web components with corresponding HTML and JavaScript files in the same directory.", "logSuccess": "Test case successfully created: %s" } diff --git a/src/commands/force/lightning/lwc/test/create.ts b/src/commands/force/lightning/lwc/test/create.ts index a69a3cb..d678a6f 100644 --- a/src/commands/force/lightning/lwc/test/create.ts +++ b/src/commands/force/lightning/lwc/test/create.ts @@ -44,11 +44,6 @@ export default class Create extends SfdxCommand { throw new SfdxError(messages.getMessage('errorFileNotFound', [this.flags.filepath])); } - const htmlPath = modulePath.substring(0, modulePath.lastIndexOf('.')) + '.html'; - if (!fs.existsSync(htmlPath)) { - throw new SfdxError(messages.getMessage('errorHtmlFileNotFound', [this.flags.filepath])); - } - const bundlePath = path.dirname(modulePath); const testDirPath = path.join(bundlePath, testDirName); diff --git a/test/commands/lwc/test/create.test.ts b/test/commands/lwc/test/create.test.ts index fd32438..0360538 100644 --- a/test/commands/lwc/test/create.test.ts +++ b/test/commands/lwc/test/create.test.ts @@ -58,6 +58,24 @@ describe('force:lightning:lwc:test:create', () => { expect(writeFileSyncStub.args[0][0]).to.equal('/path/to/js/__tests__/foo.test.js'); }); + test + .do(() => { + stubMethod($$.SANDBOX, fs, 'existsSync') + .withArgs(sinon.match.in(['/path/to/js/foo.js'])) + .returns(true) + .withArgs('/path/to/js/__tests__/foo.test.js') + .returns(false); + (fs.existsSync as SinonStub).callThrough(); + stubMethod($$.SANDBOX, fs, 'mkdirSync'); + writeFileSyncStub = stubMethod($$.SANDBOX, fs, 'writeFileSync'); + }) + .stdout() + .withProject() + .command(['force:lightning:lwc:test:create', '-f', '/path/to/js/foo.js']) + .it('creates test file in __tests__ folder of component bundle when .html file is missing', ctx => { + expect(writeFileSyncStub.args[0][0]).to.equal('/path/to/js/__tests__/foo.test.js'); + }); + test .do(() => { stubMethod($$.SANDBOX, fs, 'existsSync')