test: refactor fixtures
This commit is contained in:
11
tests/fixtures/README.md
vendored
Normal file
11
tests/fixtures/README.md
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
# Generating diffs
|
||||
|
||||
1. Instruct ChatGPT with the following command:
|
||||
```
|
||||
I want you to act as a git cli
|
||||
I will give you the type of content and you will generate a random git diff based on that
|
||||
```
|
||||
|
||||
2. Insert the type of change
|
||||
|
||||
ChatGPT will generate a fictional git diff based on the type of change you inserted.
|
||||
18
tests/fixtures/chore.diff
vendored
Normal file
18
tests/fixtures/chore.diff
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
diff --git a/package.json b/package.json
|
||||
index 2a7398e..6b2a3f0 100644
|
||||
--- a/package.json
|
||||
+++ b/package.json
|
||||
@@ -3,7 +3,7 @@
|
||||
"version": "1.0.0",
|
||||
"description": "A sample project",
|
||||
"main": "index.js",
|
||||
- "scripts": {
|
||||
+ "scripts": {
|
||||
"start": "node index.js",
|
||||
"test": "mocha",
|
||||
- "lint": "eslint ."
|
||||
+ "lint": "eslint .",
|
||||
+ "clean": "rm -rf node_modules && npm install"
|
||||
},
|
||||
"dependencies": {
|
||||
"express": "^4.17.1",
|
||||
34
tests/fixtures/code-refactoring.diff
vendored
Normal file
34
tests/fixtures/code-refactoring.diff
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
diff --git a/old_example.ts b/new_example.ts
|
||||
index 1234567..abcdefg 100644
|
||||
--- a/old_example.ts
|
||||
+++ b/new_example.ts
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
-import { Component, OnInit } from '@angular/core';
|
||||
+import { Component } from '@angular/core';
|
||||
|
||||
-@Component({
|
||||
- selector: 'app-example',
|
||||
- templateUrl: './example.component.html',
|
||||
- styleUrls: ['./example.component.css']
|
||||
-})
|
||||
-export class ExampleComponent implements OnInit {
|
||||
- message: string;
|
||||
+@Component({
|
||||
+ selector: 'app-improved-example',
|
||||
+ templateUrl: './improved-example.component.html',
|
||||
+ styleUrls: ['./improved-example.component.css']
|
||||
+})
|
||||
+export class ImprovedExampleComponent {
|
||||
+ private _message: string;
|
||||
|
||||
- ngOnInit() {
|
||||
- this.message = 'Hello, world!';
|
||||
+ constructor() {
|
||||
+ this._message = 'Hello, world!';
|
||||
}
|
||||
|
||||
+ get message(): string {
|
||||
+ return this._message;
|
||||
+ }
|
||||
}
|
||||
28
tests/fixtures/code-style.diff
vendored
Normal file
28
tests/fixtures/code-style.diff
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
diff --git a/src/app.js b/src/app.js
|
||||
index 8741c37..91b2e74 100644
|
||||
--- a/src/app.js
|
||||
+++ b/src/app.js
|
||||
@@ -10,12 +10,12 @@ app.use(express.json());
|
||||
// Routes
|
||||
app.get('/', (req, res) => {
|
||||
- res.send('Welcome to the API!');
|
||||
+ res.send('Welcome to the API!');
|
||||
});
|
||||
|
||||
app.post('/users', (req, res) => {
|
||||
- const user = createUser(req.body);
|
||||
- res.status(201).send(user);
|
||||
+ const user = createUser(req.body);
|
||||
+ res.status(201).send(user);
|
||||
});
|
||||
|
||||
app.get('/users/:id', (req, res) => {
|
||||
@@ -27,7 +27,7 @@ app.get('/users/:id', (req, res) => {
|
||||
if (user) {
|
||||
res.send(user);
|
||||
} else {
|
||||
- res.status(404).send('User not found');
|
||||
+ res.status(404).send('User not found');
|
||||
}
|
||||
});
|
||||
|
||||
30
tests/fixtures/continous-integration.diff
vendored
Normal file
30
tests/fixtures/continous-integration.diff
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
|
||||
new file mode 100644
|
||||
index 0000000..b6e5789
|
||||
--- /dev/null
|
||||
+++ b/.github/workflows/ci.yml
|
||||
@@ -0,0 +1,16 @@
|
||||
+name: Continuous Integration
|
||||
+
|
||||
+on:
|
||||
+ push:
|
||||
+ branches:
|
||||
+ - main
|
||||
+ pull_request:
|
||||
+ branches:
|
||||
+ - main
|
||||
+
|
||||
+jobs:
|
||||
+ build-and-test:
|
||||
+ runs-on: ubuntu-latest
|
||||
+ steps:
|
||||
+ - name: Checkout repository
|
||||
+ uses: actions/checkout@v2
|
||||
+ - name: Set up Node.js
|
||||
+ uses: actions/setup-node@v2
|
||||
+ with:
|
||||
+ node-version: '16'
|
||||
+ - name: Install dependencies
|
||||
+ run: npm ci
|
||||
+ - name: Run tests
|
||||
+ run: npm test
|
||||
27
tests/fixtures/deprecate-feature.diff
vendored
Normal file
27
tests/fixtures/deprecate-feature.diff
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
diff --git a/old_feature.py b/old_feature.py
|
||||
index 1234567..abcdefg 100644
|
||||
--- a/old_feature.py
|
||||
+++ b/old_feature.py
|
||||
@@ -1,7 +1,9 @@
|
||||
import warnings
|
||||
|
||||
|
||||
class OldFeature:
|
||||
+ def __init__(self):
|
||||
+ warnings.warn("OldFeature is deprecated and will be removed in the next release. Please use NewFeature instead.", DeprecationWarning)
|
||||
|
||||
def do_something(self):
|
||||
print("Doing something with the old feature...")
|
||||
diff --git a/new_feature.py b/new_feature.py
|
||||
new file mode 100644
|
||||
index 0000000..1111111
|
||||
--- /dev/null
|
||||
+++ b/new_feature.py
|
||||
@@ -0,0 +1,7 @@
|
||||
+class NewFeature:
|
||||
+ def __init__(self):
|
||||
+ print("Initializing the new feature...")
|
||||
+
|
||||
+ def do_something(self):
|
||||
+ print("Doing something with the new feature...")
|
||||
+
|
||||
30
tests/fixtures/documentation-changes.diff
vendored
Normal file
30
tests/fixtures/documentation-changes.diff
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
diff --git a/README.md b/README.md
|
||||
index a0c3e1b..9d1b6f8 100644
|
||||
--- a/README.md
|
||||
+++ b/README.md
|
||||
@@ -1,6 +1,11 @@
|
||||
# My Awesome Project
|
||||
|
||||
+## Overview
|
||||
+
|
||||
+My Awesome Project is a web application that allows users to manage their tasks and projects in a simple and intuitive way. The project is built with React and Node.js and uses MongoDB for data storage.
|
||||
+
|
||||
## Installation
|
||||
|
||||
+To install and run My Awesome Project, follow these steps:
|
||||
+
|
||||
1. Clone the repository: `git clone https://github.com/username/my-awesome-project.git`
|
||||
2. Install dependencies: `npm install`
|
||||
3. Start the development server: `npm start`
|
||||
@@ -13,6 +18,11 @@ To install and run My Awesome Project, follow these steps:
|
||||
## Usage
|
||||
|
||||
To use My Awesome Project, follow these steps:
|
||||
+
|
||||
+1. Open your web browser and navigate to `http://localhost:3000`
|
||||
+2. Sign up for a new account or log in to an existing one
|
||||
+3. Create a new task or project and start managing your work!
|
||||
+
|
||||
## Contributing
|
||||
|
||||
We welcome contributions from anyone and everyone. To contribute to My Awesome Project, follow these steps:
|
||||
14
tests/fixtures/fix-nullpointer-exception.diff
vendored
Normal file
14
tests/fixtures/fix-nullpointer-exception.diff
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
diff --git a/src/main/java/com/example/MyClass.java b/src/main/java/com/example/MyClass.java
|
||||
index e7d8f38..caab7f1 100644
|
||||
--- a/src/main/java/com/example/MyClass.java
|
||||
+++ b/src/main/java/com/example/MyClass.java
|
||||
@@ -23,7 +23,10 @@ public class MyClass {
|
||||
public void processItems(List<Item> items) {
|
||||
for (Item item : items) {
|
||||
- if (item.getValue().equalsIgnoreCase("example")) {
|
||||
+ // Fixing NullPointerException by adding a null check
|
||||
+ String itemValue = item.getValue();
|
||||
+ if (itemValue != null && itemValue.equalsIgnoreCase("example")) {
|
||||
processExampleItem(item);
|
||||
}
|
||||
}
|
||||
21
tests/fixtures/github-action-build-pipeline.diff
vendored
Normal file
21
tests/fixtures/github-action-build-pipeline.diff
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
|
||||
index 1d07d31..085eb64 100644
|
||||
--- a/.github/workflows/build.yml
|
||||
+++ b/.github/workflows/build.yml
|
||||
@@ -10,6 +10,8 @@ jobs:
|
||||
- uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 12.x
|
||||
+ - name: Install dependencies
|
||||
+ run: npm install
|
||||
- name: Build and test
|
||||
run: |
|
||||
npm run build
|
||||
@@ -22,3 +24,7 @@ jobs:
|
||||
if: always()
|
||||
uses: actions/upload-artifact@v1
|
||||
with:
|
||||
+ name: Build artifact
|
||||
+ path: build
|
||||
+ - name: Deploy to production
|
||||
+ uses: some-third-party/deploy-action@v1
|
||||
47
tests/fixtures/new-feature.diff
vendored
Normal file
47
tests/fixtures/new-feature.diff
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
diff --git a/src/features/newFeature.js b/src/features/newFeature.js
|
||||
new file mode 100644
|
||||
index 0000000..b6e5789
|
||||
--- /dev/null
|
||||
+++ b/src/features/newFeature.js
|
||||
@@ -0,0 +1,18 @@
|
||||
+/**
|
||||
+ * New feature: Calculates the factorial of a given number.
|
||||
+ * @param {number} n - The input number.
|
||||
+ * @returns {number} - The factorial of the input number.
|
||||
+ */
|
||||
+function factorial(n) {
|
||||
+ if (n === 0 || n === 1) {
|
||||
+ return 1;
|
||||
+ }
|
||||
+ return n * factorial(n - 1);
|
||||
+}
|
||||
+
|
||||
+module.exports = {
|
||||
+ factorial,
|
||||
+};
|
||||
+
|
||||
diff --git a/src/app.js b/src/app.js
|
||||
index 8741c37..91b2e74 100644
|
||||
--- a/src/app.js
|
||||
+++ b/src/app.js
|
||||
@@ -2,6 +2,7 @@
|
||||
const express = require('express');
|
||||
const bodyParser = require('body-parser');
|
||||
const userRoutes = require('./routes/userRoutes');
|
||||
+const { factorial } = require('./features/newFeature');
|
||||
|
||||
const app = express();
|
||||
app.use(bodyParser.json());
|
||||
@@ -21,6 +22,12 @@
|
||||
res.send('Welcome to the API!');
|
||||
});
|
||||
|
||||
+app.get('/factorial/:number', (req, res) => {
|
||||
+ const number = parseInt(req.params.number, 10);
|
||||
+ const result = factorial(number);
|
||||
+ res.send(`Factorial of ${number} is ${result}`);
|
||||
+});
|
||||
+
|
||||
// Other routes...
|
||||
|
||||
module.exports = app;
|
||||
26
tests/fixtures/performance-improvement.diff
vendored
Normal file
26
tests/fixtures/performance-improvement.diff
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
diff --git a/src/loop.js b/src/loop.js
|
||||
index 1d45a2b..8c52e81 100644
|
||||
--- a/src/loop.js
|
||||
+++ b/src/loop.js
|
||||
@@ -5,14 +5,14 @@ const items = generateItems(100000);
|
||||
function processData(items) {
|
||||
let sum = 0;
|
||||
|
||||
- for (let i = 0; i < items.length; i++) {
|
||||
- const item = items[i];
|
||||
- if (item.isValid()) {
|
||||
- sum += item.value;
|
||||
- }
|
||||
+ for (const item of items) {
|
||||
+ if (item.isValid()) sum += item.value;
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
const startTime = Date.now();
|
||||
-const result = processData(items);
|
||||
+const result = processData(items); // Improved loop iteration
|
||||
const endTime = Date.now();
|
||||
|
||||
console.log(`Result: ${result}, Time: ${endTime - startTime} ms`);
|
||||
27
tests/fixtures/remove-feature.diff
vendored
Normal file
27
tests/fixtures/remove-feature.diff
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
diff --git a/Controllers/FeatureController.cs b/Controllers/FeatureController.cs
|
||||
index 8a3b7c1..3e29f9a 100644
|
||||
--- a/Controllers/FeatureController.cs
|
||||
+++ b/Controllers/FeatureController.cs
|
||||
@@ -1,16 +1,7 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MyWebApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class FeatureController : ControllerBase
|
||||
{
|
||||
- [HttpGet("old-feature")]
|
||||
- public ActionResult<string> GetOldFeature()
|
||||
- {
|
||||
- return "This is the removed old feature.";
|
||||
- }
|
||||
-
|
||||
[HttpGet("new-feature")]
|
||||
public ActionResult<string> GetNewFeature()
|
||||
{
|
||||
return "This is the new feature.";
|
||||
}
|
||||
}
|
||||
}
|
||||
22
tests/fixtures/testing-react-application.diff
vendored
Normal file
22
tests/fixtures/testing-react-application.diff
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
diff --git a/src/components/MyComponent.test.js b/src/components/MyComponent.test.js
|
||||
index 37eabf2..976c6bf 100644
|
||||
--- a/src/components/MyComponent.test.js
|
||||
+++ b/src/components/MyComponent.test.js
|
||||
@@ -10,6 +10,7 @@ describe("MyComponent", () => {
|
||||
});
|
||||
|
||||
it("renders the component correctly", () => {
|
||||
+ const props = { name: "John Doe", age: 25 };
|
||||
const tree = renderer.create(<MyComponent {...props} />).toJSON();
|
||||
expect(tree).toMatchSnapshot();
|
||||
});
|
||||
@@ -25,6 +26,11 @@ describe("MyComponent", () => {
|
||||
expect(wrapper.find("h1").text()).toEqual("Hello, John Doe!");
|
||||
});
|
||||
|
||||
+ it("displays the correct age", () => {
|
||||
+ const props = { name: "Jane Doe", age: 30 };
|
||||
+ const wrapper = shallow(<MyComponent {...props} />);
|
||||
+ expect(wrapper.find("p").text()).toEqual("Age: 30");
|
||||
+ });
|
||||
});
|
||||
Reference in New Issue
Block a user