Skip to content

Commit 123c9ac

Browse files
Revert a few changes
1 parent 7ea2802 commit 123c9ac

File tree

3 files changed

+44
-23
lines changed

3 files changed

+44
-23
lines changed

.github/workflows/build-and-test.yaml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
node-version: [18.x, 20.x]
14+
node-version: [16.x, 18.x, 20.x]
1515

1616
steps:
1717
- name: Checkout
@@ -28,8 +28,24 @@ jobs:
2828

2929
report-coverage:
3030
runs-on: ubuntu-latest
31-
if: false # temporarily disabled until coverage is reinstated
3231
steps:
32+
- name: Checkout
33+
uses: actions/checkout@v4
34+
- name: Setup node
35+
uses: actions/setup-node@v4
36+
with:
37+
node-version: 18.x
38+
cache: yarn
39+
- name: Yarn
40+
run: yarn
41+
- name: Test
42+
run: yarn coverage
43+
- name: Coveralls
44+
uses: coverallsapp/github-action@master
45+
with:
46+
github-token: ${{ secrets.GITHUB_TOKEN }}
47+
env:
48+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3349

3450
test-as-dependency:
3551
runs-on: ubuntu-latest

src/repository/bootstrap-provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { promises } from 'fs';
2-
import fetch from 'make-fetch-happen';
2+
import * as fetch from 'make-fetch-happen';
33
import { ClientFeaturesResponse, FeatureInterface } from '../feature';
44
import { CustomHeaders } from '../headers';
55
import { buildHeaders } from '../request';

src/test/metrics.test.ts

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,22 @@ test('should sendMetrics and register when metricsInterval is a positive number'
5757
const url = getUrl();
5858
const regEP = nockRegister(url);
5959
const metricsEP = nockMetrics(url);
60+
t.plan(2);
6061
// @ts-expect-error
6162
const metrics = new Metrics({
6263
url,
6364
metricsInterval: 50,
6465
});
6566

66-
let metricsSent = 0;
67-
let registered = 0;
68-
metrics.on('registered', () => {
69-
registered++;
70-
t.true(regEP.isDone());
71-
});
72-
metrics.on('sent', () => {
73-
t.true(metricsEP.isDone());
74-
metrics.stop();
75-
metricsSent++;
67+
const validator = new Promise<void>((resolve) => {
68+
metrics.on('registered', () => {
69+
t.true(regEP.isDone());
70+
});
71+
metrics.on('sent', () => {
72+
t.true(metricsEP.isDone());
73+
metrics.stop();
74+
resolve();
75+
});
7676
});
7777

7878
metrics.count('toggle-x', true);
@@ -81,18 +81,18 @@ test('should sendMetrics and register when metricsInterval is a positive number'
8181
metrics.start();
8282
const timeout = new Promise<void>((resolve) =>
8383
setTimeout(() => {
84+
t.fail('Failed to successfully both send and register');
8485
resolve();
8586
}, 1000),
8687
);
87-
await timeout;
88-
t.is(registered, 1);
89-
t.is(metricsSent, 1);
88+
await Promise.race([validator, timeout]);
9089
});
9190

9291
test('should sendMetrics', async (t) => {
9392
const url = getUrl();
93+
t.plan(7);
9494
const metricsEP = nock(url)
95-
.post(metricsUrl, (payload: any) => {
95+
.post(metricsUrl, (payload) => {
9696
t.truthy(payload.bucket);
9797
t.truthy(payload.bucket.start);
9898
t.truthy(payload.bucket.stop);
@@ -101,8 +101,6 @@ test('should sendMetrics', async (t) => {
101101
'toggle-y': { yes: 1, no: 0, variants: {} },
102102
});
103103
t.deepEqual(payload.connectionId, 'connection-id');
104-
t.truthy(payload.bucket.toggles['toggle-x']);
105-
t.truthy(payload.bucket.toggles['toggle-y']);
106104
return true;
107105
})
108106
.reply(200, '');
@@ -130,6 +128,7 @@ test('should sendMetrics', async (t) => {
130128
test('should send correct custom and unleash headers', (t) =>
131129
new Promise((resolve) => {
132130
const url = getUrl();
131+
t.plan(2);
133132
const randomKey = `value-${Math.random()}`;
134133
const metricsEP = nockMetrics(url)
135134
.matchHeader('randomKey', randomKey)
@@ -169,6 +168,7 @@ test('should send correct custom and unleash headers', (t) =>
169168

170169
test('should send content-type header', async (t) => {
171170
const url = getUrl();
171+
t.plan(2);
172172
const metricsEP = nockMetrics(url).matchHeader('content-type', 'application/json');
173173
const regEP = nockRegister(url).matchHeader('content-type', 'application/json');
174174

@@ -188,14 +188,15 @@ test('should send content-type header', async (t) => {
188188

189189
test('request with customHeadersFunction should take precedence over customHeaders', async (t) => {
190190
const url = getUrl();
191+
t.plan(2);
191192
const customHeadersKey = `value-${Math.random()}`;
192193
const randomKey = `value-${Math.random()}`;
193194
const metricsEP = nockMetrics(url)
194-
.matchHeader('randomKey', (value: any) => value === undefined)
195+
.matchHeader('randomKey', (value) => value === undefined)
195196
.matchHeader('customHeadersKey', customHeadersKey);
196197

197198
const regEP = nockRegister(url)
198-
.matchHeader('randomKey', (value: any) => value === undefined)
199+
.matchHeader('randomKey', (value) => value === undefined)
199200
.matchHeader('customHeadersKey', customHeadersKey);
200201

201202
// @ts-expect-error
@@ -221,7 +222,10 @@ test.skip('should respect timeout', (t) =>
221222
new Promise((resolve, reject) => {
222223
t.plan(2);
223224
const url = getUrl();
225+
// @ts-expect-error
224226
nock(url).post(metricsUrl).socketDelay(100).reply(200, '');
227+
228+
// @ts-expect-error
225229
nock(url).post(registerUrl).socketDelay(100).reply(200, '');
226230

227231
// @ts-expect-error
@@ -242,6 +246,7 @@ test.skip('should respect timeout', (t) =>
242246
}));
243247

244248
test('registerInstance should warn when non 200 statusCode', async (t) => {
249+
t.plan(2);
245250
const url = getUrl();
246251
const regEP = nockRegister(url, 500);
247252

@@ -649,7 +654,7 @@ test('sendMetrics should include impactMetrics in the payload', async (t) => {
649654
});
650655

651656
const scope = nock(url)
652-
.post('/client/metrics', (body: any) => {
657+
.post('/client/metrics', (body) => {
653658
capturedBody = body;
654659
return true;
655660
})
@@ -712,7 +717,7 @@ test('sendMetrics should not include impactMetrics field when empty', async (t)
712717
metrics.count('toggle-x', true);
713718

714719
const scope = nock(url)
715-
.post('/client/metrics', (body: any) => {
720+
.post('/client/metrics', (body) => {
716721
capturedBody = body;
717722
return true;
718723
})

0 commit comments

Comments
 (0)