@@ -13,64 +13,64 @@ const quoteMeta = str => {
1313 return str . replace ( / [ - [ \] \\ / { } ( ) * + ? . ^ $ | ] / g, "\\$&" ) ;
1414} ;
1515
16- describe ( "Defaults" , ( ) => {
17- const cwd = process . cwd ( ) ;
18- const cwdRegExp = new RegExp (
19- `${ quoteMeta ( cwd ) } ((?:\\\\)?(?:[a-zA-Z.\\-_]+\\\\)*)` ,
20- "g"
21- ) ;
22- const escapedCwd = JSON . stringify ( cwd ) . slice ( 1 , - 1 ) ;
23- const escapedCwdRegExp = new RegExp (
24- `${ quoteMeta ( escapedCwd ) } ((?:\\\\\\\\)?(?:[a-zA-Z.\\-_]+\\\\\\\\)*)` ,
25- "g"
26- ) ;
27- const normalize = str => {
28- if ( cwd . startsWith ( "/" ) ) {
29- str = str . replace ( new RegExp ( quoteMeta ( cwd ) , "g" ) , "<cwd>" ) ;
30- } else {
31- str = str . replace ( cwdRegExp , ( m , g ) => `<cwd>${ g . replace ( / \\ / g, "/" ) } ` ) ;
32- str = str . replace (
33- escapedCwdRegExp ,
34- ( m , g ) => `<cwd>${ g . replace ( / \\ \\ / g, "/" ) } `
35- ) ;
36- }
37- str = str . replace ( / @ @ - \d + , \d + \+ \d + , \d + @ @ / g, "@@ ... @@" ) ;
38- return str ;
39- } ;
16+ const cwd = process . cwd ( ) ;
17+ const cwdRegExp = new RegExp (
18+ `${ quoteMeta ( cwd ) } ((?:\\\\)?(?:[a-zA-Z.\\-_]+\\\\)*)` ,
19+ "g"
20+ ) ;
21+ const escapedCwd = JSON . stringify ( cwd ) . slice ( 1 , - 1 ) ;
22+ const escapedCwdRegExp = new RegExp (
23+ `${ quoteMeta ( escapedCwd ) } ((?:\\\\\\\\)?(?:[a-zA-Z.\\-_]+\\\\\\\\)*)` ,
24+ "g"
25+ ) ;
26+ const normalize = str => {
27+ if ( cwd . startsWith ( "/" ) ) {
28+ str = str . replace ( new RegExp ( quoteMeta ( cwd ) , "g" ) , "<cwd>" ) ;
29+ } else {
30+ str = str . replace ( cwdRegExp , ( m , g ) => `<cwd>${ g . replace ( / \\ / g, "/" ) } ` ) ;
31+ str = str . replace (
32+ escapedCwdRegExp ,
33+ ( m , g ) => `<cwd>${ g . replace ( / \\ \\ / g, "/" ) } `
34+ ) ;
35+ }
36+ str = str . replace ( / @ @ - \d + , \d + \+ \d + , \d + @ @ / g, "@@ ... @@" ) ;
37+ return str ;
38+ } ;
4039
41- class Diff {
42- constructor ( value ) {
43- this . value = value ;
44- }
40+ class Diff {
41+ constructor ( value ) {
42+ this . value = value ;
4543 }
44+ }
4645
47- expect . addSnapshotSerializer ( {
48- test ( value ) {
49- return value instanceof Diff ;
50- } ,
51- print ( received ) {
52- return normalize ( received . value ) ;
53- }
54- } ) ;
46+ expect . addSnapshotSerializer ( {
47+ test ( value ) {
48+ return value instanceof Diff ;
49+ } ,
50+ print ( received ) {
51+ return normalize ( received . value ) ;
52+ }
53+ } ) ;
5554
56- expect . addSnapshotSerializer ( {
57- test ( value ) {
58- return typeof value === "string" ;
59- } ,
60- print ( received ) {
61- return JSON . stringify ( normalize ( received ) ) ;
62- }
63- } ) ;
55+ expect . addSnapshotSerializer ( {
56+ test ( value ) {
57+ return typeof value === "string" ;
58+ } ,
59+ print ( received ) {
60+ return JSON . stringify ( normalize ( received ) ) ;
61+ }
62+ } ) ;
6463
65- const getDefaultConfig = config => {
66- const { applyWebpackOptionsDefaults, getNormalizedWebpackOptions } =
67- require ( ".." ) . config ;
68- config = getNormalizedWebpackOptions ( config ) ;
69- applyWebpackOptionsDefaults ( config ) ;
70- process . chdir ( cwd ) ;
71- return config ;
72- } ;
64+ const getDefaultConfig = config => {
65+ const { applyWebpackOptionsDefaults, getNormalizedWebpackOptions } =
66+ require ( ".." ) . config ;
67+ config = getNormalizedWebpackOptions ( config ) ;
68+ applyWebpackOptionsDefaults ( config ) ;
69+ process . chdir ( cwd ) ;
70+ return config ;
71+ } ;
7372
73+ describe ( "snapshots" , ( ) => {
7474 const baseConfig = getDefaultConfig ( { mode : "none" } ) ;
7575
7676 it ( "should have the correct base config" , ( ) => {
@@ -2018,3 +2018,27 @@ describe("Defaults", () => {
20182018 ` )
20192019 ) ;
20202020} ) ;
2021+
2022+ it ( "should result in the same target options for same target" , ( ) => {
2023+ const inlineTarget = getDefaultConfig ( { target : "node12.17" } ) ;
2024+ const browserslistTarget = getDefaultConfig ( {
2025+ target : "browserslist: node 12.17"
2026+ } ) ;
2027+ const diff = stripAnsi (
2028+ jestDiff ( inlineTarget , browserslistTarget , {
2029+ expand : false ,
2030+ contextLines : 0
2031+ } )
2032+ ) ;
2033+
2034+ expect ( inlineTarget . output . environment . module ) . toBe ( true ) ;
2035+ expect ( inlineTarget . output . environment . dynamicImport ) . toBe ( true ) ;
2036+ expect ( new Diff ( diff ) ) . toMatchInlineSnapshot ( `
2037+ - Expected
2038+ + Received
2039+
2040+ @@ ... @@
2041+ - "target": "node12.17",
2042+ + "target": "browserslist: node 12.17",
2043+ ` ) ;
2044+ } ) ;
0 commit comments