Skip to content

Commit 53d4189

Browse files
committed
Migrate to Vitest
Vitest replaces Jest for almost everything, because Jest still cannot support ESM in a reasonable way. And Jasmine is used to test a CJS version of the schematics specifically built for testing purpose, because Vitest does not play nice with that unusual part.
1 parent 336ab3d commit 53d4189

Some content is hidden

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

56 files changed

+3337
-3768
lines changed

.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ jobs:
8282
key: ${{ github.sha }}
8383

8484
- name: Test
85-
run: yarn test --ci
85+
run: yarn test
8686

8787
prettier:
8888
runs-on: ubuntu-latest

.prettierignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
/scripts/
88

99
# Needed because TextEncoder workaround must happen before importing @angular-devkit/schematics
10-
/packages/apollo-angular/schematics/tests/ng-add.spec.ts
11-
/packages/apollo-angular/schematics/tests/utils.spec.ts
10+
/packages/apollo-angular/schematics/tests/ng-add.spec.cts
11+
/packages/apollo-angular/schematics/tests/utils.spec.cts

package.json

-7
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,17 @@
4444
"@changesets/cli": "^2.27.3",
4545
"@schematics/angular": "^18.0.1",
4646
"@theguild/prettier-config": "^2.0.1",
47-
"@types/jest": "^29.5.4",
4847
"@types/node": "^20.12.12",
49-
"babel-jest": "^29.6.4",
5048
"browserlist": "^1.0.1",
51-
"cpx2": "^7.0.1",
5249
"graphql": "^16.8.0",
5350
"husky": "^9.0.0",
54-
"jest": "^29.6.4",
55-
"jest-preset-angular": "^14.1.0",
56-
"jest-zone-patch": "^0.0.10",
5751
"lint-staged": "^15.2.5",
5852
"ng-packagr": "^18.0.0",
5953
"prettier": "^3.5.3",
6054
"react": "^18.3.1",
6155
"rimraf": "^5.0.7",
6256
"rxjs": "~7.8.0",
6357
"shelljs": "^0.8.5",
64-
"ts-jest": "^29.1.3",
6558
"tslib": "^2.3.0",
6659
"typescript": "5.4.5",
6760
"zone.js": "~0.14.6"

packages/apollo-angular/headers/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "apollo-angular/headers",
3+
"type": "module",
34
"description": "An Apollo Link to easily transform headers from being a key-value object to an instance of HttpHeaders. Great combination with apollo-angular-link-http.",
45
"author": {
56
"name": "Kamil Kisiela",
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { describe, expect, test } from 'vitest';
12
import { HttpHeaders } from '@angular/common/http';
23
import { ApolloLink, execute, gql, Observable as LinkObservable } from '@apollo/client/core';
34
import { httpHeaders } from '../src';
@@ -13,51 +14,53 @@ const query = gql`
1314
const data = { heroes: [{ name: 'Foo', __typename: 'Hero' }] };
1415

1516
describe('httpHeaders', () => {
16-
test('should turn object into HttpHeaders', (done: jest.DoneCallback) => {
17-
const headersLink = httpHeaders();
17+
test('should turn object into HttpHeaders', () =>
18+
new Promise<void>(done => {
19+
const headersLink = httpHeaders();
1820

19-
const mockLink = new ApolloLink(operation => {
20-
const { headers } = operation.getContext();
21+
const mockLink = new ApolloLink(operation => {
22+
const { headers } = operation.getContext();
2123

22-
expect(headers instanceof HttpHeaders).toBe(true);
23-
expect(headers.get('Authorization')).toBe('Bearer Foo');
24+
expect(headers instanceof HttpHeaders).toBe(true);
25+
expect(headers.get('Authorization')).toBe('Bearer Foo');
2426

25-
return LinkObservable.of({ data });
26-
});
27+
return LinkObservable.of({ data });
28+
});
2729

28-
const link = headersLink.concat(mockLink);
30+
const link = headersLink.concat(mockLink);
2931

30-
execute(link, {
31-
query,
32-
context: {
33-
headers: {
34-
Authorization: 'Bearer Foo',
32+
execute(link, {
33+
query,
34+
context: {
35+
headers: {
36+
Authorization: 'Bearer Foo',
37+
},
3538
},
36-
},
37-
}).subscribe(result => {
38-
expect(result.data).toEqual(data);
39-
done();
40-
});
41-
});
39+
}).subscribe(result => {
40+
expect(result.data).toEqual(data);
41+
done();
42+
});
43+
}));
4244

43-
test('should not set headers when not defined', (done: jest.DoneCallback) => {
44-
const headersLink = httpHeaders();
45+
test('should not set headers when not defined', () =>
46+
new Promise<void>(done => {
47+
const headersLink = httpHeaders();
4548

46-
const mockLink = new ApolloLink(operation => {
47-
const { headers } = operation.getContext();
49+
const mockLink = new ApolloLink(operation => {
50+
const { headers } = operation.getContext();
4851

49-
expect(headers).toBeUndefined();
52+
expect(headers).toBeUndefined();
5053

51-
return LinkObservable.of({ data });
52-
});
54+
return LinkObservable.of({ data });
55+
});
5356

54-
const link = headersLink.concat(mockLink);
57+
const link = headersLink.concat(mockLink);
5558

56-
execute(link, {
57-
query,
58-
}).subscribe(result => {
59-
expect(result.data).toEqual(data);
60-
done();
61-
});
62-
});
59+
execute(link, {
60+
query,
61+
}).subscribe(result => {
62+
expect(result.data).toEqual(data);
63+
done();
64+
});
65+
}));
6366
});

packages/apollo-angular/headers/tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"compilerOptions": {
44
"rootDir": ".",
55
"baseUrl": ".",
6-
"outDir": "../build/http",
6+
"outDir": "../build/testing",
77
"paths": {
8-
"apollo-angular": ["../"]
8+
"apollo-angular": ["../src"]
99
}
1010
},
1111
"include": ["src/**/*.ts", "tests/**/*.ts"]

packages/apollo-angular/http/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "apollo-angular/http",
3+
"type": "module",
34
"description": "An Apollo Link to allow sending an http request per operation.",
45
"author": {
56
"name": "Kamil Kisiela",

packages/apollo-angular/http/tests/__snapshots__/ssr.spec.ts.snap

-5
This file was deleted.

0 commit comments

Comments
 (0)