Skip to content

Commit

Permalink
Revert "revert: revert #245 (#247)"
Browse files Browse the repository at this point in the history
This reverts commit c65e264.
  • Loading branch information
kanadgupta committed Sep 23, 2024
1 parent 70faf2e commit 431e785
Show file tree
Hide file tree
Showing 162 changed files with 334 additions and 1,443 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ jobs:
strategy:
matrix:
node-version:
- 18
- 20
- lts/-1
- lts/*
- latest

steps:
- uses: actions/checkout@v4
Expand Down
9 changes: 7 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll": "explicit"
},
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,

// controlled by the .editorconfig at root since we can't map vscode settings directly to files
// https://github.com/microsoft/vscode/issues/35350
"files.insertFinalNewline": false
"files.insertFinalNewline": false,

"search.exclude": {
"coverage": true
}
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ console.log(
}),
);

// generate Node.js: Unirest output
console.log(snippet.convert('node', 'unirest'));
// generate Node.js: Axios output
console.log(snippet.convert('node', 'axios'));
```

### addTarget(target)
Expand Down
5 changes: 1 addition & 4 deletions integrations/node.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ WORKDIR /src
ADD package.json /src/

# https://www.npmjs.com/package/axios
# https://www.npmjs.com/package/request
# Installing node-fetch@2 because as of 3.0 is't now an ESM-only package.
# https://www.npmjs.com/package/node-fetch
RUN npm install axios request node-fetch@2 && \
RUN npm install axios && \
npm install

ADD . /src
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,12 @@
"ocaml",
"php",
"python",
"request",
"requests",
"ruby",
"shell",
"snippet",
"swift",
"swift",
"unirest",
"xhr",
"xmlhttprequest"
],
Expand Down
10 changes: 5 additions & 5 deletions src/fixtures/customTarget.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { Target } from '../targets/index.js';

import { request } from '../targets/node/request/client.js';
import { axios } from '../targets/node/axios/client.js';

export const customTarget = {
info: {
key: 'js-variant',
title: 'JavaScript Variant',
key: 'node-variant',
title: 'Node Variant',
extname: '.js',
default: 'request',
default: 'axios',
},
clientsById: {
request,
axios,
},
} as unknown as Target;
30 changes: 7 additions & 23 deletions src/helpers/__snapshots__/utils.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ exports[`availableTargets > returns all available targets 1`] = `
"title": "jQuery",
},
],
"default": "xhr",
"default": "fetch",
"key": "javascript",
"title": "JavaScript",
},
Expand Down Expand Up @@ -192,39 +192,23 @@ exports[`availableTargets > returns all available targets 1`] = `
"link": "http://nodejs.org/api/http.html#http_http_request_options_callback",
"title": "HTTP",
},
{
"description": "Simplified HTTP request client",
"extname": ".cjs",
"installation": "npm install request --save",
"key": "request",
"link": "https://github.com/request/request",
"title": "Request",
},
{
"description": "Lightweight HTTP Request Client Library",
"extname": ".cjs",
"key": "unirest",
"link": "http://unirest.io/nodejs.html",
"title": "Unirest",
},
{
"description": "Promise based HTTP client for the browser and node.js",
"extname": ".cjs",
"extname": ".js",
"installation": "npm install axios --save",
"key": "axios",
"link": "https://github.com/axios/axios",
"title": "Axios",
},
{
"description": "Simplified HTTP node-fetch client",
"extname": ".cjs",
"installation": "npm install node-fetch@2 --save",
"description": "Perform asynchronous HTTP requests with the Fetch API",
"extname": ".js",
"key": "fetch",
"link": "https://github.com/bitinn/node-fetch",
"title": "Fetch",
"link": "https://nodejs.org/docs/latest/api/globals.html#fetch",
"title": "fetch",
},
],
"default": "native",
"default": "fetch",
"key": "node",
"title": "Node.js",
},
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('extname', () => {
expect(extname('c', 'libcurl')).toBe('.c');
expect(extname('clojure', 'clj_http')).toBe('.clj');
expect(extname('javascript', 'axios')).toBe('.js');
expect(extname('node', 'axios')).toBe('.cjs');
expect(extname('node', 'axios')).toBe('.js');
});

it('returns empty string if the extension is not found', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const ENVIRONMENT_CONFIG = {
c: ['libcurl'],
csharp: ['httpclient', 'restsharp'],
go: ['native'],
node: ['axios', 'fetch', 'native', 'request'],
node: ['axios', 'fetch'],
php: ['curl', 'guzzle'],
python: ['requests'],
shell: ['curl'],
Expand All @@ -30,7 +30,7 @@ const ENVIRONMENT_CONFIG = {
// When running tests locally, or within a CI environment, we shold limit the targets that
// we're testing so as to not require a mess of dependency requirements that would be better
// served within a container.
node: ['native'],
node: ['fetch'],
php: ['curl'],
python: ['requests'],
shell: ['curl'],
Expand Down
2 changes: 1 addition & 1 deletion src/targets/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const targetFilter: TargetId[] = [
/** useful for debuggin, only run a particular set of targets */
const clientFilter: ClientId[] = [
// put your clientId here:
// 'unirest',
// 'axios',
];

/** useful for debuggin, only run a particular set of fixtures */
Expand Down
8 changes: 2 additions & 6 deletions src/targets/javascript/axios/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,8 @@ export const axios: Client = {

push('axios');
push('.request(options)', 1);
push('.then(function (response) {', 1);
push('console.log(response.data);', 2);
push('})', 1);
push('.catch(function (error) {', 1);
push('console.error(error);', 2);
push('});', 1);
push('.then(res => console.log(res.data))', 1);
push('.catch(err => console.error(err));', 1);

return join();
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,5 @@ const options = {

axios
.request(options)
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.error(error);
});
.then(res => console.log(res.data))
.catch(err => console.error(err));
8 changes: 2 additions & 6 deletions src/targets/javascript/axios/fixtures/application-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,5 @@ const options = {

axios
.request(options)
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.error(error);
});
.then(res => console.log(res.data))
.catch(err => console.error(err));
8 changes: 2 additions & 6 deletions src/targets/javascript/axios/fixtures/cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,5 @@ const options = {

axios
.request(options)
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.error(error);
});
.then(res => console.log(res.data))
.catch(err => console.error(err));
8 changes: 2 additions & 6 deletions src/targets/javascript/axios/fixtures/custom-method.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,5 @@ const options = {method: 'PROPFIND', url: 'https://httpbin.org/anything'};

axios
.request(options)
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.error(error);
});
.then(res => console.log(res.data))
.catch(err => console.error(err));
8 changes: 2 additions & 6 deletions src/targets/javascript/axios/fixtures/full.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,5 @@ const options = {

axios
.request(options)
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.error(error);
});
.then(res => console.log(res.data))
.catch(err => console.error(err));
8 changes: 2 additions & 6 deletions src/targets/javascript/axios/fixtures/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,5 @@ const options = {

axios
.request(options)
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.error(error);
});
.then(res => console.log(res.data))
.catch(err => console.error(err));
8 changes: 2 additions & 6 deletions src/targets/javascript/axios/fixtures/http-insecure.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,5 @@ const options = {method: 'GET', url: 'http://httpbin.org/anything'};

axios
.request(options)
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.error(error);
});
.then(res => console.log(res.data))
.catch(err => console.error(err));
8 changes: 2 additions & 6 deletions src/targets/javascript/axios/fixtures/jsonObj-multiline.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,5 @@ const options = {

axios
.request(options)
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.error(error);
});
.then(res => console.log(res.data))
.catch(err => console.error(err));
8 changes: 2 additions & 6 deletions src/targets/javascript/axios/fixtures/jsonObj-null-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,5 @@ const options = {

axios
.request(options)
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.error(error);
});
.then(res => console.log(res.data))
.catch(err => console.error(err));
8 changes: 2 additions & 6 deletions src/targets/javascript/axios/fixtures/multipart-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,5 @@ const options = {

axios
.request(options)
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.error(error);
});
.then(res => console.log(res.data))
.catch(err => console.error(err));
8 changes: 2 additions & 6 deletions src/targets/javascript/axios/fixtures/multipart-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,5 @@ const options = {

axios
.request(options)
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.error(error);
});
.then(res => console.log(res.data))
.catch(err => console.error(err));
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,5 @@ const options = {

axios
.request(options)
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.error(error);
});
.then(res => console.log(res.data))
.catch(err => console.error(err));
8 changes: 2 additions & 6 deletions src/targets/javascript/axios/fixtures/multipart-form-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,5 @@ const options = {

axios
.request(options)
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.error(error);
});
.then(res => console.log(res.data))
.catch(err => console.error(err));
8 changes: 2 additions & 6 deletions src/targets/javascript/axios/fixtures/nested.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,5 @@ const options = {

axios
.request(options)
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.error(error);
});
.then(res => console.log(res.data))
.catch(err => console.error(err));
Loading

0 comments on commit 431e785

Please sign in to comment.