Skip to content

Commit 06b0bda

Browse files
refactor: improved integration test suite (#560)
* feat(integration): add POST method test Right now the hapi/fastify examples are not working properly for accepting an incoming POST body. This adds a test to expose that flaw, but does not yet fix it. I think this refactor makes the most sense to finish once #459 is merged in. * fix(php): update postData to push into text instead of params[] * fix: rewriting how we retrieve data out of the request * feat: adding a heap of new unit tests to the metrics integration suite * fix: the node SDK not capturing text/plain and +json payloads * fix: node sdk not capturing `application/x-www-url-formencoded` payloads * fix: optionally skipping multipart tests for sdks that dont support it * fix: stop setting postData if there's none to set * fix: adding missing env vars * fix(python): adding query strings to urls, dont add postData if empty * fix(python): handling of `x-www-form-urlencoded` requests * fix: don't crash in node or php if a json payload is corrupted * fix: python code standards issues * fix: replaying test improvemnts i made * fix: moving the webhook test over to using the node protocol * fix: removing dead code * fix: regenerating the package lockfile * fix: broken tests * fix: compatibility issues with fastify and hapi * feat: fleshing out some useful makefiles * feat: more makefiles * fix: no longer setting an empty `text` property on urlencoded requests * feat: makefile targets for the .net sdk * fix: problem where dotnet request.url didn't contain querystrings * fix: problem where .net would send nullish postData on get requests * fix: broken php tests * fix: downgrading the python ci tests in docker to use node 16 * ci: docker python debugging * fix: remove uneeded python docker workarounds for node 18 * fix(integration): exit early from tests if child process didn't start * bug: attempt to fix python ci (#565) * Revert "fix: remove uneeded python docker workarounds for node 18" This reverts commit 0c9df96. * Revert "ci: docker python debugging" This reverts commit 067f95f. * Revert "fix: downgrading the python ci tests in docker to use node 16" This reverts commit af5c110. * fix(python/integration): bump timeout of HTTPConnectionPool I think we were hitting this timeout sometimes from within the container This makes it pass locally at least, lets see if this works on gh * fix(integration): disable undici on flask integration tests * fix: try to use mocha instead of jest * fix: add commented out experimental fetch disabling * fix: getting tests in mocha working * fix: re-disabling undici in node 18 * ci: attempts to get python working in docker always * ci: disabling python flask integration in ci for now Co-authored-by: Jon Ursenbach <[email protected]> Co-authored-by: Dom Harrington <[email protected]> Co-authored-by: Dom Harrington <[email protected]>
1 parent 2d04da3 commit 06b0bda

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+3004
-1257
lines changed

.eslintrc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
2-
"extends": [
3-
"@readme/eslint-config"
4-
]
2+
"extends": "@readme/eslint-config",
3+
"rules": {
4+
"unicorn/prefer-node-protocol": "error"
5+
}
56
}

.github/workflows/python.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ jobs:
4040
steps:
4141
- uses: actions/checkout@v3
4242

43-
- run: docker-compose run integration_metrics_python_flask
43+
# This Flask suite is **extremely** flaky in Docker. Until we can figure out how to make it not
44+
# you can run this locally with `make test-python-metrics-flask`.
45+
# - run: docker-compose run integration_metrics_python_flask
4446
- run: docker-compose run integration_webhooks_python_flask
4547

4648
- name: Cleanup

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"**/composer.lock": true,
66
"packages/php/examples/laravel/bootstrap/cache/*.php": true,
77
"packages/php/examples/laravel/storage/**": true,
8+
"packages/python/build/**": true,
89

910
// Hide test coverage directories
1011
"**/coverage": true,

Makefile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
.PHONY: help
2+
3+
test-dotnet-metrics: ## Run metrics tests against the .NET SDK
4+
EXAMPLE_SERVER="dotnet examples/net6.0/out/net6.0.dll" npm run test:integration-metrics
5+
6+
test-dotnet-webhooks: ## Run webhooks tests against the .NET SDK
7+
EXAMPLE_SERVER="dotnet examples/net6.0-webhook/out/net6.0-webhook.dll" npm run test:integration-webhooks
8+
9+
test-node-metrics-express: ## Run metrics tests against the Node SDK + Express
10+
EXAMPLE_SERVER="node ./packages/node/examples/express/index.js" npm run test:integration-metrics
11+
12+
test-node-webhooks-express: ## Run webhooks tests against the Node SDK + Express
13+
EXAMPLE_SERVER="node ./packages/node/examples/express/webhook.js" npm run test:integration-webhooks
14+
15+
test-node-metrics-fastify: ## Run metrics tests against the Node SDK + Fastify
16+
EXAMPLE_SERVER="node ./packages/node/examples/fastify/index.js" npm run test:integration-metrics
17+
18+
test-node-metrics-hapi: ## Run metrics tests against the Node SDK + hapi
19+
EXAMPLE_SERVER="node ./packages/node/examples/hapi/index.js" npm run test:integration-metrics
20+
21+
test-php-metrics-laravel: ## Run metrics tests against the PHP SDK + Laravel
22+
SUPPORTS_MULTIPART=true EXAMPLE_SERVER="php packages/php/examples/laravel/artisan serve" npm run test:integration-metrics
23+
24+
test-php-webhooks-php-laravel: ## Run webhooks tests against the PHP SDK + Laravel
25+
EXAMPLE_SERVER="php packages/php/examples/laravel/artisan serve" npm run test:integration-webhooks
26+
27+
test-python-metrics-flask: ## Run Metrics tests against the Python SDK + Flask
28+
EXAMPLE_SERVER="python3 packages/python/examples/flask/app.py" npm run test:integration-metrics
29+
30+
test-python-webhooks-flask: ## Run webhooks tests against the Python SDK + Flask
31+
EXAMPLE_SERVER="python3 packages/python/examples/flask/webhooks.py" npm run test:integration-webhooks
32+
33+
help: ## Display this help screen
34+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

__tests__/.eslintrc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
{
2-
"extends": "@readme/eslint-config/testing"
2+
"extends": "@readme/eslint-config/testing-mocha",
3+
"rules": {
4+
"import/extensions": ["error", "ignorePackages"],
5+
"no-underscore-dangle": "off",
6+
"unicorn/no-unsafe-regex": "off"
7+
}
38
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"data:image/png;name=owlbert.png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAMCAYAAABbayygAAABV0lEQVR4AWNwL/Bh0FGQ9FWUENUGsZExPz8/h5gArzmIDRZw1VfpSfeyagIJgiRBYkCg7mOl72akIt0KVwhSVB5o9SPESutJWajzquJgx/lRDganc7zNX3obq9SiKKxN8P/fmB33vybc7j+MHe1k8t9RSy4NrrA4K2Xp1k0b/peUlPzPjfL5v3bpgv9NTc3/48JD/sOsBju4JDnq6MS+3v9uLlb/pzeY/l82r+9/cIA/GNtrK2wFqQH7uDzY/gXQOrBpbemi/xO9DH4B2WCrQe4GqWHQVRDfBnLXpDTX/z3xTii4xM/if4iF5n+QGgZjZamvIIH5RT5wPKvQC0wDDQAr1FMQ/8YgK8zfAzIeqgCOp+V5gBW6Giq9A6kB+9pUXTiqINjwJ9B6uKKmBHuwW7XkhFeAYg2sMMWXQTvJh/2Uu6nciTgXvVsg7Gsp+xAkZqHPIA1SAwCKnrxJusHahgAAAABJRU5ErkJggg=="

__tests__/__snapshots__/integration-metrics.test.js.snap

Lines changed: 0 additions & 9 deletions
This file was deleted.

__tests__/helpers/chai-plugins.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import caseless from 'caseless';
2+
import chai from 'chai';
3+
4+
/**
5+
* Converts an array of headers like this:
6+
*
7+
* [
8+
* { name: 'host', value: 'localhost:49914' },
9+
* { name: 'connection', value: 'close' },
10+
* ];
11+
*
12+
* To an object that can be passed in to caseless:
13+
*
14+
* {
15+
* host: 'localhost:49914',
16+
* connection: 'close'
17+
* }
18+
*/
19+
function arrayToObject(array) {
20+
return array.reduce((prev, next) => {
21+
return Object.assign(prev, { [next.name]: next.value });
22+
}, {});
23+
}
24+
25+
export default function chaiPlugins(_chai, utils) {
26+
/**
27+
* Determine if a given HAR `headers` array has a given header matching a specific value.
28+
*
29+
* @example <caption>should match a value</caption>
30+
* expect(request.headers).to.have.header('connection', 'close');
31+
*
32+
* @example <caption>should match a regex</caption>
33+
* expect(response.headers).to.have.header('content-type', /application\/json(;\s?charset=utf-8)?/);
34+
*
35+
* @example <caption>should match one of many values</caption>
36+
* expect(request.headers).to.have.header('connection', ['close', 'keep-alive']);
37+
*
38+
* @param {array} headers
39+
* @param {string} header
40+
* @param {string|RegExp} expected
41+
*/
42+
utils.addMethod(chai.Assertion.prototype, 'header', function (header, expected) {
43+
const obj = utils.flag(this, 'object');
44+
const headers = caseless(arrayToObject(obj));
45+
46+
if (expected.constructor.name === 'RegExp') {
47+
new chai.Assertion(headers.get(header)).to.match(expected);
48+
} else if (Array.isArray(expected)) {
49+
new chai.Assertion(headers.get(header)).to.oneOf(expected.map(e => e.toString()));
50+
} else {
51+
new chai.Assertion(headers.get(header)).to.equal(expected.toString());
52+
}
53+
});
54+
}

0 commit comments

Comments
 (0)