You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> Here are a few reasons for creating a separate `e2e` folder especially for cypress:
27
29
* Creating a separate directory or `e2e` makes it easier to isolate its `package.json` dependencies from the rest of your project. This results in less dependency conflicts.
28
30
* Testing frameworks have a habit of polluting the global namespace with stuff like `describe``it``expect`. It is best to keep the e2e `tsconfig.json` and `node_modules` in this special `e2e` folder to prevent global type definition conflicts.
29
31
30
-
Setup TypeScript `tsconfig.json`e.g.
32
+
Add a few scripts to the `e2e/package.json`file:
31
33
32
34
```json
33
-
{
34
-
"compilerOptions": {
35
-
"strict": true,
36
-
"sourceMap": true,
37
-
"module": "commonjs",
38
-
"target": "es5",
39
-
"lib": [
40
-
"dom",
41
-
"es6"
42
-
],
43
-
"types": ["cypress"],
44
-
"jsx": "react",
45
-
"experimentalDecorators": true
35
+
"scripts": {
36
+
"cypress:open": "cypress open",
37
+
"cypress:run": "cypress run"
46
38
},
47
-
"compileOnSave": false
48
-
}
49
39
```
50
40
51
-
Do a first dry run of cypress to prime the cypress folder structure. The Cypress IDE will open. You can close it after you see the welcome message.
41
+
Write your first test under `cypress/integration/basic.ts`:
52
42
53
-
```sh
54
-
npx cypress open
55
-
```
56
-
57
-
Setup cypress for transpiling typescript by editing `e2e/cypress/plugins/index.js` to match the following:
58
-
59
-
```js
60
-
constwp=require('@cypress/webpack-preprocessor')
61
-
module.exports= (on) => {
62
-
constoptions= {
63
-
webpackOptions: {
64
-
resolve: {
65
-
extensions: [".ts", ".tsx", ".js"]
66
-
},
67
-
module: {
68
-
rules: [
69
-
{
70
-
test:/\.tsx?$/,
71
-
loader:"ts-loader",
72
-
options: { transpileOnly:true }
73
-
}
74
-
]
75
-
}
76
-
},
77
-
}
78
-
on('file:preprocessor', wp(options))
79
-
}
43
+
```ts
44
+
it('should perform basic google search', () => {
45
+
cy.visit('https://google.com');
46
+
cy.get('[name="q"]')
47
+
.type('subscribe')
48
+
.type('{enter}');
49
+
});
80
50
```
81
51
82
-
83
-
Optionally add a few scripts to the `e2e/package.json` file:
84
-
85
-
```json
86
-
"scripts": {
87
-
"cypress:open": "cypress open",
88
-
"cypress:run": "cypress run"
89
-
},
90
-
```
52
+
Now run `npm run cypress:open` during development and `npm run cypress:run` on your build server 🌹
0 commit comments