File tree Expand file tree Collapse file tree 7 files changed +93
-26
lines changed
Expand file tree Collapse file tree 7 files changed +93
-26
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,11 @@ const path = require("path");
1212 * @returns {boolean } returns true if path is "Absolute Path"-like
1313 */
1414const looksLikeAbsolutePath = maybeAbsolutePath => {
15+ if ( / ^ \/ .* \/ $ / . test ( maybeAbsolutePath ) ) {
16+ // this 'path' is actually a regexp generated by dynamic requires.
17+ // Don't treat it as an absolute path.
18+ return false ;
19+ }
1520 return / ^ (?: [ a - z ] : \\ | \/ ) / i. test ( maybeAbsolutePath ) ;
1621} ;
1722
Original file line number Diff line number Diff line change 1+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+ exports [` ConfigTestCases records issue-2991 exported tests should write relative paths to records 1` ] = `
4+ "{
5+ \\" modules\\ " : {
6+ \\" byIdentifier\\ " : {
7+ \\"external \\\\\\"path\\\\\\" \\ " : 0 ,
8+ \\"external \\\\\\"fs\\\\\\" \\ " : 1 ,
9+ \\" ignored pkgs/somepackage/foo\\ " : 2 ,
10+ \\" test.js\\ " : 3
11+ },
12+ \\" usedIds\\ " : {
13+ \\" 0\\ " : 0 ,
14+ \\" 1\\ " : 1 ,
15+ \\" 2\\ " : 2 ,
16+ \\" 3\\ " : 3
17+ }
18+ },
19+ \\" chunks\\ " : {
20+ \\" byName\\ " : {
21+ \\" main\\ " : 0
22+ },
23+ \\" bySource\\ " : {},
24+ \\" usedIds\\ " : [
25+ 0
26+ ]
27+ }
28+ } "
29+ ` ;
30+
31+ exports [` ConfigTestCases records issue-7339 exported tests should write relative dynamic-require paths to records 1` ] = `
32+ "{
33+ \\" modules\\ " : {
34+ \\" byIdentifier\\ " : {
35+ \\" dependencies/foo.js\\ " : 0 ,
36+ \\" dependencies/bar.js\\ " : 1 ,
37+ \\"external \\\\\\"path\\\\\\" \\ " : 2 ,
38+ \\"external \\\\\\"fs\\\\\\" \\ " : 3 ,
39+ \\" dependencies sync /^\\\\\\\\ .\\\\\\\\ /.*$/\\ " : 4 ,
40+ \\" test.js\\ " : 5
41+ },
42+ \\" usedIds\\ " : {
43+ \\" 0\\ " : 0 ,
44+ \\" 1\\ " : 1 ,
45+ \\" 2\\ " : 2 ,
46+ \\" 3\\ " : 3 ,
47+ \\" 4\\ " : 4 ,
48+ \\" 5\\ " : 5
49+ }
50+ },
51+ \\" chunks\\ " : {
52+ \\" byName\\ " : {
53+ \\" main\\ " : 0
54+ },
55+ \\" bySource\\ " : {},
56+ \\" usedIds\\ " : [
57+ 0
58+ ]
59+ }
60+ } "
61+ ` ;
Original file line number Diff line number Diff line change 11try {
22 require ( "pkgs/somepackage/foo" ) ;
3- } catch ( e ) { }
3+ } catch ( e ) { }
44
55it ( "should write relative paths to records" , function ( ) {
66 var fs = require ( "fs" ) ;
77 var path = require ( "path" ) ;
88 var content = fs . readFileSync ( path . join ( __dirname , "records.json" ) , "utf-8" ) ;
9- expect ( content ) . toEqual ( `{
10- "modules": {
11- "byIdentifier": {
12- "external \\"path\\"": 0,
13- "external \\"fs\\"": 1,
14- "ignored pkgs/somepackage/foo": 2,
15- "test.js": 3
16- },
17- "usedIds": {
18- "0": 0,
19- "1": 1,
20- "2": 2,
21- "3": 3
22- }
23- },
24- "chunks": {
25- "byName": {
26- "main": 0
27- },
28- "bySource": {},
29- "usedIds": [
30- 0
31- ]
32- }
33- }` ) ;
9+ expect ( content ) . toMatchSnapshot ( ) ;
3410} ) ;
Original file line number Diff line number Diff line change 1+ module . exports = "Bar"
Original file line number Diff line number Diff line change 1+ module . exports = "Foo"
Original file line number Diff line number Diff line change 1+ function loadDependency ( dep ) {
2+ require ( "./dependencies/" + dep ) ;
3+ }
4+
5+ it ( "should write relative dynamic-require paths to records" , function ( ) {
6+ var fs = require ( "fs" ) ;
7+ var path = require ( "path" ) ;
8+ var content = fs . readFileSync ( path . join ( __dirname , "records.json" ) , "utf-8" ) ;
9+ expect ( content ) . toMatchSnapshot ( ) ;
10+ } ) ;
Original file line number Diff line number Diff line change 1+ var path = require ( "path" ) ;
2+
3+ module . exports = {
4+ entry : "./test" ,
5+ recordsOutputPath : path . resolve (
6+ __dirname ,
7+ "../../../js/config/records/issue-7339/records.json"
8+ ) ,
9+ target : "node" ,
10+ node : {
11+ __dirname : false
12+ }
13+ } ;
You can’t perform that action at this time.
0 commit comments