Skip to content

Commit 6f6c981

Browse files
committed
test(e2e): add adding .babelrc case
1 parent 64812f5 commit 6f6c981

File tree

2 files changed

+65
-0
lines changed
  • e2e-tests/development-runtime

2 files changed

+65
-0
lines changed

e2e-tests/development-runtime/cypress/integration/functionality/babelrc.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,57 @@ describe(`babelrc`, () => {
3535
.invoke(`text`)
3636
.should(`eq`, `babel-rc-edited`)
3737
})
38+
39+
it(`adding .babelrc`, () => {
40+
cy.visit(`/babelrc/add/`).waitForRouteChange()
41+
42+
cy.getTestElement(TEST_ELEMENT)
43+
.invoke(`text`)
44+
.should(`eq`, `babel-rc-test`)
45+
46+
const FILE_CONTENT = `
47+
{
48+
"plugins": [
49+
[
50+
"babel-plugin-search-and-replace",
51+
{
52+
"rules": [
53+
{
54+
"search": "babel-rc-test",
55+
"replace": "babel-rc-added",
56+
"searchTemplateStrings": true
57+
}
58+
59+
]
60+
}
61+
]
62+
],
63+
"presets": [
64+
"babel-preset-gatsby"
65+
]
66+
}
67+
`
68+
69+
cy.exec(
70+
`npm run update -- --file src/pages/babelrc/add/.babelrc --file-content '${JSON.stringify(
71+
FILE_CONTENT
72+
)}'`
73+
)
74+
75+
// babel-loader doesn't actually hot reloads itself when new .babelrc file is added
76+
// this is because it registers dependency only if file already exists
77+
// ( https://github.com/babel/babel-loader/blob/1669ac07ee1eed28a8e6fcacbf1c07ceb06fe053/src/index.js#L214-L216 )
78+
// so to test hot-reloading here we actually have to invalidate js file, which would recompile it and discover
79+
// new babelrc file
80+
cy.exec(
81+
`npm run update -- --file src/pages/babelrc/add/index.js --replacements "foo-bar:foo-bar" --exact`
82+
)
83+
84+
cy.waitForHmr()
85+
86+
cy.getTestElement(TEST_ELEMENT)
87+
.invoke(`text`)
88+
.should(`eq`, `babel-rc-added`)
89+
})
3890
})
3991
})
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from "react"
2+
3+
export default function BabelrcAdd() {
4+
return (
5+
<>
6+
<p>
7+
Code block below should contain <code>babel-rc-test</code> first and
8+
after .babelrc addition it should contain <code>babel-rc-added</code>
9+
</p>
10+
<pre data-testid="test-element">babel-rc-test</pre>
11+
</>
12+
)
13+
}

0 commit comments

Comments
 (0)