Skip to content

Commit 091d559

Browse files
committed
[service] work around node issue nodejs/node#48886 that causes tests to fail using deep equals assertion on url objects
1 parent 0fcdb25 commit 091d559

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

service/src/adapters/icons/adapters.icons.db.mongoose.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export class MongooseStaticIconRepository extends BaseMongooseRepository<StaticI
128128
}
129129

130130
async loadContent(id: StaticIconId): Promise<[StaticIcon, NodeJS.ReadableStream] | null | UrlResolutionError> {
131-
let icon = await this.model.findById(id)
131+
const icon = await this.model.findById(id)
132132
if (!icon) {
133133
return null
134134
}

service/test/adapters/icons/adapters.icons.db.mongoose.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { URL } from 'url'
22
import { expect } from 'chai'
3-
import _, { uniq, uniqueId } from 'lodash'
3+
import _ from 'lodash'
44
import { MongoMemoryServer } from 'mongodb-memory-server'
55
import mongoose from 'mongoose'
66
import uniqid from 'uniqid'
@@ -10,6 +10,7 @@ import { MongooseStaticIconRepository, StaticIconDocument, StaticIconModel } fro
1010
import { EntityIdFactory, UrlResolutionError, UrlScheme } from '../../../lib/entities/entities.global'
1111
import { Readable } from 'stream'
1212

13+
1314
interface TestUrlScheme extends UrlScheme {
1415
urlWithPath(path: string): URL
1516
}
@@ -130,7 +131,6 @@ describe('static icon mongoose repository', function() {
130131
it('replaces icon properties for an existing source url when the content hash changes', async function() {
131132

132133
const sourceUrl = new URL('mage:///test/replace.png')
133-
134134
const origAttrs: Required<StaticIconStub> = {
135135
sourceUrl,
136136
imageType: 'raster',
@@ -145,7 +145,7 @@ describe('static icon mongoose repository', function() {
145145
summary: 'replace me'
146146
}
147147
const updatedAttrs: Required<StaticIconStub> = {
148-
sourceUrl,
148+
sourceUrl: new URL(sourceUrl.toString()),
149149
imageType: 'vector',
150150
sizeBytes: 1100,
151151
sizePixels: { width: 220, height: 220 },
@@ -688,7 +688,7 @@ describe('static icon mongoose repository', function() {
688688
tags: []
689689
}
690690
scheme2LocalIcon = {
691-
id: uniqueId(),
691+
id: uniqid(),
692692
sourceUrl: scheme2Local.urlWithPath('test2.png'),
693693
registeredTimestamp: Date.now(),
694694
resolvedTimestamp: Date.now(),

service/test/app/systemInfo/app.systemInfo.test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ const mockEnvironmentInfo: EnvironmentInfo = {
2323
const mockDisclaimer = {};
2424
const mockContactInfo = {};
2525

26-
// Test utility function
2726
function requestBy<T extends object>(
2827
principal: string,
2928
params?: T

service/test/init.test.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11

2+
3+
import url from 'url'
4+
5+
/**
6+
* This class works around issue https://github.com/nodejs/node/issues/48886,
7+
* which was introduced in Node 18.17.0.
8+
*/
9+
url.URL = class Node_18_17_Issue_48886_URL extends url.URL {
10+
constructor(input: string, base?: string | url.URL) {
11+
super(input, base)
12+
this.searchParams
13+
}
14+
}
15+
216
declare module 'mocha' {
317
namespace Mocha {
418
interface MochaOptions {}
519
}
620
}
721

8-
922
import chai, { Assertion } from 'chai'
1023
import asPromised from 'chai-as-promised'
1124

0 commit comments

Comments
 (0)