Skip to content

Commit b9559e9

Browse files
committed
Update to Jest 30
1 parent 7dfb2e5 commit b9559e9

15 files changed

Lines changed: 1336 additions & 631 deletions

File tree

engines/query-sparql-link-traversal-solid/test/QuerySparqlLinkTraversalSolid-solidbench-test.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
/** @jest-environment setup-polly-jest/jest-environment-node */
2-
3-
// Needed to undo automock from actor-http-native, cleaner workarounds do not appear to be working.
42
import { QueryEngine } from '../lib';
53
import { usePolly, loadQueries } from './util';
64

75
if (!globalThis.window) {
8-
jest.unmock('follow-redirects');
6+
jest.useRealTimers();
97
}
108

11-
jest.useRealTimers();
12-
139
const queries = loadQueries();
1410

1511
describe('System test: QuerySparqlLinkTraversalSolid', () => {
@@ -43,7 +39,9 @@ describe('System test: QuerySparqlLinkTraversalSolid', () => {
4339
], (file, expectedCount) => () => {
4440
it('produces the expected results', async() => {
4541
const bindings = await engine.queryBindings(queries[file], { lenient: true });
46-
await expect((bindings.toArray())).resolves.toHaveLength(expectedCount);
42+
// Ignore eslint suggestion to make this work in karma as well!
43+
// eslint-disable-next-line jest/prefer-to-have-length
44+
expect((await bindings.toArray()).length).toBe(expectedCount);
4745
});
4846
});
4947

eslint.config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,22 @@ module.exports = config([
7878
'import/extensions': 'off',
7979
},
8080
},
81+
{
82+
// Karma setup script
83+
files: [
84+
'karma.setup.ts',
85+
],
86+
rules: {
87+
'import/no-extraneous-dependencies': 'off',
88+
},
89+
},
90+
{
91+
files: [
92+
'eslint.config.js',
93+
],
94+
rules: {
95+
'ts/no-var-requires': 'off',
96+
'ts/no-require-imports': 'off',
97+
},
98+
},
8199
]);

karma.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const testFiles = [
99
// Based on https://github.com/tom-sherman/blog/blob/main/posts/02-running-jest-tests-in-a-browser.md
1010
module.exports = function(config) {
1111
config.set({
12-
basePath: '',
12+
basePath: __dirname,
1313
browserNoActivityTimeout: 100_000,
1414
plugins: [
1515
'karma-webpack',
@@ -21,15 +21,15 @@ module.exports = function(config) {
2121
],
2222
frameworks: [ 'jasmine', 'webpack' ],
2323

24-
files: [ './karma-setup.js', ...testFiles ],
24+
files: [ './karma.setup.ts', ...testFiles ],
2525
client: {
2626
args: [ '--grep', '/^(?!.*no browser).*$/' ],
2727
jasmine: {
2828
timeoutInterval: 50_000,
2929
},
3030
},
3131
preprocessors: {
32-
'./karma-setup.js': [ 'webpack' ],
32+
'./karma.setup.ts': [ 'webpack' ],
3333
...Object.fromEntries(testFiles.map(key => [ key, [ 'webpack', 'sourcemap' ]])),
3434
},
3535

karma-setup.js renamed to karma.setup.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/* eslint-disable import/first */
2+
(<any> window).process = {
3+
env: {},
4+
};
5+
16
import expect from 'expect';
27
import jest from 'jest-mock';
38

@@ -9,5 +14,5 @@ window.test.each = inputs => (testName, test) => {
914
}
1015
};
1116
window.test.todo = function() {};
12-
window.jest = jest;
13-
window.expect = expect;
17+
(<any>window).jest = jest;
18+
(<any>window).expect = expect;

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"@pollyjs/persister-fs": "^6.0.6",
5151
"@rubensworks/eslint-config": "^3.0.0",
5252
"@rubensworks/process-sparql-benchmark-results": "^1.3.4",
53-
"@types/jest": "^29.5.14",
53+
"@types/jest": "^30.0.0",
5454
"@types/node": "^22.0.0",
5555
"@types/setup-polly-jest": "^0.5.5",
5656
"@types/triple-beam": "^1.3.5",
@@ -62,7 +62,8 @@
6262
"eslint": "^8.0.0",
6363
"husky": "^9.1.7",
6464
"immutable": "^5.0.3",
65-
"jest": "^29.7.0",
65+
"jest": "^30.2.0",
66+
"jest-mock": "^29.3.1",
6667
"jest-rdf": "^2.0.0",
6768
"karma": "^6.4.4",
6869
"karma-chrome-launcher": "^3.2.0",
@@ -84,7 +85,7 @@
8485
"stream-to-string": "^1.2.1",
8586
"streamify-array": "^1.0.1",
8687
"streamify-string": "^1.0.1",
87-
"ts-jest": "^29.2.5",
88+
"ts-jest": "^29.4.4",
8889
"ts-loader": "^9.5.1",
8990
"ts-node": "^10.9.2",
9091
"typedoc": "^0.27.6",

packages/actor-extract-links-headers/test/ActorExtractLinksHeaders-test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,52 @@ describe('ActorExtractLinksHeaders', () => {
4747
],
4848
});
4949
});
50+
51+
it('should run on empty link headers', async() => {
52+
const inputThis = new Headers();
53+
inputThis.append('Content-Type', 'text-turtle');
54+
inputThis.append('Location', '/storage/resource');
55+
inputThis.append('Content-Length', '1024');
56+
inputThis.append('Link', '');
57+
await expect(actor.run({ url: 'http://pod.example.com/storage/resource', metadata: inputMetadata, headers: inputThis, requestTime: 0, context: new ActionContext() })).resolves
58+
.toEqual({
59+
links: [],
60+
});
61+
});
62+
63+
it('should run on no link headers', async() => {
64+
const inputThis = new Headers();
65+
inputThis.append('Content-Type', 'text-turtle');
66+
inputThis.append('Location', '/storage/resource');
67+
inputThis.append('Content-Length', '1024');
68+
await expect(actor.run({ url: 'http://pod.example.com/storage/resource', metadata: inputMetadata, headers: inputThis, requestTime: 0, context: new ActionContext() })).resolves
69+
.toEqual({
70+
links: [],
71+
});
72+
});
73+
74+
it('should run on unknown link headers', async() => {
75+
const inputThis = new Headers();
76+
inputThis.append('Content-Type', 'text-turtle');
77+
inputThis.append('Location', '/storage/resource');
78+
inputThis.append('Content-Length', '1024');
79+
inputThis.append('Link', '</storage/resource.meta>;rel="unknown"');
80+
await expect(actor.run({ url: 'http://pod.example.com/storage/resource', metadata: inputMetadata, headers: inputThis, requestTime: 0, context: new ActionContext() })).resolves
81+
.toEqual({
82+
links: [],
83+
});
84+
});
85+
86+
it('should run on invalid link headers', async() => {
87+
const inputThis = new Headers();
88+
inputThis.append('Content-Type', 'text-turtle');
89+
inputThis.append('Location', '/storage/resource');
90+
inputThis.append('Content-Length', '1024');
91+
inputThis.append('Link', '/storage/resource.meta;rel="describedby"');
92+
await expect(actor.run({ url: 'http://pod.example.com/storage/resource', metadata: inputMetadata, headers: inputThis, requestTime: 0, context: new ActionContext() })).resolves
93+
.toEqual({
94+
links: [],
95+
});
96+
});
5097
});
5198
});

packages/actor-extract-links-solid-type-index/lib/ActorExtractLinksSolidTypeIndex.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,12 @@ export class ActorExtractLinksSolidTypeIndex extends ActorExtractLinks {
165165
.map(async predicate => [ predicate, await this.fetchPredicateDomains(predicate) ]));
166166
const predicateDomainsRec = Object.fromEntries(predicateDomainsInner);
167167
for (const [ predicate, subject ] of Object.entries(predicateSubjects)) {
168-
const typeNames = predicateDomainsRec[predicate];
169-
if (typeNames) {
170-
for (const typeName of typeNames) {
171-
if (!typeSubjects[typeName]) {
172-
typeSubjects[typeName] = [];
173-
}
174-
typeSubjects[typeName].push(subject);
168+
const typeNames = predicateDomainsRec[predicate]!;
169+
for (const typeName of typeNames) {
170+
if (!typeSubjects[typeName]) {
171+
typeSubjects[typeName] = [];
175172
}
173+
typeSubjects[typeName].push(subject);
176174
}
177175
}
178176
}

0 commit comments

Comments
 (0)