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 "container is falsey" error when using code coverage #156

Merged
merged 9 commits into from Feb 11, 2021

Conversation

mdeanjones
Copy link

@mdeanjones
Copy link
Author

Node 6 does not like object spreads.

Copy link
Member

@rwjblue rwjblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this!

fixtures/istanbul-should-cover.js Outdated Show resolved Hide resolved
@mdeanjones
Copy link
Author

Ya, I had some misconceptions about how the Istanbul plugin was getting things done.

Comment on lines +427 to +429
// babel-plugin-istanbul won't run on <= Node 6
const majorVersion = parseInt(process.version.match(/^v(\d+)\./)[1], 10);
const runOrSkip = majorVersion > 6 ? it : it.skip;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one, thank you!

Comment on lines 439 to 444
expect(() => {
babel7.transformSync(source, {
filename: 'istanbul-should-cover.js',
plugins: [require('babel-plugin-istanbul'), Plugin],
});
}).toThrow(/Container is falsy/i);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you tweak this to something like:

Suggested change
expect(() => {
babel7.transformSync(source, {
filename: 'istanbul-should-cover.js',
plugins: [require('babel-plugin-istanbul'), Plugin],
});
}).toThrow(/Container is falsy/i);
expect(() => {
babel7.transformSync(source, {
filename: 'istanbul-should-cover.js',
plugins: [require('babel-plugin-istanbul'), Plugin],
});
}).toMatchInlineSnapshot();

Basically, we don't want it to throw...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make sure I'm tracking, the idea is to provide feedback that's a bit more useful than "it did/not throw"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, exactly. Basically expect().toThrow() is not what we want here, we want to say it does not throw (IOW, this PR should be failing not passing). Using .toMatchInlineSnapshot just lets us confirm that it emits something that we can visually verify "looks correct".

@mdeanjones
Copy link
Author

Poking some more, it looks like this is the root cause.

@mdeanjones
Copy link
Author

Standing on bigger shoulders than my own, this seems like a commonly accepted solution - istanbuljs/babel-plugin-istanbul#192

Don't know if it's the most efficient place to put it though.

@mdeanjones mdeanjones marked this pull request as draft December 4, 2020 18:02
src/index.js Outdated
@@ -165,6 +165,8 @@ module.exports = function (babel) {
])
);
} else {
path.scope.crawl();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I worry that doing this for every import declaration replacement is going to be quite costly. Now that you fully understand what is wrong, I wonder if we can avoid the re-crawl by detecting the specific failure scenario and handling it. 🤔

Thoughts @mdeanjones?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I opted for a "try, and try again" approach. It gets the job done, but does feel a bit... hacky.

…ber-modules-api-polyfill

� Conflicts:
�	__tests__/index-test.js
�	package.json
�	src/index.js
�	yarn.lock
@mdeanjones mdeanjones marked this pull request as ready for review February 11, 2021 12:06
@rwjblue rwjblue changed the title Failing test when used with babel-plugin-istanbul Fix "container is falsey" error when using code coverage Feb 11, 2021
@rwjblue rwjblue added the bug label Feb 11, 2021
@rwjblue
Copy link
Member

rwjblue commented Feb 11, 2021

Thank you @mdeanjones!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants