Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Node.js CI to check this adapter supports newer Node.js #34

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: CI
on:
pull_request:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
# fetch was added in Node.js 17.5
node-version: ['18.x', '20.x']
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: npm
- run: npm ci
- run: npm test
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ axios.request({

# Note

- Since, this adapter relies on fetch API so it won't work in Node environment
- Node 17.5 or later is required to use this adapter in Node environment.
22 changes: 22 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {expect, test, describe, beforeEach, afterEach} from 'vitest'
import axios from "axios";
import fetchAdapter from "./index";
import {getLocal} from "mockttp";

describe('fetchAdapter', () => {
const mockServer = getLocal();

beforeEach(() => mockServer.start(18080));
afterEach(() => mockServer.stop());

test('basic', async () => {
const axiosInstance = axios.create({
baseURL: 'http://localhost:18080',
timeout: 1000,
adapter: fetchAdapter,
});
await mockServer.forGet("/hello").thenReply(200, "A mocked response");
const response = await axiosInstance.get("/hello");
expect(response.data).to.equal("A mocked response");
});
});
Loading