File tree Expand file tree Collapse file tree 4 files changed +8
-5
lines changed
packages/jest-haste-map/src Expand file tree Collapse file tree 4 files changed +8
-5
lines changed Original file line number Diff line number Diff line change 22
33### Features
44
5+ * ` [jest-haste-map] ` Support extracting dynamic ` import ` s
6+ ([ #5883 ] ( https://github.com/facebook/jest/pull/5883 ) )
57* ` [expect] ` Improve output format for mismatchedArgs in mock/spy calls.
68 ([ #5846 ] ( https://github.com/facebook/jest/pull/5846 ) )
79* ` [jest-cli] ` Add support for using ` --coverage ` in combination with watch
Original file line number Diff line number Diff line change @@ -14,7 +14,6 @@ import crypto from 'crypto';
1414import EventEmitter from 'events' ;
1515import getMockName from './get_mock_name' ;
1616import getPlatformExtension from './lib/get_platform_extension' ;
17- // eslint-disable-next-line import/no-duplicates
1817import H from './constants' ;
1918import HasteFS from './haste_fs' ;
2019import HasteModuleMap from './module_map' ;
@@ -41,8 +40,7 @@ import type {
4140 MockData ,
4241} from 'types/HasteMap' ;
4342
44- // eslint-disable-next-line import/no-duplicates
45- import typeof HType from './constants' ;
43+ type HType = typeof H ;
4644
4745type Options = {
4846 cacheDirectory ?: string ,
Original file line number Diff line number Diff line change @@ -15,9 +15,10 @@ it('extracts both requires and imports from code', () => {
1515 const code = `
1616 import module1 from 'module1';
1717 const module2 = require('module2');
18+ import('module3').then(module3 => {})';
1819 ` ;
1920
20- expect ( extractRequires ( code ) ) . toEqual ( [ 'module1' , 'module2' ] ) ;
21+ expect ( extractRequires ( code ) ) . toEqual ( [ 'module1' , 'module2' , 'module3' ] ) ;
2122} ) ;
2223
2324it ( 'extracts requires in order' , ( ) => {
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ const blockCommentRe = /\/\*[^]*?\*\//g;
1111const lineCommentRe = / \/ \/ .* / g;
1212
1313const replacePatterns = {
14+ DYNAMIC_IMPORT_RE : / (?: ^ | [ ^ . ] \s * ) ( \b i m p o r t \s * ?\( \s * ?) ( [ ` ' " ] ) ( [ ^ ` ' " ] + ) ( \2\s * ?\) ) / g,
1415 EXPORT_RE : / ( \b e x p o r t \s + (? ! t y p e ) (?: [ ^ ' " ] + \s + f r o m \s + ) ? ?) ( [ ' " ] ) ( [ ^ ' " ] + ) ( \2) / g,
1516 IMPORT_RE : / ( \b i m p o r t \s + (? ! t y p e ) (?: [ ^ ' " ] + \s + f r o m \s + ) ? ?) ( [ ' " ] ) ( [ ^ ' " ] + ) ( \2) / g,
1617 REQUIRE_EXTENSIONS_PATTERN : / (?: ^ | [ ^ . ] \s * ) ( \b (?: r e q u i r e \s * ?\. \s * ?(?: r e q u i r e A c t u a l | r e q u i r e M o c k ) | j e s t \s * ?\. \s * ?(?: r e q u i r e A c t u a l | r e q u i r e M o c k | g e n M o c k F r o m M o d u l e ) ) \s * ?\( \s * ?) ( [ ` ' " ] ) ( [ ^ ` ' " ] + ) ( \2\s * ?\) ) / g,
@@ -30,7 +31,8 @@ export default function extractRequires(code: string): Array<string> {
3031 . replace ( replacePatterns . EXPORT_RE , addDependency )
3132 . replace ( replacePatterns . IMPORT_RE , addDependency )
3233 . replace ( replacePatterns . REQUIRE_EXTENSIONS_PATTERN , addDependency )
33- . replace ( replacePatterns . REQUIRE_RE , addDependency ) ;
34+ . replace ( replacePatterns . REQUIRE_RE , addDependency )
35+ . replace ( replacePatterns . DYNAMIC_IMPORT_RE , addDependency ) ;
3436
3537 return Array . from ( dependencies ) ;
3638}
You can’t perform that action at this time.
0 commit comments