Skip to content

Commit

Permalink
Add test for if/switch conditions
Browse files Browse the repository at this point in the history
These test for nested block expression with `return`s where we need to
add the profileEnd function in each of the branches to ensure we stop
the profiling no matter which branch is taken when the code gets
executed.
  • Loading branch information
kgrz committed Oct 17, 2017
1 parent a505dcc commit 9a5932f
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
39 changes: 39 additions & 0 deletions __snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,45 @@ const b = () => {
};"
`;

exports[`maintains indentation when for if blocks 1`] = `
"
const b = () => {
console.profile('b');
// profile
if (true) {
console.profileEnd();
return 12;
}
switch (true) {
case 'case1':
console.profileEnd();
return 'what';
case 'case 2':
{
console.profileEnd();
return 'where';
}
case 'case 3':
console.profileEnd();
return 'who';
default:
console.profileEnd();
return 'default';
}
console.profileEnd();
return 42;
};"
`;

exports[`maintains indentation when used with iterators 1`] = `
"
const b = () => {
Expand Down
29 changes: 29 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,32 @@ it('maintains indentation when used with iterators', () => {
expect(code).toMatchSnapshot();
});

it('maintains indentation when for if blocks', () => {
const example = `
const b = () => {
// profile
if (true) {
return 12;
}
switch (true) {
case 'case1':
return 'what';
case 'case 2': {
return 'where';
}
case 'case 3':
return 'who';
default:
return 'default'
}
return 42;
};
`;

const code = babel.transform(example, { plugins: [ plugin ] }).code;
expect(code).toMatchSnapshot();
});

0 comments on commit 9a5932f

Please sign in to comment.