Skip to content

Commit

Permalink
feat: moving our integration test suite over to using native fetch (#…
Browse files Browse the repository at this point in the history
…1018)

## 🧰 Changes

Moves out integration test suite off an outdated collection of
`isomorphic-fetch`, `form-data-encoder`, and `formdata-node` in favor of
native `fetch` and `FormData` utilizations.
  • Loading branch information
erunion authored Jul 30, 2024
1 parent 2a93cd8 commit cc07ac2
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 16
node-version: 20

- run: npm ci --ignore-scripts
- run: make test-metrics-dotnet
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 16
node-version: 20

- run: npm ci --ignore-scripts
- run: make test-metrics-node-express
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 16
node-version: 20

- run: npm ci --ignore-scripts
- run: make test-metrics-php-laravel
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 16
node-version: 20

- run: npm ci --ignore-scripts
- run: make test-metrics-python-django
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 16
node-version: 20

- run: npm ci --ignore-scripts
- run: make test-metrics-ruby-rails
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ version: '3.4'

x-server-config: &server-config
README_API_KEY: rdme_abcdefghijklmnopqrstuvwxyz
README_METRICS_SERVER: "http://host.docker.internal:8001"
README_METRICS_SERVER: 'http://host.docker.internal:8001'

x-extra_hosts: &default-extra_hosts
# Docker in Github doesn't automaticaly map these and without `host.docker.internal`
# working our SDK HTTP servers can't talk to our mock Metrics server.
- "host.docker.internal:host-gateway"
- 'host.docker.internal:host-gateway'

services:
runner:
container_name: runner
image: node:16
image: node:20

#
# .NET
Expand Down
60 changes: 0 additions & 60 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@
"alex": "^11.0.0",
"caseless": "^0.12.0",
"eslint": "^8.27.0",
"form-data-encoder": "^2.1.0",
"formdata-node": "^5.0.0",
"har-validator": "^5.1.5",
"isomorphic-fetch": "^3.0.0",
"lerna": "^8.1.3",
"prettier": "^3.0.2",
"vitest": "^0.34.2"
Expand Down
16 changes: 3 additions & 13 deletions test/integration-metrics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ import { once } from 'node:events';
import fs from 'node:fs/promises';
import http from 'node:http';
import net from 'node:net';
import { Readable } from 'node:stream';

import chai from 'chai';
import { FormDataEncoder } from 'form-data-encoder';
import { File, FormData } from 'formdata-node';
import 'isomorphic-fetch';
import { describe, beforeAll, beforeEach, afterAll, expect, it, expectTypeOf } from 'vitest';

import chaiPlugins from './helpers/chai-plugins.js';
Expand Down Expand Up @@ -461,12 +457,9 @@ describe('Metrics SDK Integration Tests', function () {
formData.append('another', 'Hello world');
formData.append('buster', [1234, 5678]);

const encoder = new FormDataEncoder(formData);

await fetch(`http://localhost:${PORT}/`, {
method: 'post',
headers: encoder.headers,
body: Readable.from(encoder),
body: formData,
});

const [, body] = await getRequest();
Expand Down Expand Up @@ -503,12 +496,9 @@ describe('Metrics SDK Integration Tests', function () {
formData.append('buster', [1234, 5678]);
formData.append('owlbert.png', new File([owlbert], 'owlbert.png', { type: 'image/png' }), 'owlbert.png');

const encoder = new FormDataEncoder(formData);

await fetch(`http://localhost:${PORT}/`, {
method: 'post',
headers: encoder.headers,
body: Readable.from(encoder),
body: formData,
});

const [, body] = await getRequest();
Expand All @@ -522,7 +512,7 @@ describe('Metrics SDK Integration Tests', function () {

expect(request.method).toBe('POST');
expect(request.headers).to.have.header('content-type', /multipart\/form-data; boundary=(.*)/);
expect(request.headers).to.have.header('content-length', 982);
expect(request.headers).to.have.header('content-length', [960, 982]);
expect(request.postData.mimeType).toMatch(/multipart\/form-data; boundary=(.*)/);

const owlbertDataURL = await fs.readFile('./test/__datasets__/owlbert.dataurl.json').then(JSON.parse);
Expand Down
1 change: 0 additions & 1 deletion test/integration-webhooks.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import crypto from 'node:crypto';

import 'isomorphic-fetch';
import { describe, it, expect } from 'vitest';

const PORT = 8000; // SDK HTTP server port
Expand Down

0 comments on commit cc07ac2

Please sign in to comment.