File tree Expand file tree Collapse file tree 4 files changed +76
-8
lines changed
e2e-tests/development-runtime
cypress/integration/functionality Expand file tree Collapse file tree 4 files changed +76
-8
lines changed Original file line number Diff line number Diff line change @@ -87,5 +87,30 @@ describe(`babelrc`, () => {
8787 . invoke ( `text` )
8888 . should ( `eq` , `babel-rc-added` )
8989 } )
90+
91+ it ( `removing .babelrc` , ( ) => {
92+ cy . visit ( `/babelrc/remove/` ) . waitForRouteChange ( )
93+
94+ cy . getTestElement ( TEST_ELEMENT )
95+ . invoke ( `text` )
96+ . should ( `eq` , `babel-rc-will-be-deleted` )
97+
98+ cy . exec (
99+ `npm run update -- --file src/pages/babelrc/remove/.babelrc --delete`
100+ )
101+
102+ // babel-loader doesn't actually hot reloads itself when .babelrc file is deleted
103+ // so to test hot-reloading here we actually have to invalidate js file, which would recompile it and discover
104+ // new babelrc file
105+ cy . exec (
106+ `npm run update -- --file src/pages/babelrc/remove/index.js --replacements "foo-bar:foo-bar" --exact`
107+ )
108+
109+ cy . waitForHmr ( )
110+
111+ cy . getTestElement ( TEST_ELEMENT )
112+ . invoke ( `text` )
113+ . should ( `eq` , `babel-rc-test` )
114+ } )
90115 } )
91116} )
Original file line number Diff line number Diff line change @@ -17,6 +17,10 @@ const args = yargs
1717 default : false ,
1818 type : `boolean` ,
1919 } )
20+ . option ( `delete` , {
21+ default : false ,
22+ type : `boolean` ,
23+ } )
2024 . option ( `fileContent` , {
2125 default : JSON . stringify (
2226 `
@@ -72,15 +76,21 @@ async function update() {
7276 history . set ( filePath , exists ? file : false )
7377 }
7478
75- const contents = replacements . reduce ( ( replaced , pair ) => {
76- const [ key , value ] = pair . split ( `:` )
77- return replaced . replace (
78- args . exact ? key : new RegExp ( `%${ key } %` , `g` ) ,
79- value
80- )
81- } , file )
79+ if ( args . delete ) {
80+ if ( exists ) {
81+ await fs . remove ( filePath )
82+ }
83+ } else {
84+ const contents = replacements . reduce ( ( replaced , pair ) => {
85+ const [ key , value ] = pair . split ( `:` )
86+ return replaced . replace (
87+ args . exact ? key : new RegExp ( `%${ key } %` , `g` ) ,
88+ value
89+ )
90+ } , file )
8291
83- await fs . writeFile ( filePath , contents , `utf8` )
92+ await fs . writeFile ( filePath , contents , `utf8` )
93+ }
8494
8595 await writeHistory ( history )
8696}
Original file line number Diff line number Diff line change 1+ {
2+ "plugins" : [
3+ [
4+ " babel-plugin-search-and-replace" ,
5+ {
6+ "rules" : [
7+ {
8+ "search" : " babel-rc-test" ,
9+ "replace" : " babel-rc-will-be-deleted" ,
10+ "searchTemplateStrings" : true
11+ }
12+
13+ ]
14+ }
15+ ]
16+ ],
17+ "presets" : [
18+ " babel-preset-gatsby"
19+ ]
20+ }
Original file line number Diff line number Diff line change 1+ import React from "react"
2+
3+ export default function BabelrcRemove ( ) {
4+ return (
5+ < >
6+ < p >
7+ Code block below should contain < code > babel-rc-will-be-deleted</ code > { " " }
8+ first and after removal it should contain < code > babel-rc-test</ code >
9+ </ p >
10+ < pre data-testid = "test-element" > babel-rc-test</ pre >
11+ </ >
12+ )
13+ }
You can’t perform that action at this time.
0 commit comments