Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: removes .html file validation #39

Merged
merged 1 commit into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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