-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(e2e): add base babelrc support tests for dev and prod (#30644)
* test(e2e): add base babelrc support tests for dev and prod * test(e2e): add editing .babelrc case * test(e2e): add adding .babelrc case * test(e2e): add removing .babelrc case * maybe this command will work in circle?
- Loading branch information
Showing
15 changed files
with
297 additions
and
13 deletions.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
e2e-tests/development-runtime/cypress/integration/functionality/babelrc.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
const TEST_ELEMENT = `test-element` | ||
|
||
before(() => { | ||
cy.exec(`npm run reset`) | ||
}) | ||
|
||
after(() => { | ||
cy.exec(`npm run reset`) | ||
}) | ||
|
||
describe(`babelrc`, () => { | ||
it(`Applies .babelrc`, () => { | ||
cy.visit(`/babelrc/base/`).waitForRouteChange() | ||
|
||
cy.getTestElement(TEST_ELEMENT) | ||
.invoke(`text`) | ||
.should(`eq`, `babel-rc-is-used`) | ||
}) | ||
|
||
describe(`hot reload`, () => { | ||
it(`editing .babelrc`, () => { | ||
cy.visit(`/babelrc/edit/`).waitForRouteChange() | ||
|
||
cy.getTestElement(TEST_ELEMENT) | ||
.invoke(`text`) | ||
.should(`eq`, `babel-rc-initial`) | ||
|
||
cy.exec( | ||
`npm run update -- --file src/pages/babelrc/edit/.babelrc --replacements "babel-rc-initial:babel-rc-edited" --exact` | ||
) | ||
|
||
cy.waitForHmr() | ||
|
||
cy.getTestElement(TEST_ELEMENT) | ||
.invoke(`text`) | ||
.should(`eq`, `babel-rc-edited`) | ||
}) | ||
|
||
it(`adding .babelrc`, () => { | ||
cy.visit(`/babelrc/add/`).waitForRouteChange() | ||
|
||
cy.getTestElement(TEST_ELEMENT) | ||
.invoke(`text`) | ||
.should(`eq`, `babel-rc-test`) | ||
|
||
cy.exec( | ||
`npm run update -- --file src/pages/babelrc/add/.babelrc --file-source src/pages/babelrc/add/.babelrc-fixture` | ||
) | ||
|
||
// babel-loader doesn't actually hot reloads itself when new .babelrc file is added | ||
// this is because it registers dependency only if file already exists | ||
// ( https://github.com/babel/babel-loader/blob/1669ac07ee1eed28a8e6fcacbf1c07ceb06fe053/src/index.js#L214-L216 ) | ||
// so to test hot-reloading here we actually have to invalidate js file, which would recompile it and discover | ||
// new babelrc file | ||
cy.exec( | ||
`npm run update -- --file src/pages/babelrc/add/index.js --replacements "foo-bar:foo-bar" --exact` | ||
) | ||
|
||
cy.waitForHmr() | ||
|
||
cy.getTestElement(TEST_ELEMENT) | ||
.invoke(`text`) | ||
.should(`eq`, `babel-rc-added`) | ||
}) | ||
|
||
it(`removing .babelrc`, () => { | ||
cy.visit(`/babelrc/remove/`).waitForRouteChange() | ||
|
||
cy.getTestElement(TEST_ELEMENT) | ||
.invoke(`text`) | ||
.should(`eq`, `babel-rc-will-be-deleted`) | ||
|
||
cy.exec( | ||
`npm run update -- --file src/pages/babelrc/remove/.babelrc --delete` | ||
) | ||
|
||
// babel-loader doesn't actually hot reloads itself when .babelrc file is deleted | ||
// so to test hot-reloading here we actually have to invalidate js file, which would recompile it and discover | ||
// new babelrc file | ||
cy.exec( | ||
`npm run update -- --file src/pages/babelrc/remove/index.js --replacements "foo-bar:foo-bar" --exact` | ||
) | ||
|
||
cy.waitForHmr() | ||
|
||
cy.getTestElement(TEST_ELEMENT) | ||
.invoke(`text`) | ||
.should(`eq`, `babel-rc-test`) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
e2e-tests/development-runtime/src/pages/babelrc/add/.babelrc-fixture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"plugins": [ | ||
[ | ||
"babel-plugin-search-and-replace", | ||
{ | ||
"rules": [ | ||
{ | ||
"search": "babel-rc-test", | ||
"replace": "babel-rc-added", | ||
"searchTemplateStrings": true | ||
} | ||
|
||
] | ||
} | ||
] | ||
], | ||
"presets": [ | ||
"babel-preset-gatsby" | ||
] | ||
} |
13 changes: 13 additions & 0 deletions
13
e2e-tests/development-runtime/src/pages/babelrc/add/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from "react" | ||
|
||
export default function BabelrcAdd() { | ||
return ( | ||
<> | ||
<p> | ||
Code block below should contain <code>babel-rc-test</code> first and | ||
after .babelrc addition it should contain <code>babel-rc-added</code> | ||
</p> | ||
<pre data-testid="test-element">babel-rc-test</pre> | ||
</> | ||
) | ||
} |
20 changes: 20 additions & 0 deletions
20
e2e-tests/development-runtime/src/pages/babelrc/base/.babelrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"plugins": [ | ||
[ | ||
"babel-plugin-search-and-replace", | ||
{ | ||
"rules": [ | ||
{ | ||
"search": "babel-rc-test", | ||
"replace": "babel-rc-is-used", | ||
"searchTemplateStrings": true | ||
} | ||
|
||
] | ||
} | ||
] | ||
], | ||
"presets": [ | ||
"babel-preset-gatsby" | ||
] | ||
} |
13 changes: 13 additions & 0 deletions
13
e2e-tests/development-runtime/src/pages/babelrc/base/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from "react" | ||
|
||
export default function BabelrcBase() { | ||
return ( | ||
<> | ||
<p> | ||
Code block below should contain <code>babel-rc-is-used</code> when | ||
compiled | ||
</p> | ||
<pre data-testid="test-element">babel-rc-test</pre> | ||
</> | ||
) | ||
} |
20 changes: 20 additions & 0 deletions
20
e2e-tests/development-runtime/src/pages/babelrc/edit/.babelrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"plugins": [ | ||
[ | ||
"babel-plugin-search-and-replace", | ||
{ | ||
"rules": [ | ||
{ | ||
"search": "babel-rc-test", | ||
"replace": "babel-rc-initial", | ||
"searchTemplateStrings": true | ||
} | ||
|
||
] | ||
} | ||
] | ||
], | ||
"presets": [ | ||
"babel-preset-gatsby" | ||
] | ||
} |
13 changes: 13 additions & 0 deletions
13
e2e-tests/development-runtime/src/pages/babelrc/edit/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from "react" | ||
|
||
export default function BabelrcEdit() { | ||
return ( | ||
<> | ||
<p> | ||
Code block below should contain <code>babel-rc-initial</code> first and | ||
after edit it should contain <code>babel-rc-edited</code> | ||
</p> | ||
<pre data-testid="test-element">babel-rc-test</pre> | ||
</> | ||
) | ||
} |
20 changes: 20 additions & 0 deletions
20
e2e-tests/development-runtime/src/pages/babelrc/remove/.babelrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"plugins": [ | ||
[ | ||
"babel-plugin-search-and-replace", | ||
{ | ||
"rules": [ | ||
{ | ||
"search": "babel-rc-test", | ||
"replace": "babel-rc-will-be-deleted", | ||
"searchTemplateStrings": true | ||
} | ||
|
||
] | ||
} | ||
] | ||
], | ||
"presets": [ | ||
"babel-preset-gatsby" | ||
] | ||
} |
13 changes: 13 additions & 0 deletions
13
e2e-tests/development-runtime/src/pages/babelrc/remove/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from "react" | ||
|
||
export default function BabelrcRemove() { | ||
return ( | ||
<> | ||
<p> | ||
Code block below should contain <code>babel-rc-will-be-deleted</code>{" "} | ||
first and after removal it should contain <code>babel-rc-test</code> | ||
</p> | ||
<pre data-testid="test-element">babel-rc-test</pre> | ||
</> | ||
) | ||
} |
11 changes: 11 additions & 0 deletions
11
e2e-tests/production-runtime/cypress/integration/babelrc.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const TEST_ELEMENT = `test-element` | ||
|
||
describe(`babelrc`, () => { | ||
it(`Applies .babelrc`, () => { | ||
cy.visit(`/babelrc/base/`).waitForRouteChange() | ||
|
||
cy.getTestElement(TEST_ELEMENT) | ||
.invoke(`text`) | ||
.should(`eq`, `babel-rc-is-used`) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
e2e-tests/production-runtime/src/pages/babelrc/base/.babelrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"plugins": [ | ||
[ | ||
"babel-plugin-search-and-replace", | ||
{ | ||
"rules": [ | ||
{ | ||
"search": "babel-rc-test", | ||
"replace": "babel-rc-is-used", | ||
"searchTemplateStrings": true | ||
} | ||
|
||
] | ||
} | ||
] | ||
], | ||
"presets": [ | ||
"babel-preset-gatsby" | ||
] | ||
} |
13 changes: 13 additions & 0 deletions
13
e2e-tests/production-runtime/src/pages/babelrc/base/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from "react" | ||
|
||
export default function BabelrcBase() { | ||
return ( | ||
<> | ||
<p> | ||
Code block below should contain <code>babel-rc-is-used</code> when | ||
compiled | ||
</p> | ||
<pre data-testid="test-element">babel-rc-test</pre> | ||
</> | ||
) | ||
} |