Skip to content

Commit

Permalink
fix: remove .html file validation (#39)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
jodarove committed Nov 1, 2021
1 parent e75d023 commit ba85d46
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
1 change: 0 additions & 1 deletion messages/create.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
5 changes: 0 additions & 5 deletions src/commands/force/lightning/lwc/test/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
18 changes: 18 additions & 0 deletions test/commands/lwc/test/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit ba85d46

Please sign in to comment.