Skip to content

Commit 4805239

Browse files
authored
task: migrate off ava to vitest (#796)
1 parent 49a0722 commit 4805239

Some content is hidden

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

46 files changed

+2469
-3868
lines changed

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

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

1616
steps:
1717
- name: Checkout
18-
uses: actions/checkout@v4
18+
uses: actions/checkout@v6
1919
- name: Setup node
2020
uses: actions/setup-node@v4
2121
with:
@@ -30,28 +30,29 @@ jobs:
3030
runs-on: ubuntu-latest
3131
steps:
3232
- name: Checkout
33-
uses: actions/checkout@v4
33+
uses: actions/checkout@v6
3434
- name: Setup node
3535
uses: actions/setup-node@v4
3636
with:
37-
node-version: 18.x
37+
node-version: 22.x
3838
cache: yarn
3939
- name: Yarn
4040
run: yarn
4141
- name: Test
4242
run: yarn coverage
4343
- name: Coveralls
44-
uses: coverallsapp/github-action@master
44+
uses: coverallsapp/github-action@v2
4545
with:
4646
github-token: ${{ secrets.GITHUB_TOKEN }}
47+
fail-on-error: false
4748
env:
4849
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4950

5051
test-as-dependency:
5152
runs-on: ubuntu-latest
5253
steps:
5354
- name: Checkout
54-
uses: actions/checkout@v4
55+
uses: actions/checkout@v6
5556
- name: Setup node
5657
uses: actions/setup-node@v4
5758
with:

biome.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"useIgnoreFile": true
77
},
88
"files": {
9-
"ignoreUnknown": false
9+
"ignoreUnknown": false,
10+
"includes": ["src/**/*.ts"]
1011
},
1112
"formatter": {
1213
"enabled": true,

package.json

Lines changed: 22 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
"pre-commit": "lint-staged",
1313
"prebuild": "del-cli --force lib",
1414
"build": "tsc -p .",
15-
"prepare": "husky install && yarn run build",
16-
"test": "cross-env NODE_ENV=test yarn run build && ava",
17-
"coverage": "nyc --reporter=lcov yarn test"
15+
"prepare": "husky && yarn run build",
16+
"test": "vitest run",
17+
"coverage": "vitest run --coverage"
1818
},
1919
"repository": {
2020
"type": "git",
@@ -37,44 +37,39 @@
3737
"make-fetch-happen": "^13.0.1",
3838
"murmurhash3js": "^3.0.1",
3939
"proxy-from-env": "^1.1.0",
40-
"semver": "^7.6.2"
40+
"semver": "^7.7.3"
4141
},
4242
"engines": {
43-
"node": ">=16"
43+
"node": ">=20"
4444
},
4545
"files": [
4646
"lib",
4747
"!lib/test",
4848
"examples"
4949
],
5050
"devDependencies": {
51-
"@ava/babel": "^2.0.0",
52-
"@ava/typescript": "^4.0.0",
5351
"@biomejs/biome": "2.3.8",
54-
"@tsconfig/node12": "^12.0.0",
55-
"@types/eventsource": "^1.1.15",
56-
"@types/express": "^4.17.17",
52+
"@tsconfig/node18": "^18.2.6",
53+
"@types/express": "^4.17.25",
5754
"@types/jsbn": "^1.2.33",
5855
"@types/make-fetch-happen": "^10.0.4",
59-
"@types/murmurhash3js": "^3.0.3",
56+
"@types/murmurhash3js": "^3.0.7",
6057
"@types/nock": "^11.1.0",
6158
"@types/node": "^20.17.17",
6259
"@types/proxy-from-env": "^1.0.4",
6360
"@types/semver": "^7.5.0",
64-
"@types/sinon": "^17.0.0",
65-
"@unleash/client-specification": "^5.1.6",
66-
"ava": "^5.3.0",
67-
"cross-env": "^7.0.3",
68-
"del-cli": "^5.0.0",
69-
"esm": "^3.2.25",
70-
"husky": "^8.0.3",
71-
"lint-staged": "^14.0.0",
61+
"@unleash/client-specification": "5.1.9",
62+
"@vitest/coverage-v8": "4.0.14",
63+
"@vitest/ui": "4.0.14",
64+
"del-cli": "^7.0.0",
65+
"husky": "^9.1.7",
66+
"lint-staged": "^16.2.7",
7267
"mkdirp": "^3.0.1",
73-
"nock": "^13.3.1",
74-
"nyc": "^15.1.0",
68+
"nock": "^14.0.10",
7569
"redis": "^4.6.7",
76-
"sinon": "^18.0.0",
77-
"typescript": "^5.4.3"
70+
"sinon": "^21.0.0",
71+
"typescript": "^5.9.3",
72+
"vitest": "^4.0.14"
7873
},
7974
"resolutions": {
8075
"ansi-regex": "^5.0.1",
@@ -84,36 +79,14 @@
8479
"json-schema": "^0.4.0",
8580
"json5": "^2.0.0",
8681
"qs": "^6.5.3",
87-
"minimatch": "^3.0.5",
82+
"minimatch": "^9.0.0",
8883
"semver": "^7.5.3"
8984
},
90-
"nyc": {
91-
"lines": 95,
92-
"statements": 95,
93-
"functions": 95,
94-
"branches": 80,
95-
"include": [
96-
"lib/**.js",
97-
"lib/**/*.js"
98-
],
99-
"all": true,
100-
"exclude-after-remap": false
101-
},
10285
"lint-staged": {
10386
"*.{js,ts,jsx,tsx,json,md}": [
104-
"biome check --write"
105-
]
106-
},
107-
"ava": {
108-
"typescript": {
109-
"rewritePaths": {
110-
"src/": "lib/"
111-
},
112-
"compile": false
113-
},
114-
"files": [
115-
"src/**/*.test.ts"
87+
"biome check --write --no-errors-on-unmatched --files-ignore-unknown=true"
11688
]
11789
},
118-
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
90+
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e",
91+
"type": "commonjs"
11992
}

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 'node:fs';
2-
import * as fetch from 'make-fetch-happen';
2+
import fetch from 'make-fetch-happen';
33
import type { ClientFeaturesResponse, FeatureInterface } from '../feature';
44
import type { CustomHeaders } from '../headers';
55
import { buildHeaders } from '../request';

src/repository/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ Message: ${message}`,
282282
}
283283

284284
private convertToMap(features: FeatureInterface[]): FeatureToggleData {
285-
const obj = features.reduce(
285+
const obj = (features || []).reduce(
286286
(o: { [s: string]: FeatureInterface }, feature: FeatureInterface) => {
287287
this.validateFeature(feature);
288288
o[feature.name] = feature;

src/request.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import * as http from 'node:http';
2-
import * as https from 'node:https';
1+
import http from 'node:http';
2+
import https from 'node:https';
33
import type { URL } from 'node:url';
44
import { HttpProxyAgent } from 'http-proxy-agent';
55
import { HttpsProxyAgent } from 'https-proxy-agent';
6-
import * as fetch from 'make-fetch-happen';
6+
import fetch from 'make-fetch-happen';
77
import { getProxyForUrl } from 'proxy-from-env';
8+
import details from './details.json';
89
import type { CustomHeaders } from './headers';
910
import type { HttpOptions } from './http-options';
1011

11-
const details = require('./details.json');
12-
1312
export interface RequestOptions {
1413
url: string;
1514
timeout?: number;
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`should return variant when equal weight on 1,1,1 1`] = `
4+
{
5+
"enabled": true,
6+
"featureEnabled": true,
7+
"feature_enabled": true,
8+
"name": "variant3",
9+
"payload": {
10+
"type": "string",
11+
"value": "val3",
12+
},
13+
}
14+
`;
15+
16+
exports[`should return variant when equal weight on 1,1,1 2`] = `
17+
{
18+
"enabled": true,
19+
"featureEnabled": true,
20+
"feature_enabled": true,
21+
"name": "variant3",
22+
"payload": {
23+
"type": "string",
24+
"value": "val3",
25+
},
26+
}
27+
`;
28+
29+
exports[`should return variant when equal weight on 1,1,1 3`] = `
30+
{
31+
"enabled": true,
32+
"featureEnabled": true,
33+
"feature_enabled": true,
34+
"name": "variant3",
35+
"payload": {
36+
"type": "string",
37+
"value": "val3",
38+
},
39+
}
40+
`;
41+
42+
exports[`should return variant when equal weight on 33,33,33 1`] = `
43+
{
44+
"enabled": true,
45+
"featureEnabled": true,
46+
"feature_enabled": true,
47+
"name": "variant3",
48+
"payload": {
49+
"type": "string",
50+
"value": "val3",
51+
},
52+
}
53+
`;
54+
55+
exports[`should return variant when equal weight on 33,33,33 2`] = `
56+
{
57+
"enabled": true,
58+
"featureEnabled": true,
59+
"feature_enabled": true,
60+
"name": "variant1",
61+
"payload": {
62+
"type": "string",
63+
"value": "val1",
64+
},
65+
}
66+
`;
67+
68+
exports[`should return variant when equal weight on 33,33,33 3`] = `
69+
{
70+
"enabled": true,
71+
"featureEnabled": true,
72+
"feature_enabled": true,
73+
"name": "variant3",
74+
"payload": {
75+
"type": "string",
76+
"value": "val3",
77+
},
78+
}
79+
`;
80+
81+
exports[`should return variant when equal weight on 100,100,100 1`] = `
82+
{
83+
"enabled": true,
84+
"featureEnabled": true,
85+
"feature_enabled": true,
86+
"name": "variant3",
87+
"payload": {
88+
"type": "string",
89+
"value": "val3",
90+
},
91+
}
92+
`;
93+
94+
exports[`should return variant when equal weight on 100,100,100 2`] = `
95+
{
96+
"enabled": true,
97+
"featureEnabled": true,
98+
"feature_enabled": true,
99+
"name": "variant3",
100+
"payload": {
101+
"type": "string",
102+
"value": "val3",
103+
},
104+
}
105+
`;
106+
107+
exports[`should return variant when equal weight on 100,100,100 3`] = `
108+
{
109+
"enabled": true,
110+
"featureEnabled": true,
111+
"feature_enabled": true,
112+
"name": "variant2",
113+
"payload": {
114+
"type": "string",
115+
"value": "val2",
116+
},
117+
}
118+
`;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`should call methods 1`] = `false`;
4+
5+
exports[`should call methods 2`] = `undefined`;
6+
7+
exports[`should call methods 3`] = `
8+
{
9+
"enabled": false,
10+
"featureEnabled": false,
11+
"feature_enabled": false,
12+
"name": "disabled",
13+
}
14+
`;

0 commit comments

Comments
 (0)