Skip to content

Commit a6396fc

Browse files
authored
Upgrade Jest + cleanup test output (#246)
* Upgrade Jest + cleanup test output * suppress errors * fix tsc
1 parent 75cb4cc commit a6396fc

File tree

13 files changed

+1577
-1051
lines changed

13 files changed

+1577
-1051
lines changed

packages/eslint-plugin-obsidian/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"version": "2.26.1",
66
"scripts": {
77
"build": "npx tsc --project tsconfig.prod.json",
8-
"test": "npx jest",
8+
"test": "npx jest --colors",
99
"lint": "eslint src --ignore-pattern '*.d.ts' --ext .ts,.tsx,.js",
1010
"prepublishOnly": "yarn build"
1111
},
@@ -53,7 +53,7 @@
5353
"eslint-plugin-unused-imports": "^4.1.4",
5454
"external-lib-a": "file:./tests/fixtures/external-lib-a",
5555
"external-lib-b": "file:./tests/fixtures/external-lib-b",
56-
"jest": "^29.7.0",
56+
"jest": "30.2.0",
5757
"jest-extended": "^4.0.2",
5858
"react-obsidian": "workspace:*",
5959
"typescript": "^5.8.0"

packages/eslint-plugin-obsidian/src/dto/callExpression.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class CallExpression {
2020
get generics() {
2121
return this.node.typeArguments ?
2222
new Generics(this.node.typeArguments) :
23-
this.node.typeParameters && new Generics(this.node.typeParameters);
23+
undefined;
2424
}
2525

2626
private get callee(): TSESTree.Identifier {

packages/react-obsidian/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
"pretest": "tsc --project tsconfig.json",
1010
"test": "yarn test:all",
1111
"test:all": "yarn test:legacy && yarn test:modern",
12-
"test:legacy": "BABEL_CONFIG_PATH=./babel.config.legacy.js npx jest",
13-
"test:modern": "npx jest",
14-
"test-coverage": "npx jest --coverage"
12+
"test:legacy": "BABEL_CONFIG_PATH=./babel.config.legacy.js npx jest --colors",
13+
"test:modern": "npx jest --colors",
14+
"test-coverage": "npx jest --coverage --colors"
1515
},
1616
"main": "dist/src/index.js",
1717
"directories": {
@@ -41,7 +41,7 @@
4141
"@stylistic/eslint-plugin": "^1.7.0",
4242
"@testing-library/react": "14.x.x",
4343
"@types/hoist-non-react-statics": "^3.3.1",
44-
"@types/jest": "^29.5.14",
44+
"@types/jest": "^30.0.0",
4545
"@types/jest-when": "^3.5.5",
4646
"@types/lodash": "^4.14.176",
4747
"@types/react": "18.3.x",
@@ -59,8 +59,8 @@
5959
"eslint-plugin-react": "^7.26.1",
6060
"eslint-plugin-react-hooks": "^4.2.0",
6161
"eslint-plugin-unused-imports": "^4.1.4",
62-
"jest": "29.7.x",
63-
"jest-environment-jsdom": "^29.7.0",
62+
"jest": "30.2.0",
63+
"jest-environment-jsdom": "30.2.0",
6464
"jest-extended": "^4.0.2",
6565
"jest-mock-extended": "^3.0.7",
6666
"jest-when": "^3.7.0",

packages/react-obsidian/src/graph/PropertyRetriever.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('PropertyRetriever', () => {
3333

3434
it('throws on circular dependencies', () => {
3535
const uut1 = new PropertyRetriever(new CircularDependencyGraph2());
36-
expect(() => uut1.retrieve('dep1')).toThrowError(
36+
expect(() => uut1.retrieve('dep1')).toThrow(
3737
/Could not resolve dep1 from CircularDependencyGraph2\d because of a circular dependency: dep1 -> dep2 -> dep3 -> dep1/,
3838
);
3939
});

packages/react-obsidian/src/injectors/components/InjectComponent.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('injectComponent', () => {
3737

3838
it('Throws an error if the Graph is undefined', () => {
3939
const Graph = undefined as unknown as Constructable<ObjectGraph>;
40-
expect(() => injectComponent(component, Graph)).toThrowError(
40+
expect(() => injectComponent(component, Graph)).toThrow(
4141
`injectComponent was called with an undefined Graph.`
4242
+ `This is probably not an issue with Obsidian.`
4343
+ `It's typically caused by circular dependencies.`

packages/react-obsidian/src/observable/mediator/MediatorObservable.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ describe('MediatorObservable', () => {
8585
it('should throw an error if a subscriber is already subscribed', () => {
8686
const subscriber = () => {};
8787
uut.subscribe(subscriber);
88-
expect(() => uut.subscribe(subscriber)).toThrowError(
89-
'Subscriber already subscribed',
90-
);
88+
expect(() => uut.subscribe(subscriber)).toThrow('Subscriber already subscribed');
9189
});
9290

9391
it('should mediate between observers of different types', () => {

packages/react-obsidian/src/observable/observable.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe('makeObservable', () => {
4848
const observable = new Observable({});
4949
const subscriber = () => {};
5050
observable.subscribe(subscriber);
51-
expect(() => observable.subscribe(subscriber)).toThrowError('Subscriber already subscribed');
51+
expect(() => observable.subscribe(subscriber)).toThrow('Subscriber already subscribed');
5252
});
5353

5454
it('should unsubscribe', () => {
@@ -71,7 +71,7 @@ describe('makeObservable', () => {
7171
it('should throw error because the subscriber is not subscribed', () => {
7272
const observable = new Observable({});
7373
const subscriber = () => { };
74-
expect(() => observable.unsubscribe(subscriber)).toThrowError(`Can't unsubscribe, subscriber doesn't exist`);
74+
expect(() => observable.unsubscribe(subscriber)).toThrow(`Can't unsubscribe, subscriber doesn't exist`);
7575
});
7676

7777
it('should await the current value', async () => {

packages/react-obsidian/test/acceptance/obtain.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('obtain', () => {
1717
it('Should throw circular dependency error when encountering circular dependencies', () => {
1818
expect(
1919
() => Obsidian.obtain(CircularDependencyGraph).aString(),
20-
).toThrowError(/Could not resolve aString from CircularDependencyGraph\d because of a circular dependency: aString -> aString$/);
20+
).toThrow(/Could not resolve aString from CircularDependencyGraph\d because of a circular dependency: aString -> aString$/);
2121
});
2222

2323
it('Should not throw circular dependency error resolving valid dependencies', () => {
@@ -27,7 +27,7 @@ describe('obtain', () => {
2727
});
2828

2929
it('describes the circular dependency path in the thrown exception', () => {
30-
expect(() => Obsidian.obtain(CircularDependencyFromSubgraph).dep1()).toThrowError(
30+
expect(() => Obsidian.obtain(CircularDependencyFromSubgraph).dep1()).toThrow(
3131
// eslint-disable-next-line max-len
3232
/Could not resolve dep1 from CircularDependencyFromSubgraph\d because of a circular dependency: dep1 -> dep2 -> dep3 -> dep2/,
3333
);

packages/react-obsidian/test/integration/customScopedLifecycleBoundGraphs.test.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
Singleton,
99
} from '../../src';
1010
import graphRegistry from '../../src/graph/registry/GraphRegistry';
11+
import { restoreConsoleErrors, suppressConsoleErrors } from '../utils/console';
1112

1213
describe('custom scoped lifecycle-bound graphs', () => {
1314
it('instantiates custom scoped graphs eagerly', () => {
@@ -38,9 +39,11 @@ describe('custom scoped lifecycle-bound graphs', () => {
3839
});
3940

4041
it('throws when trying to use a scoped subgraph from an unscoped graph', async () => {
42+
suppressConsoleErrors();
4143
expect(() => {
4244
render(<ComponentThatWronglyReliesOnCustomScopedGraph />);
4345
}).toThrow(/Cannot instantiate the scoped graph 'CustomScopeGraph' as a subgraph of 'UnscopedGraph' because the scopes do not match. undefined !== customScope/);
46+
restoreConsoleErrors();
4447
});
4548

4649
it('eagerly instantiates nested scoped graphs', () => {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
let errorSpy: jest.SpyInstance;
2+
3+
export function suppressConsoleErrors() {
4+
errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
5+
}
6+
7+
export function restoreConsoleErrors() {
8+
errorSpy?.mockRestore();
9+
}

0 commit comments

Comments
 (0)