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
Copy file name to clipboardExpand all lines: docs/src/develop/README.md
+70-4Lines changed: 70 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -57,10 +57,76 @@ Github CLI is not supported yet with our Worldline account, so you need to use t
57
57
58
58
## 🧪 Exercise
59
59
60
-
::: warning TODO
61
-
#### Install Github Copilot on VSCode and generate tests for the following project repository
62
-
#### Use Copilot to refactor the following project repository
63
-
:::
60
+
### Install Github Copilot on VSCode
61
+
62
+
1. Install the [Github Copilot extension](https://marketplace.visualstudio.com/items?itemName=github.copilot) on your VSCode
63
+
2. Sign in with your Github account, if not already done
64
+
3. Create a new file and start typing a functionor a class, to see the suggestions provided by Copilot
65
+
66
+
### Generating unit tests
67
+
68
+
We"re going to use Github Copilot to generate unit tests for a simple JavaScript project repository.
69
+
70
+
To run the project and unit tests, you will need [NodeJs](https://nodejs.org/en/download/) installed on your machine.
71
+
72
+
1. Clone the following repository: [github.com/worldline/learning-ai-workspace-js](https://github.com/worldline/learning-ai-workspace-js)
73
+
2. Open the project in your VSCode
74
+
3. Open Github Copilot Chat by clicking on the Copilot icon in the bottom right corner of your VSCode
75
+
4. Ask Copilot to generate unit tests for the `index.js` file . You can also try the `/setupTests` command
76
+
5. Copilot may make several suggestions: choosing a testing framework, adding a `test` command to package.json, install new dependencies. Accept all its suggestions.
77
+
6. Try to run the generated tests. In case of trouble, use Copilot Chat to ask for help.
78
+
79
+
80
+
<details>
81
+
<summary>Solution</summary>
82
+
83
+
<p>Here we decided to go with supertest framework</p>
<p>Here is an example of how Copilot can help you fix a failing test:</p>
90
+
<img src="./images/fixTest.png" height="300" />
91
+
<img src="./images/fixTest2.png" height="300" />
92
+
93
+
</details>
94
+
95
+
### Refactoring
96
+
97
+
Now we are going to use Copilot to refactor a piece of code in the same project.
98
+
99
+
1. Open the `index.js` file in the project
100
+
2. Ask Copilot to add a feature in the GET /movies endpoint that allows filtering movies by director, based on a `director` query parameter.
101
+
3. Copilot will generate the code for you. Try to understand the changes it made and run the project to test the new feature.
102
+
4. Ask Copilot to complete the unit test in `index.test.js` to test getting movies filtered by director. It should generate more unit tests that check against one of the directors in the example data.
103
+
5. Now we're going to refactor the code to extract the filtering logic into a separate function. Select the parts of the code with the `.find()` and `.filter()` function calls and ask Copilot to extract them into a new function. Let Copilot suggest a name for these functions
104
+
6. Under the previous generated function, type `function filterMoviesByYear(`. Wait for Copilot to suggest you the rest of the functionsignature and functionbody. Accept the suggestion using the `Tab` key.
105
+
7. Ask Copilot again to allow filtering movies by a `year` query parameter. Copilot should use the `filterMoviesByYear`functionyou just created to implement this feature.
106
+
8. Open `index.test.js`. In the `GET /movies`test block, add a new assertion block by typing `it('should return movies filtered by year',`. Wait for Copilot to suggest you the rest of the tests. Review code to make sure it uses the ?year query parameter and checks correctly a date from the example data.
107
+
9. Run the tests to make sure everything is working as expected. Use Copilot to ask forhelpif needed.
0 commit comments