Skip to content

Commit 98f9570

Browse files
committed
Add an example illustrating ct with react + webpack
1 parent a037b4c commit 98f9570

File tree

10 files changed

+136
-0
lines changed

10 files changed

+136
-0
lines changed

examples/ct-react-ts/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { defineConfig } from "cypress";
2+
3+
import * as Webpack from "webpack";
4+
5+
import { devServer } from "@cypress/webpack-dev-server";
6+
7+
const webpackConfig = (
8+
cypressConfig: Cypress.PluginConfigOptions
9+
): Webpack.Configuration => {
10+
return {
11+
resolve: {
12+
extensions: [".js", ".ts", ".tsx"],
13+
},
14+
module: {
15+
rules: [
16+
{
17+
test: /\.tsx?$/,
18+
exclude: [/node_modules/],
19+
use: [
20+
{
21+
loader: "ts-loader",
22+
options: { transpileOnly: true },
23+
},
24+
],
25+
},
26+
{
27+
test: /\.feature$/,
28+
use: [
29+
{
30+
loader: "@badeball/cypress-cucumber-preprocessor/webpack",
31+
options: cypressConfig,
32+
},
33+
],
34+
},
35+
],
36+
},
37+
};
38+
};
39+
40+
export default defineConfig({
41+
component: {
42+
specPattern: "**/*.feature",
43+
supportFile: false,
44+
devServer(devServerConfig) {
45+
return devServer({
46+
...devServerConfig,
47+
framework: "react",
48+
webpackConfig: webpackConfig(devServerConfig.cypressConfig),
49+
});
50+
},
51+
},
52+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Feature: App
2+
Scenario: render
3+
Given I render the component
4+
Then I should see the text "Hello world!"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Given, Then } from "@badeball/cypress-cucumber-preprocessor";
2+
3+
import { mount } from 'cypress/react'
4+
5+
import App from "../../src/App";
6+
7+
Given("I render the component", () => {
8+
mount(<App />);
9+
});
10+
11+
Then("I should see the text {string}", (text: string) => {
12+
cy.contains(text).should("exist");
13+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
7+
<title>Components App</title>
8+
9+
</head>
10+
<body>
11+
12+
<div data-cy-root></div>
13+
</body>
14+
</html>

examples/ct-react-ts/package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"dependencies": {
3+
"@badeball/cypress-cucumber-preprocessor": "latest",
4+
"@cypress/webpack-dev-server": "latest",
5+
"cypress": "latest",
6+
"react": "17",
7+
"react-dom": "17",
8+
"react-scripts": "latest",
9+
"ts-loader": "latest"
10+
},
11+
"browserslist": {
12+
"production": [
13+
">0.2%",
14+
"not dead",
15+
"not op_mini all"
16+
],
17+
"development": [
18+
"last 1 chrome version",
19+
"last 1 firefox version",
20+
"last 1 safari version"
21+
]
22+
}
23+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { mount } from 'cypress/react'
2+
3+
import App from './App';
4+
5+
describe('App', () => {
6+
it('should render «Hello world!»', () => {
7+
mount(<App />);
8+
cy.contains("Hello world!").should("exist");
9+
});
10+
});

examples/ct-react-ts/src/App.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function App () {
2+
return <p>Hello world!</p>
3+
}

examples/ct-react-ts/tsconfig.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"compilerOptions": {
3+
"jsx": "react-jsx",
4+
"types": ["cypress"]
5+
}
6+
}

examples/readme.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
# Examples
22

3+
## E2E testing
4+
35
The examples illustrates using each bundler in each language flavor.
46

57
| | CJS | ESM | TS |
68
|------------|------------------------|------------------------|-----------------------|
79
| Browserify | [Link](browserify-cjs) | [Link](browserify-esm) | [Link](browserify-ts) |
810
| Esbuild | [Link](esbuild-cjs) | [Link](esbuild-esm) | [Link](esbuild-ts) |
911
| Webpack | [Link](webpack-cjs) | [Link](webpack-esm) | [Link](webpack-ts) |
12+
13+
## Component testing
14+
15+
Only a single example illustrating component testing exist so far.
16+
17+
| | CJS | ESM | TS |
18+
|-----------------|------------------------|------------------------|-----------------------|
19+
| React + Webpack | | | [Link](ct-react-ts) |

0 commit comments

Comments
 (0)