Skip to content

Commit

Permalink
Issue 8547: side effect import deps extracted
Browse files Browse the repository at this point in the history
ed4edd8 -> red
965a24c -> green
c4bbbba -> Refinement
  • Loading branch information
astigefb committed Jul 10, 2019
1 parent a501718 commit eca3234
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -15,6 +15,7 @@

### Fixes

- `[jest-cli]` Detect side-effect only imports when running `--onlyChanged` or `--changedSince` ([#8670](https://github.com/facebook/jest/pull/8670))
- `[jest-cli]` Allow `--maxWorkers` to work with % input again ([#8565](https://github.com/facebook/jest/pull/8565))
- `[babel-plugin-jest-hoist]` Expand list of whitelisted globals in global mocks ([#8429](https://github.com/facebook/jest/pull/8429)
- `[jest-core]` Make watch plugin initialization errors look nice ([#8422](https://github.com/facebook/jest/pull/8422))
Expand Down
Expand Up @@ -17,6 +17,7 @@ describe('dependencyExtractor', () => {
// require('ignore-line-comment');
/*
* import a from 'ignore-block-comment';
* import './ignore-block-comment';
* require('ignore-block-comment');
*/
`;
Expand Down Expand Up @@ -67,6 +68,23 @@ describe('dependencyExtractor', () => {
expect(extract(code)).toEqual(new Set(['dep1', 'dep2', 'dep3', 'dep4']));
});

// https://github.com/facebook/jest/issues/8547
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Import_a_module_for_its_side_effects_only
it('should extract dependencies from side-effect only `import` statements', () => {
const code = `
// Good
import './side-effect-dep1';
import 'side-effect-dep2';
// Bad
import ./inv1;
import inv2
`;
expect(extract(code)).toEqual(
new Set(['./side-effect-dep1', 'side-effect-dep2']),
);
});

it('should not extract dependencies from `import type/typeof` statements', () => {
const code = `
// Bad
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-haste-map/src/lib/dependencyExtractor.ts
Expand Up @@ -54,7 +54,7 @@ const REQUIRE_OR_DYNAMIC_IMPORT_RE = createRegExp(

const IMPORT_OR_EXPORT_RE = createRegExp(
[
'\\b(?:import|export)\\s+(?!type(?:of)?\\s+)[^\'"]+\\s+from\\s+',
'\\b(?:import|export)\\s+(?!type(?:of)?\\s+)(?:[^\'"]+\\s+from\\s+)?',
CAPTURE_STRING_LITERAL(1),
],
'g',
Expand Down

0 comments on commit eca3234

Please sign in to comment.